Skip to content

v1.0.1

v1.0.1 #12

name: Verify and Deploy to GitHub Packages
on:
push:
branches:
- main
permissions:
contents: read
packages: write
id-token: write
jobs:
deploy_gpr_package:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://npm.pkg.github.com"
scope: "@proangular"
cache: "npm"
- name: Install
run: npm ci
- name: Build
run: npm run build
- name: Lint (optional)
if: hashFiles('.eslintrc*') != ''
run: npm run lint --if-present
- name: Test (optional)
run: npm test --if-present
- name: Read package version
id: pkg
shell: bash
run: |
VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("package.json","utf8")).version')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if version already exists on GitHub Packages
id: check
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
PKG=$(node -p "require('./package.json').name")
CURRENT=$(npm view "$PKG" version --registry=https://npm.pkg.github.com || echo "0.0.0")
echo "current_registry_version=$CURRENT" >> "$GITHUB_OUTPUT"
if [ "$CURRENT" = "${{ steps.pkg.outputs.version }}" ]; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "Version $CURRENT already exists on GitHub Packages. Skipping publish."
else
echo "should_publish=true" >> "$GITHUB_OUTPUT"
fi
- name: Publish to GitHub Packages
if: steps.check.outputs.should_publish == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: npm publish --registry=https://npm.pkg.github.com