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:

  - `push.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 flow with a sequence of jobs.

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 afe92b2 commit 83417d3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 42 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/push.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: CI/CD
name: CI

on:
push:
branches:
Expand All @@ -7,7 +8,6 @@ on:

jobs:
test:
name: Test
runs-on: ubuntu-latest
services:
mongo:
Expand All @@ -17,18 +17,18 @@ jobs:
steps:
- name: Checkout (push)
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v3
uses: actions/checkout@v4
# Separate checkout action for pull_request_target, which needs to
# explicitly checkout the SHA
- name: Checkout (pull request)
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '20.9'
node-version: '20.x'
- name: Install
run: npm install
- name: Lint
Expand All @@ -37,7 +37,24 @@ jobs:
run: npm run build
- name: test
run: npm run test
- name: Tag
if: |
github.event_name == 'push' && github.ref == 'refs/heads/master'
run: ./tag.sh

release:
needs:
- test
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
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: Build
run: npm run build
- name: Release
run: ./release.sh
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 0 additions & 32 deletions .github/workflows/publish.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 @@ -23,3 +23,5 @@ git add --all lib/
git commit --message "Release version $VERSION"
git tag $VERSION
git push origin refs/tags/$VERSION

npm publish

0 comments on commit 83417d3

Please sign in to comment.