Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Version Packages

Version Packages #4

# Based on https://github.com/Shopify/polaris
name: Snapshot Release
on:
issue_comment:
types:
- created
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
snapshot:
name: Snapshot Release
runs-on: ubuntu-latest
if: |
github.event.issue.pull_request &&
github.event.comment.body == '/snapshot' &&
github.repository == 'pedakihq/pedaki'
steps:
- name: Add initial reaction
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ github.event.comment.id }}
body: |
@${{ github.actor }} your snapshot release is being processed.
:eyes: Please wait while we run the release process.
- name: Enforce permission requirement
id: check-permissions
continue-on-error: true
uses: prince-chrismc/check-actor-permissions-action@v2
with:
permission: write
- name: Add reaction if permission requirement not met
if: steps.check-permissions.outcome == 'failure'
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ github.event.comment.id }}
reactions: confused
body: |
@${{ github.actor }} you do not have permission to run this command.
Please ask a maintainer to run this command for you.
- name: Exit if permission requirement not met
if: steps.check-permissions.outcome == 'failure'
run: exit 1
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
# Because changeset entries are consumed and removed on the
# 'changeset-release/main' branch, we need to reset the files
# so the following 'changeset version --snapshot' command will
# regenerate the package version bumps with the snapshot releases
- name: Reset changeset entries on changeset-release/main branch
run: |
if [[ $(git branch --show-current) == 'changeset-release/main' ]]; then
git checkout origin/main -- .changeset
fi
- uses: pnpm/action-setup@v2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install deps
run: pnpm install --child-concurrency 3 --frozen-lockfile --prefer-offline
- name: Create an .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
- name: Run Changeset
id: changeset
run: |
pnpm exec changeset version --snapshot
pnpm run publish:prepare
pnpm exec changeset publish --tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Format changeset comment
id: format-comment
run: |
changesetComment=$(echo "${{ steps.changesets.outputs.changeset-comment }}" | jq '.[] | "\(.name)@\(.version)"')
echo "changesetComment=$changesetComment" >> $GITHUB_OUTPUT
shell: bash
- name: Send success comment
uses: peter-evans/create-or-update-comment@v3
if: steps.changesets.outputs.published == 'true'
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket
body: |
@${{ github.actor }} your snapshot release has been published!
```
${{ steps.format-comment.outputs.changesetComment }}
```
- name: Send failure comment
uses: peter-evans/create-or-update-comment@v3
if: failure()
with:
comment-id: ${{ github.event.comment.id }}
reactions: x
body: |
@${{ github.actor }} your snapshot release failed to publish.
Please check the logs for more information.