Publish npm #65
Workflow file for this run
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 npm | |
on: | |
workflow_call: | |
inputs: | |
NODE_VERSION: | |
required: true | |
type: string | |
PNPM_VERSION: | |
required: true | |
type: string | |
PUBLISH_APPS: | |
required: true | |
type: boolean | |
PUBLISH_PACKAGES: | |
required: true | |
type: boolean | |
PUBLISH_PLUGINS: | |
required: true | |
type: boolean | |
CHECK_CHANGES: | |
required: true | |
type: boolean | |
secrets: | |
NPM_TOKEN: | |
required: true | |
workflow_dispatch: | |
inputs: | |
NODE_VERSION: | |
description: Nodejs version used | |
required: true | |
type: string | |
default: 22.13.0 | |
PNPM_VERSION: | |
description: Pnpm version used | |
required: true | |
type: string | |
default: 9.15.4 | |
PUBLISH_APPS: | |
description: Publish apps modules | |
required: true | |
type: boolean | |
default: false | |
PUBLISH_PACKAGES: | |
description: Publish packages modules | |
required: true | |
type: boolean | |
default: false | |
PUBLISH_PLUGINS: | |
description: Publish plugins modules | |
required: true | |
type: boolean | |
default: true | |
jobs: | |
path-filter: | |
if: ${{ inputs.CHECK_CHANGES }} | |
runs-on: ubuntu-latest | |
outputs: | |
packages: ${{ steps.filter.outputs.changes }} | |
steps: | |
- name: Checks-out repository | |
uses: actions/checkout@v4 | |
- name: Check updated files paths | |
uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: | | |
eslint-config: | |
- 'packages/eslintconfig/src/**' | |
shared: | |
- 'packages/shared/src/**' | |
hooks: | |
- 'packages/hooks/src/**' | |
ts-config: | |
- 'packages/tsconfig/**' | |
argocd: | |
- 'plugins/argocd/src/**' | |
gitlab: | |
- 'plugins/gitlab/src/**' | |
harbor: | |
- 'plugins/harbor/src/**' | |
keycloak: | |
- 'plugins/keycloak/src/**' | |
kubernetes: | |
- 'plugins/kubernetes/src/**' | |
nexus: | |
- 'plugins/nexus/src/**' | |
sonarqube: | |
- 'plugins/sonarqube/src/**' | |
vault: | |
- 'plugins/vault/src/**' | |
check-update: | |
name: Check for package version update | |
runs-on: ubuntu-latest | |
needs: | |
- path-filter | |
strategy: | |
matrix: | |
packages: ${{ fromJSON(needs.path-filter.outputs.packages) }} | |
steps: | |
- name: Checks-out repository | |
uses: actions/checkout@v4 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
id: pnpm-install | |
with: | |
version: "${{ inputs.PNPM_VERSION }}" | |
run_install: false | |
- name: Check changes | |
id: check | |
run: | | |
PACKAGE_NAME=$(jq -cr --arg p "${{ matrix.packages }}" '[.packages[], .plugins[]][] | select(.name | test($p)?) | .name' < ./ci/matrix-npm.json) | |
PACKAGE_PATH=$(jq -cr --arg p "${{ matrix.packages }}" '[.packages[], .plugins[]][] | select(.name | test($p)?) | .path' < ./ci/matrix-npm.json) | |
PACKAGE_VERSION=$(jq -cr '.version' < ${PACKAGE_PATH}/package.json) | |
if [ "$(curl -s -o /dev/null -I -w %{http_code} https://registry.npmjs.org/${PACKAGE_NAME})" = 404 ]; then | |
REMOTE=false | |
else | |
REMOTE=$(pnpm view ${PACKAGE_NAME} --json | jq --arg v "$PACKAGE_VERSION" 'any(.versions[] == $v; .)') | |
fi | |
if [ "$REMOTE" = "true" ]; then | |
echo "WARNING=true" >> $GITHUB_OUTPUT | |
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_OUTPUT | |
echo "PACKAGE_PATH=$PACKAGE_PATH" >> $GITHUB_OUTPUT | |
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_OUTPUT | |
else | |
echo "WARNING=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Comment PR | |
uses: thollander/actions-comment-pull-request@v2 | |
if: ${{ steps.check.outputs.WARNING == 'true' }} | |
with: | |
message: | | |
🤖 Hey ! | |
The __${{ steps.check.outputs.PACKAGE_NAME }} (v${{ steps.check.outputs.PACKAGE_VERSION }})__ package already exists [on npm](https://www.npmjs.com/package/${{ steps.check.outputs.PACKAGE_NAME }}/v/${{ steps.check.outputs.PACKAGE_VERSION }}) but the source code has changed, you should consider updating the package version. | |
*The version update warning should be ignored in the case of modifications that do not affect the code once it has been built, such as code formatting, etc...* | |
comment_tag: npm-check-${{ matrix.packages }} | |
matrix: | |
name: Generate matrix | |
if: ${{ inputs.PUBLISH_APPS || inputs.PUBLISH_PACKAGES || inputs.PUBLISH_PLUGINS }} | |
runs-on: ubuntu-latest | |
outputs: | |
publish-matrix: ${{ steps.packages-matrix.outputs.PUBLISH_MATRIX }} | |
steps: | |
- name: Checks-out repository | |
uses: actions/checkout@v4 | |
- name: Generate matrix | |
id: packages-matrix | |
run: | | |
PUBLISH_MATRIX="[]" | |
APPS_MATRIX="$(jq -c '.apps' < ./ci/matrix-npm.json)" | |
PACKAGES_MATRIX="$(jq -c '.packages' < ./ci/matrix-npm.json)" | |
PLUGINS_MATRIX="$(jq -c '.plugins' < ./ci/matrix-npm.json)" | |
if [ "${{ inputs.PUBLISH_APPS }}" = "true" ]; then | |
PUBLISH_MATRIX="$(jq -n -c --argjson acc "$PUBLISH_MATRIX" --argjson cur "$APPS_MATRIX" '$acc + $cur')" | |
fi | |
if [ "${{ inputs.PUBLISH_PACKAGES }}" = "true" ]; then | |
PUBLISH_MATRIX="$(jq -n -c --argjson acc "$PUBLISH_MATRIX" --argjson cur "$PACKAGES_MATRIX" '$acc + $cur')" | |
fi | |
if [ "${{ inputs.PUBLISH_PLUGINS }}" = "true" ]; then | |
PUBLISH_MATRIX="$(jq -n -c --argjson acc "$PUBLISH_MATRIX" --argjson cur "$PLUGINS_MATRIX" '$acc + $cur')" | |
fi | |
echo "PUBLISH_MATRIX=$PUBLISH_MATRIX" >> $GITHUB_OUTPUT | |
publish-npm: | |
name: Pubish on npm | |
if: ${{ inputs.PUBLISH_APPS || inputs.PUBLISH_PACKAGES || inputs.PUBLISH_PLUGINS }} | |
runs-on: ubuntu-latest | |
needs: | |
- matrix | |
strategy: | |
matrix: | |
modules: ${{ fromJSON(needs.matrix.outputs.publish-matrix) }} | |
steps: | |
- name: Checks-out repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.ref }} | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
id: pnpm-install | |
with: | |
version: "${{ inputs.PNPM_VERSION }}" | |
run_install: false | |
- name: Check for new package version | |
id: check-version | |
run: | | |
PACKAGE_VERSION=$(jq -cr '.version' < ${{ matrix.modules.path }}/package.json) | |
if [ "$(curl -s -o /dev/null -I -w %{http_code} https://registry.npmjs.org/${{ matrix.modules.name }})" = 404 ]; then | |
REMOTE=false | |
else | |
REMOTE=$(pnpm view ${{ matrix.modules.name }} --json | jq --arg v "$PACKAGE_VERSION" 'any(.versions[] == $v; .)') | |
fi | |
if [ "$REMOTE" = "true" ]; then | |
echo "Package ${{ matrix.modules.name }} - version $PACKAGE_VERSION already exists" | |
else | |
echo "Package ${{ matrix.modules.name }} - version $PACKAGE_VERSION does not exist" | |
fi | |
echo "REMOTE=$REMOTE" >> $GITHUB_OUTPUT | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
if: ${{ steps.check-version.outputs.REMOTE == 'false' }} | |
with: | |
node-version: "${{ inputs.NODE_VERSION }}" | |
registry-url: "https://registry.npmjs.org" | |
always-auth: true | |
- name: Get pnpm store directory | |
if: ${{ steps.check-version.outputs.REMOTE == 'false' }} | |
id: pnpm-store | |
run: | | |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
- name: Cache node files | |
if: ${{ steps.check-version.outputs.REMOTE == 'false' }} | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ steps.pnpm-store.outputs.STORE_PATH }} | |
key: node-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
node-${{ runner.os }}-${{ runner.arch }}- | |
- name: Install dependencies | |
if: ${{ steps.check-version.outputs.REMOTE == 'false' }} | |
run: pnpm install --frozen-lockfile | |
- name: Publish packages | |
if: ${{ steps.check-version.outputs.REMOTE == 'false' }} | |
run: | | |
# This line use turbo to handle build dependency graph | |
pnpm run build --filter ${{ matrix.modules.name }} | |
# This line use pnpm to publish without turbo | |
pnpm --filter ${{ matrix.modules.name }} publish --no-git-checks --report-summary | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |