Release NPM packages #57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release NPM packages | |
on: | |
workflow_dispatch: | |
# Require a version bump (patch, minor, major) and an optional dist tag | |
inputs: | |
version_bump: | |
description: 'Version bump (patch, minor, or major)' | |
required: true | |
default: 'patch' | |
dist_tag: | |
description: 'Dist tag (latest, next, etc.)' | |
required: false | |
default: 'latest' | |
jobs: | |
release: | |
# Only run this workflow from the trunk branch and when it's triggered by dmsnell OR adamziel | |
if: > | |
github.ref == 'refs/heads/trunk' && ( | |
github.actor == 'adamziel' || | |
github.actor == 'dmsnell' || | |
github.actor == 'bgrgicak' || | |
github.actor == 'brandonpayton' | |
) | |
# Specify runner + deployment step | |
runs-on: ubuntu-latest | |
environment: | |
name: npm | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
clean: true | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: 'Install bun (for the changelog)' | |
run: | | |
curl -fsSL https://bun.sh/install | bash | |
- name: Config git user | |
run: | | |
git config --global user.name "deployment_bot" | |
git config --global user.email "[email protected]" | |
git remote set-url origin https://${{ secrets.GH_ACTOR }}:${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }} | |
- name: Authenticate with Registry | |
run: | | |
echo "@php-wasm:registry=https://registry.npmjs.org/" > ~/.npmrc | |
echo "@wp-playground:registry=https://registry.npmjs.org/" >> ~/.npmrc | |
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc | |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc | |
- uses: ./.github/actions/prepare-playground | |
# Version bump, release, tag a new version on GitHub | |
- name: Release new version of NPM packages | |
shell: bash | |
run: npx [email protected] publish ${{ inputs.version_bump }} --yes --no-private --loglevel=verbose --dist-tag=${{ inputs.dist_tag }} | |
- name: '✏️ Generate release changelog' | |
run: | | |
npm run changelog -- --version=current | |
- name: '📦 Commit and push changelog' | |
run: | | |
- name: '📦 Commit and push changelog' | |
run: | | |
if [[ -n $(git status --porcelain CHANGELOG.md) ]]; then | |
git commit CHANGELOG.md -m "chore: update changelog" | |
git push origin HEAD:${{ github.event.pull_request.head.ref }} | |
else | |
echo "No changes in CHANGELOG.md. Skipping commit and push." | |
fi |