@@ -128,18 +128,26 @@ jobs:
128128 shell : bash
129129 id : lerna-publish
130130 run : |
131- # Attempt to publish all packages
132- pnpm exec lerna publish from-package --force-publish --yes --otp ${{ steps.wait-for-secrets.outputs.OTP }}
133- EXIT_CODE=$?
134- echo "EXIT_CODE=$EXIT_CODE" >> $GITHUB_ENV
135- OUTPUT=$(cat /dev/stdout)
136- echo "OUTPUT=$OUTPUT" >> $GITHUB_ENV
131+ set -o pipefail
132+ OUTPUT_FILE=$(mktemp)
133+ pnpm exec lerna publish from-package --force-publish --yes --otp ${{ steps.wait-for-secrets.outputs.OTP }} 2>&1 | tee $OUTPUT_FILE
134+ EXIT_CODE=${PIPESTATUS[0]}
135+ OUTPUT=$(cat $OUTPUT_FILE)
136+ echo "publish_failed=false" >> $GITHUB_OUTPUT
137+ echo "publish_output<<EOF" >> $GITHUB_OUTPUT
138+ echo "$OUTPUT" >> $GITHUB_OUTPUT
139+ echo "EOF" >> $GITHUB_OUTPUT
137140 if [ $EXIT_CODE -ne 0 ]; then
138- echo "::set-output name=publish_failed::true"
141+ if echo "$OUTPUT" | grep -q 'HttpErrorAuthOTP'; then
142+ echo "publish_failed=true" >> $GITHUB_OUTPUT
143+ else
144+ echo "::error title=Lerna Publish Failed::$OUTPUT"
145+ exit $EXIT_CODE
146+ fi
139147 fi
140148
141149 - name : Check for EOTP and Prompt for New OTP
142- if : ${{ steps.lerna-publish.outputs.publish_failed == 'true' && contains(env.OUTPUT, 'HttpErrorAuthOTP') }}
150+ if : ${{ steps.lerna-publish.outputs.publish_failed == 'true' }}
143151 uses : step-security/wait-for-secrets@v1
144152 id : wait-for-new-otp
145153 with :
@@ -149,14 +157,13 @@ jobs:
149157 description: 'OTP from authenticator app'
150158
151159 - name : Retry Lerna Publish with New OTP
152- if : ${{ steps.lerna-publish.outputs.publish_failed == 'true' && contains(env.OUTPUT, 'HttpErrorAuthOTP') }}
160+ if : ${{ steps.lerna-publish.outputs.publish_failed == 'true' }}
153161 env :
154162 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
155163 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
156164 NPM_CONFIG_PROVENANCE : true
157165 shell : bash
158166 run : |
159- # Retry the publish command with the new OTP
160167 pnpm exec lerna publish from-package --force-publish --yes --otp ${{ steps.wait-for-new-otp.outputs.OTP }} || {
161168 echo "::error title=Publish Failed::Publishing failed even after providing a new OTP."
162169 exit 1
0 commit comments