Skip to content

Rebase and atomically push commit with tag in publish workflow #33

Rebase and atomically push commit with tag in publish workflow

Rebase and atomically push commit with tag in publish workflow #33

Workflow file for this run

name: "Publish"
on:
pull_request:
branches:
- main
types: [closed]
jobs:
publish_js:
name: "Create release for JS client"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./js
if: >-
${{ github.event.pull_request.merged == true && (
contains(github.event.pull_request.labels.*.name, 'patch') ||
contains(github.event.pull_request.labels.*.name, 'minor') ||
contains(github.event.pull_request.labels.*.name, 'major') ) }}
steps:
- name: Checkout the repository
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
with:
token: ${{ secrets.RELEASE_PAT }}
fetch-depth: 0
- name: Setup git user
run: |
git config user.name "neetobot"
git config user.email "neetobot.github@neeto.com"
- name: Setup NodeJS LTS version
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5
with:
node-version-file: ".nvmrc"
- name: Setup the project
run: yarn install
- name: Generate production build
run: yarn build
- name: Prefix version tag with "v"
run: yarn config set version-tag-prefix "v"
- name: Disable Git commit hooks
run: git config core.hooksPath /dev/null
- name: Bump the patch version and create git tag on release
if: ${{ contains(github.event.pull_request.labels.*.name, 'patch') }}
run: yarn version --patch
- name: Bump the minor version and create git tag on release
if: ${{ contains(github.event.pull_request.labels.*.name, 'minor') }}
run: yarn version --minor
- name: Bump the major version and create git tag on release
if: ${{ contains(github.event.pull_request.labels.*.name, 'major') }}
run: yarn version --major
- name: Get the package version from package.json
uses: tyankatsu0105/read-package-version-actions@v1
id: package-version
- name: Create a new version release commit
uses: EndBug/add-and-commit@290ea2c423ad77ca9c62ae0f5b224379612c0321 # v10
with:
message: "New version release"
push: false
- name: Rebase on latest main and push commit and tag
working-directory: ${{ github.workspace }}
run: |
VERSION=$(node -p "require('./js/package.json').version")
git fetch origin main
git rebase origin/main
git tag -f "v${VERSION}"
git push --atomic origin HEAD:main "refs/tags/v${VERSION}"
- name: Publish the package on NPM
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
npm publish