Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Publish Package

on:
pull_request:
types: [closed]
branches:
# runs on main PRs targeting main
- main

permissions:
contents: write # To push version bump commit and tag

jobs:
publish:
if: github.event.pull_request.merged == true && (contains(github.event.pull_request.labels.*.name, 'release-major') || contains(github.event.pull_request.labels.*.name, 'release-minor') || contains(github.event.pull_request.labels.*.name, 'release-patch'))
runs-on: ubuntu-latest
steps:
- name: Determine version type from label
id: version-type
run: |
LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}"
if echo "$LABELS" | grep -q '"release-major"'; then
echo "type=major" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -q '"release-minor"'; then
echo "type=minor" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -q '"release-patch"'; then
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "::error::No valid release label found (release-major, release-minor, release-patch)."
exit 1
fi

- name: Checkout
uses: actions/checkout@v3
with:
ref: "main"
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18.15"
cache: "yarn"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: yarn install --frozen-lockfile --non-interactive

- name: Build
run: yarn build

- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"

- name: Bump version
id: bump-version
run: |
VERSION_TYPE="${{ steps.version-type.outputs.type }}"
yarn version --"$VERSION_TYPE" --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
git add package.json
git commit -m "chore: bump version to $NEW_VERSION"
git push

- name: Create tag
run: |
NEW_VERSION=${{ steps.bump-version.outputs.new_version }}
git tag v$NEW_VERSION
git push --tags

- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.bump-version.outputs.new_version }}
release_name: v${{ steps.bump-version.outputs.new_version }}
draft: false
prerelease: false

- name: Publish to NPM
run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading