Skip to content

Commit 7e6a45b

Browse files
[stable2509] Backport #11418 (#11428)
Backport #11418 into `stable2509` from EgorPopelyaev. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Egor_P <egor@parity.io>
1 parent 11da1d4 commit 7e6a45b

File tree

1 file changed

+59
-6
lines changed

1 file changed

+59
-6
lines changed

.github/workflows/release-80_publish-crates.yml

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ on:
2525
required: true
2626
type: boolean
2727
default: true
28+
resume_from:
29+
description: 'Resume from a specific phase after a failure. Use "full" for a fresh run.'
30+
required: true
31+
type: choice
32+
options:
33+
- full
34+
- apply
35+
- publish
36+
- push
37+
default: full
38+
prdoc_path:
39+
description: 'Path to the prdoc directory used by parity-publish plan to decide whci prdocs use for publishing'
40+
required: false
41+
type: string
42+
default: prdoc
2843

2944
permissions:
3045
contents: write
@@ -89,6 +104,19 @@ jobs:
89104
90105
echo "CRATES_RELEASE_BRANCH=post-crates-release-$RELEASE_NAME" >> $GITHUB_OUTPUT
91106
107+
- name: Validate resume preconditions
108+
if: inputs.resume_from != 'full'
109+
shell: bash
110+
env:
111+
CRATES_RELEASE_BRANCH: ${{ steps.derive_branch.outputs.CRATES_RELEASE_BRANCH }}
112+
RESUME_FROM: ${{ inputs.resume_from }}
113+
run: |
114+
if ! git ls-remote --heads origin "$CRATES_RELEASE_BRANCH" | grep -q "$CRATES_RELEASE_BRANCH"; then
115+
echo "❌ ::error::Cannot resume from '$RESUME_FROM': branch '$CRATES_RELEASE_BRANCH' does not exist on remote. Use 'full' for a fresh run."
116+
exit 1
117+
fi
118+
echo "Release branch '$CRATES_RELEASE_BRANCH' exists on remote. Resuming from '$RESUME_FROM'."
119+
92120
- name: Checkout stable branch
93121
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
94122
with:
@@ -118,9 +146,14 @@ jobs:
118146
shell: bash
119147
env:
120148
CRATES_RELEASE_BRANCH: ${{ steps.derive_branch.outputs.CRATES_RELEASE_BRANCH }}
149+
RESUME_FROM: ${{ inputs.resume_from }}
121150
run: |
122-
123-
if git rev-parse --verify -q "$CRATES_RELEASE_BRANCH" &>/dev/null; then
151+
if [ "$RESUME_FROM" != "full" ]; then
152+
# Resume: checkout the existing branch pushed during the previous failed run
153+
echo "Resuming from '$RESUME_FROM' - checking out existing branch $CRATES_RELEASE_BRANCH"
154+
git fetch origin "$CRATES_RELEASE_BRANCH"
155+
git checkout "$CRATES_RELEASE_BRANCH"
156+
elif git rev-parse --verify -q "$CRATES_RELEASE_BRANCH" &>/dev/null; then
124157
echo "Branch $CRATES_RELEASE_BRANCH already exists, switching to it"
125158
git checkout "$CRATES_RELEASE_BRANCH"
126159
else
@@ -146,15 +179,18 @@ jobs:
146179
- name: Install parity-publish
147180
run: |
148181
sudo apt-get update && sudo apt-get install -y --no-install-recommends libcurl4-openssl-dev pkg-config
149-
cargo install parity-publish@0.10.11 --locked -q
182+
cargo install parity-publish@0.10.12 --locked -q
150183
151184
- name: Run parity-publish plan
185+
if: inputs.resume_from == 'full'
186+
env:
187+
PRDOC_PATH: ${{ inputs.prdoc_path }}
152188
run: |
153189
echo "Running parity-publish plan..."
154-
parity-publish plan --prdoc prdoc
190+
parity-publish plan --prdoc $PRDOC_PATH
155191
156192
- name: Save Plan.toml diff
157-
if: inputs.is_patch
193+
if: inputs.resume_from == 'full' && inputs.is_patch
158194
env:
159195
RELEASE_NAME: ${{ inputs.release_name }}
160196
run: |
@@ -167,7 +203,7 @@ jobs:
167203
cat "release-artifacts/changed_crates_${RELEASE_NAME}.txt"
168204
169205
- name: Parse crate names for release notes
170-
if: inputs.is_patch
206+
if: inputs.resume_from == 'full' && inputs.is_patch
171207
shell: bash
172208
env:
173209
RELEASE_NAME: ${{ inputs.release_name }}
@@ -182,6 +218,7 @@ jobs:
182218
cat scripts/release/templates/crates_list.md.tera
183219
184220
- name: Commit Plan.toml and crates list
221+
if: inputs.resume_from == 'full'
185222
shell: bash
186223
env:
187224
IS_PATCH: ${{ inputs.is_patch }}
@@ -202,17 +239,20 @@ jobs:
202239
fi
203240
204241
- name: Run parity-publish apply
242+
if: inputs.resume_from == 'full' || inputs.resume_from == 'apply'
205243
run: |
206244
echo "Running parity-publish apply..."
207245
parity-publish apply
208246
209247
- name: Update Cargo.lock
248+
if: inputs.resume_from == 'full' || inputs.resume_from == 'apply'
210249
run: |
211250
echo "Updating Cargo.lock..."
212251
cargo update --workspace --offline || cargo update --workspace
213252
echo "Cargo.lock updated"
214253
215254
- name: Commit version bumps
255+
if: inputs.resume_from == 'full' || inputs.resume_from == 'apply'
216256
shell: bash
217257
env:
218258
RELEASE_NAME: ${{ inputs.release_name }}
@@ -229,6 +269,7 @@ jobs:
229269
fi
230270
231271
- name: Configure cargo registry
272+
if: inputs.resume_from != 'push'
232273
shell: bash
233274
env:
234275
REGISTRY: ${{ inputs.registry }}
@@ -249,6 +290,7 @@ jobs:
249290
cat ~/.cargo/config.toml || echo "(using defaults)"
250291
251292
- name: Publish crates
293+
if: inputs.resume_from != 'push'
252294
shell: bash
253295
env:
254296
PARITY_PUBLISH_CRATESIO_TOKEN: ${{ inputs.registry == 'staging.crates.io' && secrets.STAGING_CRATES_IO_API_TOKEN || secrets.CRATES_IO_API_TOKEN }}
@@ -284,3 +326,14 @@ jobs:
284326
git remote set-url origin "https://x-access-token:${TOKEN}@github.com/paritytech/polkadot-sdk.git"
285327
git push origin "$CRATES_RELEASE_BRANCH"
286328
echo "Successfully pushed $CRATES_RELEASE_BRANCH to paritytech/polkadot-sdk"
329+
330+
- name: Push release branch to fork on failure
331+
if: failure()
332+
env:
333+
CRATES_RELEASE_BRANCH: ${{ steps.derive_branch.outputs.CRATES_RELEASE_BRANCH }}
334+
run: |
335+
echo "Job failed. Pushing branch '$CRATES_RELEASE_BRANCH' to origin (paritytech-release) to preserve state for resume..."
336+
# Restore origin to the fork repo in case it was changed by the upstream push step
337+
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"
338+
git push origin "$CRATES_RELEASE_BRANCH" --force-with-lease
339+
echo "Branch pushed. To resume, re-run this workflow with resume_from set to the appropriate phase."

0 commit comments

Comments
 (0)