Skip to content

Commit

Permalink
👷‍♀️ Move publishing inside single workflow
Browse files Browse the repository at this point in the history
At the moment, we have two Github Action workflows:

  - `test.yml`: runs build and test, then tags when bumping the version
    in `main`
  - `publish.yml`: releases the package when a new tag is published

The issue with this setup is that the built-in `GITHUB_TOKEN`
[will not trigger another workflow][1], so we had to add a separate
PAT with write permissions to our repos, which was a bit of a
security concern.

In order to avoid the need for this extra token, with its associated
risks and administrative overheads (like rotating), this change
combines our workflows into a single workflow.

We tweak the `tag.sh` to `release.sh`, and it's now also in charge of
publishing (since it knows when we've pushed a new tag).

[1]: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
  • Loading branch information
alecgibson committed Jan 18, 2024
1 parent dca8c1b commit 2767c2e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 68 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
- name: Install
run: npm install
- name: Test
run: npm test --forbid-only
- name: Release
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: ./release.sh
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 changes: 0 additions & 30 deletions .github/workflows/publish.yml

This file was deleted.

38 changes: 0 additions & 38 deletions .github/workflows/test.yml

This file was deleted.

2 changes: 2 additions & 0 deletions tag.sh → release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ echo '!/lib' >> .gitignore

git tag $VERSION
git push origin refs/tags/$VERSION

npm publish

0 comments on commit 2767c2e

Please sign in to comment.