Skip to content

Publish

Publish #5

Workflow file for this run

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Publish Packages
on:
push:
branches:
- main
jobs:
build-and-publish:
env:
HUSKY: 0
if: startsWith(github.event.head_commit.message, 'Publish') == true
runs-on: ubuntu-20.04
timeout-minutes: 15
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GH_PAT }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
cache: yarn
- name: Use Github Personal Access Token
run: git config --global url."https://${{ secrets.GH_PAT }}@github.com/".insteadOf ssh://git@github.com/
- name: Install Dependencies
run: yarn install --frozen-lockfile
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Build
run: NODE_ENV=production yarn build
- name: Fetch Latest Tags
run: |
git fetch --tags
- name: Set NPM Token
run: |
npm set '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_PUBLISH_TOKEN }}
npm whoami
- name: Publish
run: |
yarn lerna publish from-git --yes --allowBranch=main --loglevel=verbose --dist-tag latest
- name: Generate and Push Release Tag
id: push-release-tag
run: |
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
commit=${{ github.sha }}
if ! n=$(git rev-list --count $commit~ --grep "Publish" --since="00:00"); then
echo 'failed to calculate tag'
exit 1
fi
case "$n" in
0) suffix="" ;; # first commit of the day gets no suffix
*) suffix=".$n" ;; # subsequent commits get a suffix, starting with .1
esac
tag=$(printf release-$(date '+%Y-%m-%d%%s') $suffix)
git tag -a $tag -m "Release $tag"
git push origin $tag
echo "release-tag=$tag" >> $GITHUB_OUTPUT
- name: Create Github Release
id: create-github-release
uses: actions/github-script@v7
env:
RELEASE_TAG: ${{ steps.push-release-tag.outputs.release-tag }}
with:
script: |
const script = require('./scripts/create-github-release.js')
await script({github, context, core, exec})