From 2d213786e7710242429b7c03f19615170475c416 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 21 Nov 2023 20:59:32 -0500 Subject: [PATCH] chore(ci): add GitHub Action NPM publish prompt version workflow (#172) --- .github/workflows/publish-npm-prompt.yml | 110 +++++++++++++++++++++++ lerna.jsonc => lerna.json | 1 + package.json | 1 + pnpm-lock.yaml | 10 +++ 4 files changed, 122 insertions(+) create mode 100644 .github/workflows/publish-npm-prompt.yml rename lerna.jsonc => lerna.json (92%) diff --git a/.github/workflows/publish-npm-prompt.yml b/.github/workflows/publish-npm-prompt.yml new file mode 100644 index 000000000..10fa238d9 --- /dev/null +++ b/.github/workflows/publish-npm-prompt.yml @@ -0,0 +1,110 @@ +name: 🏷️ Publish NPM (version prompt) + +on: + workflow_dispatch: + inputs: + version: + description: 'Fixed Version' + required: true + type: string + tag: + type: choice + description: Tag + options: + - latest + - beta + +permissions: + contents: write + id-token: write + +jobs: + deploy-npm-beta: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Retrieve current Date Time in EST + shell: bash + run: echo "START_TIME=$(TZ=":America/New_York" date -R|sed 's/.....$//')" >> $GITHUB_ENV + + - name: Current datetime - ${{ env.START_TIME }} + run: echo ${{ env.START_TIME }} + + - name: Clone repository + uses: actions/checkout@v4 + with: + fetch-depth: 3 + token: ${{ secrets.GITHUB_TOKEN }} + + - if: ${{ github.event.pull_request.merged != true && contains('["ghiscoding"]', github.actor) != true }} + name: Ensure current actor is allowed to run the workflow + run: | + echo "Error: Your GitHub username (${{ github.actor }}) is not on the allowed list of admins for this workflow" + exit 1 + + - name: Set NodeJS + uses: actions/setup-node@v4 + with: + registry-url: 'https://registry.npmjs.org/' + node-version: 20 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + + - name: Get pnpm store directory + run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Setup pnpm cache + uses: actions/cache@v3 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Run pnpm install dependencies + run: pnpm install + + - name: Run all workspace TSC builds + run: pnpm build:full + + - name: Lerna Version (latest) 🏷️ + if: ${{ contains(inputs.tag, 'latest') }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + pnpm whoami + pnpm run ci:version ${{ inputs.version }} + + - name: Lerna Version (beta) 🏷️ + if: ${{ contains(inputs.tag, 'beta') }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + pnpm whoami + pnpm run lerna -- version prerelease --conventional-commits --conventional-prerelease --preid beta --force-publish --yes + + - name: OTP + uses: step-security/wait-for-secrets@v1 + id: wait-for-secrets + with: + secrets: | + OTP: + name: 'OTP to publish package' + description: 'OTP from authenticator app' + + - name: Lerna Publish 📦 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + pnpm run ci:publish --otp ${{ steps.wait-for-secrets.outputs.OTP }} \ No newline at end of file diff --git a/lerna.jsonc b/lerna.json similarity index 92% rename from lerna.jsonc rename to lerna.json index 1e0bf135e..f1b33da64 100644 --- a/lerna.jsonc +++ b/lerna.json @@ -20,6 +20,7 @@ "syncWorkspaceLock": true } }, + "changelogPreset": "conventional-changelog-conventionalcommits", "packages": [ "*" ] diff --git a/package.json b/package.json index 7df060093..24d3151b0 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "@types/node": "^20.9.3", "@typescript-eslint/eslint-plugin": "^6.12.0", "@typescript-eslint/parser": "^6.12.0", + "conventional-changelog-conventionalcommits": "^7.0.2", "cross-env": "^7.0.3", "eslint": "^8.54.0", "eslint-config-airbnb-base": "^15.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c85a90d6..c9580eb83 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: '@typescript-eslint/parser': specifier: ^6.12.0 version: 6.12.0(eslint@8.54.0)(typescript@5.3.2) + conventional-changelog-conventionalcommits: + specifier: ^7.0.2 + version: 7.0.2 cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -1919,6 +1922,13 @@ packages: compare-func: 2.0.0 dev: true + /conventional-changelog-conventionalcommits@7.0.2: + resolution: {integrity: sha512-NKXYmMR/Hr1DevQegFB4MwfM5Vv0m4UIxKZTTYuD98lpTknaZlSRrDOG4X7wIXpGkfsYxZTghUN+Qq+T0YQI7w==} + engines: {node: '>=16'} + dependencies: + compare-func: 2.0.0 + dev: true + /conventional-changelog-core@5.0.2: resolution: {integrity: sha512-RhQOcDweXNWvlRwUDCpaqXzbZemKPKncCWZG50Alth72WITVd6nhVk9MJ6w1k9PFNBcZ3YwkdkChE+8+ZwtUug==} engines: {node: '>=14'}