Skip to content

Publish packages

Publish packages #60

Workflow file for this run

# Simulate or publish the packages to npmjs.com
#
# Trigger a publication is a manual operation as there is no strong, automated mecanisms to ensure bug minimization.
#
# Publication strategies:
# - simulate: list the operations that would have been done during a publication.
# These operations are listed in the output of the action.
# - publication: do the operations (versions bumps, updated changelogs and Git tags) in a release branch,
# then merged it in the main branch once the publication has been done.
#
name: 🚀 Publish packages
on:
workflow_dispatch:
inputs:
PUBLICATION_MODE:
description: Publication mode
type: choice
options:
# Simulate the publication
- simulate
# Do the publication
- publish
default: simulate
required: true
VERSION_POLICY:
description: Version policy
type: choice
options:
# Increments according to their own minor or patch increment (depends of the type of changes made to each package)
- individualVersion
# Increments to the same major version. Use only for major releases.
- nextMajor
default: "individualVersion"
required: true
env:
# Force the main branch to be deployed, whatever the input is: avoid the publication of WIP code from other branches
SOURCE_BRANCH: main
TARGET_BRANCH: release/${{ github.run_id }}
jobs:
simulate:
if: inputs.PUBLICATION_MODE == 'simulate'
name: Simulate a publication to npmjs.org with the version policy ${{ inputs.VERSION_POLICY }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ env.SOURCE_BRANCH }}
- uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
- name: Git config user
uses: snow-actions/[email protected]
with:
name: Heart
email: [email protected]
- name: Bump packages versions numbers
run: node common/scripts/install-run-rush.js version --bump --version-policy ${{ inputs.VERSION_POLICY }}
- name: Simulate the publication
run: node common/scripts/install-run-rush.js publish --include-all --target-branch $TARGET_BRANCH --version-policy ${{ inputs.VERSION_POLICY }}
publish:
if: inputs.PUBLICATION_MODE == 'publish'
name: Publish to npmjs.org with the version policy ${{ inputs.VERSION_POLICY }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ env.SOURCE_BRANCH }}
- uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
- name: Git config user
uses: snow-actions/[email protected]
with:
name: Heart
email: [email protected]
- name: Install
run: node common/scripts/install-run-rush.js install
- name: 🏗 Build
run: node common/scripts/install-run-rush.js rebuild
- name: Create origin/${{ env.TARGET_BRANCH }} branch
run: |
git checkout -b $TARGET_BRANCH
git push origin $TARGET_BRANCH
# As we are using Rush version policies feature, we need to bump versions first:
# https://rushjs.io/pages/maintainer/publishing/#publishing-process-when-version-policies-are-used
- name: Bump packages versions numbers
run: node common/scripts/install-run-rush.js version --bump --target-branch $TARGET_BRANCH --version-policy ${{ inputs.VERSION_POLICY }}
- name: Publish to npmjs.org with the version policy ${{ inputs.VERSION_POLICY }}
run: node common/scripts/install-run-rush.js publish --include-all --target-branch $TARGET_BRANCH --version-policy ${{ inputs.VERSION_POLICY }} --publish
env:
# NPM_TOKEN is the expected environment variable name from common/config/rush/.npmrc-publish
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# Required step because of the test/ package
- name: Update lock file
run: |
node common/scripts/install-run-rush.js update
git add common/config/rush/pnpm-lock.yaml
git commit -m "feat: update lock file"
git push origin $TARGET_BRANCH
- name: Create a Pull Request
run: gh pr create --base $SOURCE_BRANCH --head $TARGET_BRANCH --fill --no-maintainer-edit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# We use a PAT (Personal Access Token) to do the following operations on the PR, as $GITHUB_TOKEN cannot review his own PR and cannot enforce repository settings.
# We use a merge commit to preserve Git tags added by the previous step and move them to the $TARGET_BRANCH.
# To make the merge commit work (--merge option), the "Allow merge commits" option must be checked in the repository settings.
# As the "Require linear history" option of the $SOURCE_BRANCH protected branch is on, we enforce this setting with the --admin flag.
- name: Review and merge the Pull Request, then delete the branch
run: |
gh pr review $TARGET_BRANCH --approve
gh pr merge $TARGET_BRANCH --merge --admin --delete-branch
env:
GH_TOKEN: ${{ secrets.BGATELLIER_PAT }}