Skip to content

Commit

Permalink
chore: auto publish alpha versions (#1414)
Browse files Browse the repository at this point in the history
allows automatically releasing an alpha version when a PR is labelled
  • Loading branch information
pauldambra authored Sep 16, 2024
1 parent c746005 commit 2f093d3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/label-alpha-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Autorelease alpha version

on:
pull_request:
types:
- labeled

jobs:
check-permissions:
name: "Check user has permission to release"
runs-on: ubuntu-latest
outputs:
# can have multiple outputs
# check-result: ${{ steps.check-permissions.outputs.check-result }}
# user-permission: ${{ steps.check-permissions.outputs.user-permission }}
require-result: ${{ steps.check-permissions.outputs.require-result }}
steps:
- uses: actions-cool/check-user-permission@v2
id: check-permissions
with:
require: 'write'
warn-when-failed:
name: Warn when the user does not have the required permissions
runs-on: ubuntu-latest
needs: check-permissions
if: needs.check-permissions.outputs.require-result == 'false'
steps:
- run: echo "The user does not have the write permissions to trigger this action (pun intended)."
- run: echo "require-result = ${{ needs.check-permissions.outputs.require-result }}"

label-alpha-release:
name: Release alpha version based on PR label
runs-on: ubuntu-latest
needs: check-permissions
if: needs.check-permissions.outputs.require-result == 'true' &&
contains(github.event.pull_request.labels.*.name, 'release alpha')
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
fetch-depth: 0

- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install

- name: Determine new version
id: versions
if: steps.bump-type.outputs.bump-type != 'null'
run: |
OLD_VERSION=$(jq ".version" package.json -r)
NEW_VERSION=$(pnpx semver $OLD_VERSION -i prerelease --preid alpha)
echo "old-version=$OLD_VERSION" >> "$GITHUB_OUTPUT"
echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Update version in package.json
if: steps.bump-type.outputs.bump-type != 'null'
run: |
mv package.json package.old.json
jq --indent 4 '.version = "${{ steps.versions.outputs.new-version }}"' package.old.json > package.json
rm package.old.json
- name: Publish the alpha in the npm registry
run: npm publish --access public --tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ If you forget to add the label, don't try to update the version locally as you w

To release an alpha or beta version, you'll need to use the CLI locally:

#### CLI

Only one person is set as a collaborator on NPM, so they're the only person that can manually publish alphas

1. Make sure you're a collaborator on `posthog-js` in npm ([check here](https://www.npmjs.com/package/posthog-js)).
2. Make sure you're logged into the npm CLI (`npm login`).
3. Check out your work-in-progress branch (do not release an alpha/beta from `main`).
Expand All @@ -91,3 +95,9 @@ To release an alpha or beta version, you'll need to use the CLI locally:
```

5. Enjoy the new prerelease version. You can now use it locally, in a dummy app, or in the [main repo](https://github.com/posthog/PostHog).

#### Automagically

Use the "release alpha" label on your PR to have an alpha version published automatically. This automation currently doesn't check whether an alpha exists for the version it will try to publish. If you need to publish two alphas from one PR you'll need to fix that

Remember that these versions are public and folk might use them, so make sure they're not _too_ alpha 🙈

0 comments on commit 2f093d3

Please sign in to comment.