# GitHub Actions (https://hotcodepush.com/docs/ci/github-actions)

A release.yml that releases every merge to production with the HotCodePush release action, with the bare CLI line beside it.

To ship every commit from GitHub Actions, a workflow on `push` to `main` builds the app and runs the release action with two repository secrets. The `hotcodepush-team/release-action` step wraps the pinned HotCodePush CLI and masks the token and the key. Its inputs are the flags of `release create` under the same names.

[Ship every commit](https://hotcodepush.com/docs/ci/pipeline) has the prerequisites and the three disciplines. This page carries the GitHub Actions file.

## Secrets to set [#secrets-to-set]

Both live under the repository's Settings › Secrets and variables › Actions. A job that names `environment: production` reads them from a GitHub Environment of that name instead, which keeps the key to the jobs you put there.

| Secret | Holds |
|---|---|
| `HOTCODEPUSH_TOKEN` | Holds an API token from the console's API tokens page. |
| `HOTCODEPUSH_SIGNING_KEY` | Holds the content of the private key file `signing-key create` wrote, PEM lines included. Leave it out until the app has a key. |

A pull request from a fork gets no secrets. In a pull request job that releases, such as the preview workflow, guard the job with `if: github.event.pull_request.head.repo.full_name == github.repository` when the repository takes outside contributions.

## The workflow [#the-workflow]

### Release action

```yaml title=".github/workflows/release.yml"
name: Release to production
on:
  push:
    branches: [main]
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Check out the commit
        uses: actions/checkout@v7
      - name: Build the web app
        run: npm ci && npm run build
      - name: Release to production
        uses: hotcodepush-team/release-action@v0.3.0
        with:
          token: ${{ secrets.HOTCODEPUSH_TOKEN }}
          private-key: ${{ secrets.HOTCODEPUSH_SIGNING_KEY }}
          channel: production
```

Every input is a flag of [release create](https://hotcodepush.com/docs/cli/commands/release) under the same name. An input left empty passes no flag, so the CLI's defaults apply. The inputs a pipeline reaches for:

- `rollout-percent: 10` with `progression: true` stages the release.
- `bundle-version: ${{ github.sha }}` names the bundle by the commit.
- `dry-run: true` serves a pull request check that needs no key.
- `path` points at a build that lands outside the framework's default directory.
- `working-directory` serves an app in a monorepo.
- `cli-version` runs another CLI version.

The [action's README](https://github.com/hotcodepush-team/release-action) lists them all. The step's outputs name what it released: `release-id`, `release-number`, `channel-id` and the whole answer as `release`.

### CLI

The same workflow with the bare CLI line, for a repository that pins the CLI as a dev dependency:

```yaml title=".github/workflows/release.yml"
name: Release to production
on:
  push:
    branches: [main]
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Check out the commit
        uses: actions/checkout@v7
      - name: Build the web app
        run: npm ci && npm run build
      - name: Release to production
        run: npx hotcodepush release create --channel production --bundle-version "$(git rev-parse --short HEAD)" --yes --json
        env:
          HOTCODEPUSH_TOKEN: ${{ secrets.HOTCODEPUSH_TOKEN }}
          HOTCODEPUSH_SIGNING_KEY: ${{ secrets.HOTCODEPUSH_SIGNING_KEY }}
```

- A React Native or Expo app replaces the build step with `npm ci` alone and runs the release step once per platform. A matrix over `platform: [ios, android]` feeds the action's `platform` input or the line's `--platform` flag, and the CLI packages that platform's bundle inside the upload. A Cordova app whose `www` is written by hand has no build step either.
- The runner's Node.js must be 22 or later, and GitHub-hosted runners ship it.

The release step logs one line per release and writes a job summary: channel, number, bundle and rollout. A failed release fails the step with the CLI's exit code and an annotation titled with the code, and the [error catalog](https://hotcodepush.com/docs/cli/errors) names the fix. A green job and a device that did not take the release is the other case. See [Troubleshooting](https://hotcodepush.com/docs/troubleshooting).

A preview channel per pull request runs from the same pipeline, with a QR code in a pull request comment. [Test with preview channels](https://hotcodepush.com/docs/guides/preview-channels) has that workflow.

## Next steps [#next-steps]

- [Ship every commit](https://hotcodepush.com/docs/ci/pipeline) names the three disciplines a pipeline that ships every commit keeps.
- [Test with preview channels](https://hotcodepush.com/docs/guides/preview-channels) has the preview workflow and the tester build that follows a channel.
- [Roll out gradually](https://hotcodepush.com/docs/guides/staged-rollouts) sets `rollout-percent` and `progression` on the action and explains the auto-pause counters.
