Publish PKG to NPM #120
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: "Publish PKG to NPM" | |
on: | |
workflow_dispatch: | |
inputs: | |
release: | |
type: choice | |
description: "Select version to publish" | |
required: true | |
options: | |
- pre-release | |
- release | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
GITHUB_EMAIL: ${{ secrets.GH_EMAIL }} | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node: [ '20.18.0' ] | |
env: | |
DO_NOT_TRACK: 1 | |
TURBO_TELEMETRY_DISABLED: 1 | |
name: "Publish" | |
steps: | |
- name: "⚙ Set up NodeJS v${{ matrix.node }}" | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node }} | |
- name: "✅ Checkout repository" | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: "💾 Restore Dependencies from cache" | |
uses: actions/cache@v4 | |
with: | |
path: | | |
node_modules | |
*/*/node_modules | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: "🦉 GitGuardian scan" | |
uses: GitGuardian/ggshield-action@master | |
env: | |
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }} | |
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }} | |
GITHUB_PULL_BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }} | |
- name: "📦 Install Dependencies" | |
run: yarn install | |
- name: "💅 Lint" | |
run: yarn lint | |
- name: "🔨 Build" | |
run: yarn build --force && node sonar-args.js | |
- name: "👨💻 Run Test" | |
run: yarn test --force | |
env: | |
NODE_ENV: 'test' | |
- name: "📊 Publish Test Report" | |
uses: dorny/test-reporter@v1 | |
if: success() || failure() | |
with: | |
name: "Test Report (${{ matrix.node }})" | |
path: 'packages/**/junit.xml' | |
reporter: jest-junit | |
- name: "📊 Upload coverage report to Codecov" | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: "📊 SonarCloud Scan" | |
uses: SonarSource/sonarcloud-github-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
#- name: "🦠 Snyk to check for vulnerabilities" | |
# uses: snyk/actions/node@master | |
# env: | |
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
- name: "🏷 Version packages as ${{ github.event.inputs.release }}" | |
run: | | |
# GIT and NPM config | |
git config --global user.name "GitHub CI/CD bot" | |
git config --global user.email "${GITHUB_EMAIL}" | |
if ${{github.event.inputs.release == 'pre-release'}}; then | |
yarn version:prerelease -m "ci(version): version packages as pre-release" | |
git add . | |
git commit -m "ci(version): version packages as pre-release" --no-verify | |
git push -f | |
else | |
yarn version:release -m "ci(version): version packages as release" | |
fi | |
- name: "🚀 Publish packages to npm 🎉" | |
run: | | |
npm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}" | |
npm run publish:pkgs | |
- name: "🔁 Rebase" | |
run: | | |
git remote set-url origin "https://github.com/${{ github.repository }}.git" | |
git config --global user.name "GitHub CI/CD bot" | |
git config --global user.email "${GITHUB_EMAIL}" | |
git config pull.rebase true | |
git fetch | |
git checkout develop | |
git pull | |
git merge --no-ff -m "ci(rebase): merge master" origin/master | |
git push -f |