Skip to content

fix: publish workflow part 4 #8

fix: publish workflow part 4

fix: publish workflow part 4 #8

name: Publish Package
on:
pull_request:
types: [closed]
branches:
# runs on main PRs targeting main
- main
permissions:
contents: write
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 -a "release-major"; then
VERSION_TYPE="major"
elif echo $LABELS | grep -a "release-minor"; then
VERSION_TYPE="minor"
elif echo $LABELS | grep -a "release-patch"; then
VERSION_TYPE="patch"
else
echo "::error::No valid release label found (release-major, release-minor, release-patch)."
exit 1
fi
echo "type=$VERSION_TYPE" >> $GITHUB_OUTPUT
echo "Running a $VERSION_TYPE release"
- 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: Tag release
id: bump-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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 "release: bump version to $NEW_VERSION"
git tag v$NEW_VERSION
git push --tags origin main
- 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 }}