Skip to content

Commit 4e0d623

Browse files
committed
chore: update npm release CI workflow
1 parent d1f553d commit 4e0d623

3 files changed

Lines changed: 43 additions & 20 deletions

File tree

.github/workflows/publish-npm-prerelease.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,26 @@ jobs:
173173
shell: bash
174174
id: lerna-publish
175175
run: |
176-
# Attempt to publish all packages
177-
pnpm exec lerna publish from-package --force-publish --dist-tag ${{ inputs.tag }} --yes --otp ${{ steps.wait-for-secrets.outputs.OTP }}
178-
EXIT_CODE=$?
179-
echo "EXIT_CODE=$EXIT_CODE" >> $GITHUB_ENV
180-
OUTPUT=$(cat /dev/stdout)
181-
echo "OUTPUT=$OUTPUT" >> $GITHUB_ENV
176+
set -o pipefail
177+
OUTPUT_FILE=$(mktemp)
178+
pnpm exec lerna publish from-package --force-publish --dist-tag ${{ inputs.tag }} --yes --otp ${{ steps.wait-for-secrets.outputs.OTP }} 2>&1 | tee $OUTPUT_FILE
179+
EXIT_CODE=${PIPESTATUS[0]}
180+
OUTPUT=$(cat $OUTPUT_FILE)
181+
echo "publish_failed=false" >> $GITHUB_OUTPUT
182+
echo "publish_output<<EOF" >> $GITHUB_OUTPUT
183+
echo "$OUTPUT" >> $GITHUB_OUTPUT
184+
echo "EOF" >> $GITHUB_OUTPUT
182185
if [ $EXIT_CODE -ne 0 ]; then
183-
echo "::set-output name=publish_failed::true"
186+
if echo "$OUTPUT" | grep -q 'HttpErrorAuthOTP'; then
187+
echo "publish_failed=true" >> $GITHUB_OUTPUT
188+
else
189+
echo "::error title=Lerna Publish Failed::$OUTPUT"
190+
exit $EXIT_CODE
191+
fi
184192
fi
185193
186194
- name: Check for EOTP and Prompt for New OTP
187-
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' && contains(env.OUTPUT, 'HttpErrorAuthOTP') }}
195+
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' }}
188196
uses: step-security/wait-for-secrets@v1
189197
id: wait-for-new-otp
190198
with:
@@ -194,14 +202,13 @@ jobs:
194202
description: 'OTP from authenticator app'
195203
196204
- name: Retry Lerna Publish with New OTP
197-
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' && contains(env.OUTPUT, 'HttpErrorAuthOTP') }}
205+
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' }}
198206
env:
199207
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200208
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
201209
NPM_CONFIG_PROVENANCE: true
202210
shell: bash
203211
run: |
204-
# Retry the publish command with the new OTP
205212
pnpm exec lerna publish from-package --force-publish --dist-tag ${{ inputs.tag }} --yes --otp ${{ steps.wait-for-new-otp.outputs.OTP }} || {
206213
echo "::error title=Publish Failed::Publishing failed even after providing a new OTP."
207214
exit 1

.github/workflows/publish-npm-prompt.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,26 @@ jobs:
124124
shell: bash
125125
id: lerna-publish
126126
run: |
127-
# Attempt to publish all packages
128-
pnpm exec lerna publish from-package --force-publish --yes --otp ${{ steps.wait-for-secrets.outputs.OTP }}
129-
EXIT_CODE=$?
130-
echo "EXIT_CODE=$EXIT_CODE" >> $GITHUB_ENV
131-
OUTPUT=$(cat /dev/stdout)
132-
echo "OUTPUT=$OUTPUT" >> $GITHUB_ENV
127+
set -o pipefail
128+
OUTPUT_FILE=$(mktemp)
129+
pnpm exec lerna publish from-package --force-publish --yes --otp ${{ steps.wait-for-secrets.outputs.OTP }} 2>&1 | tee $OUTPUT_FILE
130+
EXIT_CODE=${PIPESTATUS[0]}
131+
OUTPUT=$(cat $OUTPUT_FILE)
132+
echo "publish_failed=false" >> $GITHUB_OUTPUT
133+
echo "publish_output<<EOF" >> $GITHUB_OUTPUT
134+
echo "$OUTPUT" >> $GITHUB_OUTPUT
135+
echo "EOF" >> $GITHUB_OUTPUT
133136
if [ $EXIT_CODE -ne 0 ]; then
134-
echo "::set-output name=publish_failed::true"
137+
if echo "$OUTPUT" | grep -q 'HttpErrorAuthOTP'; then
138+
echo "publish_failed=true" >> $GITHUB_OUTPUT
139+
else
140+
echo "::error title=Lerna Publish Failed::$OUTPUT"
141+
exit $EXIT_CODE
142+
fi
135143
fi
136144
137145
- name: Check for EOTP and Prompt for New OTP
138-
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' && contains(env.OUTPUT, 'HttpErrorAuthOTP') }}
146+
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' }}
139147
uses: step-security/wait-for-secrets@v1
140148
id: wait-for-new-otp
141149
with:
@@ -145,14 +153,13 @@ jobs:
145153
description: 'OTP from authenticator app'
146154
147155
- name: Retry Lerna Publish with New OTP
148-
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' && contains(env.OUTPUT, 'HttpErrorAuthOTP') }}
156+
if: ${{ steps.lerna-publish.outputs.publish_failed == 'true' }}
149157
env:
150158
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151159
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
152160
NPM_CONFIG_PROVENANCE: true
153161
shell: bash
154162
run: |
155-
# Retry the publish command with the new OTP
156163
pnpm exec lerna publish from-package --force-publish --yes --otp ${{ steps.wait-for-new-otp.outputs.OTP }} || {
157164
echo "::error title=Publish Failed::Publishing failed even after providing a new OTP."
158165
exit 1

.github/workflows/publish-npm-publish-retry.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ jobs:
6969
- name: Build Everything
7070
run: pnpm build
7171

72+
# because ng-packagr copies the package.json to dist,
73+
# we need to re-run the build to get latest version in its dist/package.json
74+
- name: run another Angular-Slickgrid build
75+
run: pnpm run angular:build:framework
76+
77+
# then we need to replace all `workspace:` protocol with valid workspace package versions
78+
- name: replace Angular-Slickgrid "workspace:"
79+
run: pnpm run angular:replace-workspace
80+
7281
- name: OTP
7382
if: ${{ inputs.dryrun != true }}
7483
uses: step-security/wait-for-secrets@v1

0 commit comments

Comments
 (0)