Skip to content

Commit ece0210

Browse files
authored
fix(publish-preview-oidc): continue publishing when a package fails (#344)
* Continue publishing preview builds when a package fails `yarn workspaces foreach` stops starting new publishes after the first failure, so one broken package blocked every package after it. Loop over the public workspaces instead, log a warning for each failed publish, and carry on with the rest. * Report failed preview publishes in the build message The publish step now records each package as published or failed. The "Generate preview build message" step reads those lists instead of looking up every workspace again. Failed packages are listed with a link to the workflow run, and the message no longer says builds were published when none were.
1 parent 6fa04ca commit ece0210

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

‎.github/workflows/publish-preview-oidc.yml‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,18 @@ jobs:
150150

151151
- name: Publish preview builds (monorepo)
152152
if: ${{ inputs.is-monorepo && !inputs.dry-run }}
153-
run: yarn workspaces foreach --no-private --all exec yarn npm publish --tag preview
153+
run: |
154+
while IFS=$'\t' read -r name location; do
155+
version="$(jq -r '.version' "$location/package.json")"
156+
echo "::group::Publishing $name"
157+
if (cd "$location" && yarn npm publish --tag preview); then
158+
echo "${name}@${version}" >> "$RUNNER_TEMP/published.txt"
159+
else
160+
echo "::warning::Failed to publish $name"
161+
echo "${name}@${version}" >> "$RUNNER_TEMP/failed.txt"
162+
fi
163+
echo "::endgroup::"
164+
done < <(yarn workspaces list --no-private --json | jq -r '[.name, .location] | @tsv')
154165
env:
155166
YARN_NPM_REGISTRY_SERVER: 'https://registry.npmjs.org'
156167

@@ -175,27 +186,39 @@ jobs:
175186
fi
176187
177188
if [[ "$IS_MONOREPO" == "true" ]]; then
178-
packages="$(
179-
yarn workspaces list --no-private --json \
180-
| jq --raw-output '.location' \
181-
| xargs -I{} cat '{}/package.json' \
182-
| jq --raw-output '"\(.name)@\(.version)"'
183-
)"
184-
echo -n "Preview builds have been published." > preview-build-message.txt
185-
if [[ -n "$docs_link" ]]; then
186-
echo -n " ${docs_link}" >> preview-build-message.txt
187-
fi
188-
cat <<-MSGEOF >> preview-build-message.txt
189+
published="$(cat "$RUNNER_TEMP/published.txt" 2>/dev/null || true)"
190+
failed="$(cat "$RUNNER_TEMP/failed.txt" 2>/dev/null || true)"
191+
192+
if [[ -n "$published" ]]; then
193+
echo -n "Preview builds have been published." > preview-build-message.txt
194+
if [[ -n "$docs_link" ]]; then
195+
echo -n " ${docs_link}" >> preview-build-message.txt
196+
fi
197+
cat <<-MSGEOF >> preview-build-message.txt
189198
190199
<details>
191200
<summary>Expand for full list of packages and versions.</summary>
192201
193202
\`\`\`
194-
${packages}
203+
${published}
195204
\`\`\`
196205
197206
</details>
198207
MSGEOF
208+
else
209+
echo "No preview builds were published." > preview-build-message.txt
210+
fi
211+
212+
if [[ -n "$failed" ]]; then
213+
cat <<-MSGEOF >> preview-build-message.txt
214+
215+
The following packages failed to publish. [See the workflow run for details](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}).
216+
217+
\`\`\`
218+
${failed}
219+
\`\`\`
220+
MSGEOF
221+
fi
199222
else
200223
name="$(jq -r '.name' package.json)"
201224
version="$(jq -r '.version' package.json)"

0 commit comments

Comments
 (0)