Home

Awesome

release-js-action

GitHub Action to release JavaScript Actions.

action.yaml

This action create a commit with dist directories and pushes a branch or tag to release a new version. It supports three kinds of releases:

  1. pr/<pull request number>: Create or update pr/<pull request number> branch when pull requests are updated
  2. latest: Update latest branch when the default branch is updated
  3. GitHub Releases (vX.Y.Z, vX.Y.Z-a): Create a tag and a GitHub Release

Background

If you write JavaScript Actions in TypeScript, you need to build TypeScript to JavaScript and commit it. But adding compiled files has some problems:

To solve these issues, we stop adding compiled files in the default branch and feature branches by adding dist to .gitignore. Instead, we build TypeScript in CI and create branches and tags to release them. This means the default branch and feature branches don't work as JavaScript Action anymore. Instead, we specify the following versions.

  1. pr/<pull request number>: branches where pull request branches are built
  2. latest: A branch where the default branch is built
  3. GitHub Releases

For example, lock-action uses this action. The following versions don't work:

- uses: suzuki-shunsuke/lock-action@main
- uses: suzuki-shunsuke/lock-action@feature-branch-1

Instead, the following versions are available:

- uses: suzuki-shunsuke/lock-action@pr/82
- uses: suzuki-shunsuke/lock-action@latest
- uses: suzuki-shunsuke/lock-action@v0.1.3

How To Use

  1. If you have already added dist to the default or feature branches, you need to remove them
  2. Add dist to .gitignore
  3. Add GitHub Actions workflows using this action

In workflows,

[!WARNING] This action doesn't build TypeScript to JavaScript. You need to do it yourself before using this action

  1. Build dist directories
  2. Use this action

e.g.

<details> <summary>Example Workflow (`Pull Request`)</summary>
---
name: wc-create-pr-branch
run-name: wc-create-pr-branch (${{inputs.pr}})
on:
  workflow_call:
    inputs:
      pr:
        description: "Pull Request Number"
        required: true
        type: number
      is_comment:
        description: If the comment is posted
        required: false
        default: false
        type: boolean
jobs:
  create-pr-branch:
    timeout-minutes: 30
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - run: gh pr checkout "$PR"
        if: inputs.pr != ''
        env:
          GITHUB_TOKEN: ${{github.token}}
          PR: ${{inputs.pr}}
      - run: npm ci
      - run: npm run build

      - uses: suzuki-shunsuke/release-js-action@964d814f9200bb928f4713098c38218881cfc493 # v0.1.0
        with:
          version: pr/${{inputs.pr}}
          is_comment: ${{inputs.is_comment}}
</details> <details> <summary>Example Workflow (latest)</summary>
name: Update the latest branch
on:
  push:
    branches:
      - main
jobs:
  build:
    timeout-minutes: 15
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - run: npm ci
      - run: npm run build
      - uses: suzuki-shunsuke/release-js-action@964d814f9200bb928f4713098c38218881cfc493 # v0.1.0
        with:
          version: latest
</details> <details> <summary>Example Workflow (Release)</summary>
---
name: Release
run-name: Release ${{inputs.tag}}
on:
  workflow_dispatch:
    inputs:
      tag:
        description: "tag"
        required: true
      pr:
        description: "pr number (pre-release)"
        required: false
jobs:
  release:
    timeout-minutes: 30
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - run: gh pr checkout "$PR"
        if: inputs.pr != ''
        env:
          GITHUB_TOKEN: ${{github.token}}
          PR: ${{inputs.pr}}
      - run: npm ci
      - run: npm run build

      - uses: suzuki-shunsuke/release-js-action@964d814f9200bb928f4713098c38218881cfc493 # v0.1.0
        with:
          version: ${{inputs.tag}}
          pr: ${{inputs.pr}}
</details>

This action requires the following permissions:

Inputs / Outputs

Please see action.yaml.

LICENSE

MIT