Skip to content

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 NPM Github Package store
on:
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# When main is updated (latest)
push:
# branches:
# - 'main'
#On versioned releases
tags:
- v*.*.*
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- name: Install #run on lint step (Which is cached)
run: | # Install packages
npm install --prefer-offline --no-audit --ignore-scripts
# `npm rebuild` will run all those post-install scripts for us.
- name: rebuild and prepare
run: npm rebuild && npm run prepare --if-present
- run: npm run build
- run: npm run test
- uses: actions/upload-artifact@v4.3.1
with:
name: Tokens
path: ./dist
publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: npm list
- uses: actions/setup-node@v4 #setup registry to github package repo
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
# Defaults to the user or organization that owns the workflow file
#scope: '@${username}'
cache: 'npm'
- name: npm config output (including .npmrc file)
run: |
npm -v
node -v
cat /home/runner/work/_temp/.npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: npm install
- run: npm ci
- name: "Update package scope, export package name"
id: package_details
run: |
echo "replacing npm scope to repo owner GITHUB_REPOSITORY_OWNER = $GITHUB_REPOSITORY_OWNER"
temp_file=$(mktemp)
package=${GITHUB_REPOSITORY_OWNER,,}
awk -v scope="$package" '{
if ($0 ~ /"name": "@[a-zA-Z0-9_-]+\//) {
sub(/@[a-zA-Z0-9_-]+\//, "@" scope "/")
}
print
}' package.json > "$temp_file" && mv "$temp_file" package.json
echo "package.json updated"
cat package.json
echo "package=`npm pkg get name`" >> $GITHUB_STATE
- uses: tobysmith568/npm-publish-latest-tag@v1
id: latest_tag
with:
package-json: ./package.json
# - uses: actions/delete-package-versions@v5
# with: #Delete all except latest 3 package versions excluding major versions as per semver from a repo not having access to package
## owner: 'github'
# package-name: ${{ steps.package_details.outputs.package }}
# package-type: 'npm'
## token: ${{ secrets.GITHUB_PAT }}
# min-versions-to-keep: 3
# ignore-versions: '^(0|[1-9]\\d*)\\.0\\.0$'
# env:
# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- run: npm publish --tag ${{ steps.latest_tag.outputs.latest-tag }}
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}