Skip to content

Commit

Permalink
wat
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Sep 12, 2024
1 parent 3a84541 commit 956b620
Showing 1 changed file with 62 additions and 61 deletions.
123 changes: 62 additions & 61 deletions .github/workflows/label-alpha-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,73 @@ name: Autorelease alpha version
on:
pull_request:
types:
- labeled # Triggers when any label is added to the PR
- labeled

jobs:
check-permissions:
name: "Check user has permission to release"
runs-on: ubuntu-latest
steps:
- uses: actions-cool/check-user-permission@v2
id: check-permissions
with:
require: 'write'
check-permissions:
name: "Check user has permission to release"
runs-on: ubuntu-latest
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'

- run: echo "user-permission = ${{ steps.check-permissions.outputs.user-permission }}"
- run: echo "require-result = ${{ steps.check-permissions.outputs.require-result }}"
- run: echo "check-result = ${{ steps.check-permissions.outputs.check-result }}"
warn-when-failed:
name: Warn when the user does not have the required permissions
runs-on: ubuntu-latest
if: |
steps.check-permissions.outputs.check-result == false
steps:
- run: echo "The user does not have the required permissions to trigger this action."
- run: echo "user-permission = ${{ steps.check-permissions.outputs.user-permission }}"
- run: echo "require-result = ${{ steps.check-permissions.outputs.require-result }}"
- run: echo "check-result = ${{ steps.check-permissions.outputs.check-result }}"
label-alpha-release:
name: Release alpha version based on PR label
runs-on: ubuntu-20.04
if: |
steps.check-permissions.outputs.check-result &&
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
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.check-result == 'false'
steps:
- run: echo "The user does not have the required permissions to trigger this action."
- run: echo "user-permission = ${{ needs.check-permissions.outputs.user-permission }}"
- run: echo "require-result = ${{ needs.check-permissions.outputs.require-result }}"
- run: echo "check-result = ${{ needs.check-permissions.outputs.check-result }}"

- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- run: pnpm install
label-alpha-release:
name: Release alpha version based on PR label
runs-on: ubuntu-20.04
needs: check-permissions
if: needs.check-permissions.outputs.check-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

- 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"
- 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: 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: 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: Publish the alpha in the npm registry
run: npm publish --access public --dry-run
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- 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 --dry-run
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 comments on commit 956b620

Please sign in to comment.