Skip to content

clean up the workflows #4

clean up the workflows

clean up the workflows #4

name: "Publish Packages"
on:
push:
branches:
- publish-packages
- fake-release
paths-ignore:
- '**.md'
- '**.txt'
- '.**ignore'
- 'docs/**'
# TODO: what if package.dependencies, files were updated?
# this is meant to avoid triggering the on.push event for the version bump
- '**package*.json'
workflow_dispatch:
inputs:
build_secret:
type: string
description: Build secret
workflow_call: {}
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
timeout-minutes: 20
steps:
- name: Check secret
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ github.event.inputs.build_secret }}" != "${{ secrets.BUILD_SECRET }}" ]; then
echo "Wrong build secret."
exit 1
fi
- name: Check user permission
if: github.event_name == 'workflow_dispatch'
id: check
uses: scherermichael-oss/action-has-permission@master
with:
required-permission: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Exit if user doesn't have write permission
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ steps.check.outputs.has-permission }}" = "false" ]; then
echo "Only users with write permission are allowed to execute this workflow."
exit 1
fi
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Fetch All Tags
run: git fetch --all --tags
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: '16'
registry-url: 'https://registry.npmjs.org'
scope: '@sjcrh'
- name: ⚡ Cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.OS }}-npm-cache-
- name: Install dependencies
run: npm ci
- name: Run version bump
run: |
VERTYPE=prerelease # default
NOTES=$(node ./build/changeLogGenerator.js -u)
if [[ "$NOTES" == *"Features:"* ]]; then
VERTYPE=minor
elif [[ "$NOTES" == *"Fixes:"* ]]; then
VERTYPE=patch
fi
# initial dot makes the variables of the call script in-scope
. ./build/ci-version-update.sh $VERTYPE -w -x=container
echo "UPDATED=$UPDATED" >> $GITHUB_ENV
- name: Publish packages
run: |
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" != "publish-packages" && "$BRANCH" != "release-chain" && "$BRANCH" != "master" && ${{ github.event_name }} != 'workflow_dispatch' ]]; then
echo "skipping publishing"
else
./build/ci-npm-publish.sh "$UPDATED"
if [[ "$BRANCH" != "master" ]]; then
echo "merging to master"
git fetch --depth=10 origin master:master
git switch master
git merge $BRANCH
git push
fi
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_TOKEN }}