pin workflow #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build node-git-info Package | |
# Github documentation for publishing packages to Github Package Registry can be found here: | |
# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-github-packages | |
# Automatic token authentication and using the GITHUB_TOKEN in a workflow: | |
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication | |
# Example workflow for publishing a Node.js package: | |
# https://github.com/github-packages-examples/npm-publish/blob/master/.github/workflows/publish.yml | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://npm.pkg.github.com' | |
# Defaults to the user or organization that owns the workflow file | |
scope: ${{ github.repository_owner }} | |
- name: Print working directory | |
run: pwd | |
- name: Install pnpm | |
run: npm install -g [email protected] | |
- name: Install dependencies | |
run: pnpm install | |
working-directory: ./src | |
- name: Build Package | |
run: | | |
whoami | |
pwd | |
pnpm build | |
working-directory: ./src | |
- name: Run test suite | |
run: | | |
pnpm test | |
working-directory: ./src | |
- name: Prepare for publishing | |
run: | | |
echo "@RimuTec:registry=https://npm.pkg.github.com" > .npmrc | |
- name: Check for version change | |
id: version-check | |
run: | | |
# Fetch the history so we can access the last commit: | |
git fetch --depth=2 | |
# Get the version from the last commit | |
OLD_VERSION=$(git show HEAD^:src/package.json | jq -r '.version') | |
# Get the version from the current commit | |
NEW_VERSION=$(jq -r '.version' src/package.json) | |
# # Checkout back to the current commit's version | |
# git checkout HEAD -- src/package.json | |
# NEW_VERSION=$(jq -r '.version' src/package.json) | |
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then | |
echo "Version changed from $OLD_VERSION to $NEW_VERSION" | |
echo "CHANGED=true" >> $GITHUB_ENV | |
else | |
echo "Version unchanged" | |
echo "CHANGED=false" >> $GITHUB_ENV | |
fi | |
- name: Conditional Step - version has changed | |
if: env.CHANGED == 'true' | |
run: | | |
echo "Version changed. Proceeding with publish." | |
- name: Conditional Step - version has NOT change | |
if: env.CHANGED == 'false' | |
run: | | |
echo "Version has not changed. Nothing to publish." | |
# check if the file ./src/package.json has changed: | |
- name: changes | |
uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
filters: | | |
changed: | |
- ./src/package.json | |
- name: No changes detected | |
if: ${{ steps.changes.outputs.changed == 'false' }} | |
run: | | |
echo "No changes to ./src/package.json. Skipping publish." | |
- name: Publish | |
if: ${{ steps.changes.outputs.changed == 'true' }} | |
run: | | |
cat /home/runner/work/_temp/.npmrc | |
npm publish | |
working-directory: ./src | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# The following is NOT in the Github documentation but is required to make this work: | |
NPM_CONFIG_REGISTRY: 'https://npm.pkg.github.com/RimuTec' |