ba-web-components/.forgejo/workflows/publish.yaml
Alan Bridgeman 7f93f3a5a8
All checks were successful
Build, Test, and Publish (to Private NPM Registry) UI Components Library / publish (push) Successful in 56s
Attempting to resolve issue with CI/CD pipeline
2026-05-13 15:20:40 -05:00

120 lines
No EOL
4.9 KiB
YAML

name: Build, Test, and Publish (to Private NPM Registry) UI Components Library
on:
push:
branches:
- main
workflow_dispatch:
jobs:
publish:
runs-on: default
env:
PRIVATE_NPM_REGISTRY: 'https://npm.pkg.bridgemanaccessible.ca'
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
# Set up NPM Auth Token
- name: Set up NPM Auth Token
run: echo "NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }}" >> $GITHUB_ENV
# Set up Node.js
- name: Set up Node.js version
uses: actions/setup-node@v4
with:
# Taken from [Repo README](https://github.com/actions/setup-node#readme)
#
# > Version Spec of the version to use in SemVer notation.
# > It also admits such aliases as lts/*, latest, nightly and canary builds
# > Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node
node-version: '22.x'
# Taken from [Repo README](https://github.com/actions/setup-node#readme)
#
# > Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file,
# > and set up auth to read in from env.NODE_AUTH_TOKEN.
# > Default: ''
registry-url: ${{ env.PRIVATE_NPM_REGISTRY }}
# Taken from [Repo README](https://github.com/actions/setup-node#readme)
#
# > Optional scope for authenticating against scoped registries.
# > Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
scope: '@BridgemanAccessible'
# Transpile/Build the package (TypeScript -> JavaScript)
- name: Transpile/Build the package (TypeScript -> JavaScript)
run: |
# Because Yarn is used locally better to install and use it than have to debug weird inconsistencies
npm install --global yarn
# Install needed dependencies
yarn install
# Build the package
yarn build
# We only need chromium for CI to save time, unless you configured multi-browser testing
- name: Install Playwright Browsers
run: |
echo "${{ secrets.SUDO_PASSWORD }}" | sudo -S -E env "PATH=$PATH" npx playwright install --with-deps chromium
# This will automatically boot your server.ts, run tests, and tear it down when done
- name: Run E2E Tests & Accessibility Audits
run: yarn test:run
- name: Determine Version and Increment (if needed)
id: version_check
run: |
VERSION=$(node -p "require('./package.json').version")
echo "Version: $VERSION"
NAME=$(node -p "require('./package.lib.json').name")
LATEST_VERSION=$(npm show $NAME version --registry ${{ env.PRIVATE_NPM_REGISTRY }} 2>/dev/null || echo "0.0.0")
echo "Latest version: $LATEST_VERSION"
if [ "$LATEST_VERSION" != "$VERSION" ]; then
echo "Manually updated version detected: $VERSION"
else
NEW_VERSION=$(npm version patch --no-git-tag-version)
echo "New version: $NEW_VERSION"
# Sync the newly generated version to package.lib.json so Gulp packages it correctly
node -e "const fs = require('fs'); const pkg = require('./package.lib.json'); pkg.version = require('./package.json').version; fs.writeFileSync('./package.lib.json', JSON.stringify(pkg, null, 2));"
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit Version Change (if needed)
if: steps.version_check.outputs.version_changed == 'true'
run: |
# Update remote URL to use the GITHUB_TOKEN for authentication
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@git.bridgemanaccessible.ca/${{ github.repository }}.git
# Setup git user details for committing the version change
git config user.name "Forgejo Actions"
git config user.email "actions@git.bridgemanaccessible.ca"
# Commit the version change to the `package.json` file
git add package.json package.lib.json
git commit -m "[Forgejo Actions] Update version to ${{ env.new_version }} [skip ci]"
# Push the changes to the repository
git push origin HEAD:main
# Generates the finalized `dist/` directory with `package.json` included
- name: Package Library
run: yarn package
# Publish to private NPM registry
- name: Publish the package
run: |
# Change directory to the build output (`dist`) folder
cd dist
# Publish the package to the private NPM registry
npm publish --registry ${{ env.PRIVATE_NPM_REGISTRY }}