|
| 1 | +name: Release - Publish Crates |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_name: |
| 7 | + description: 'Release name (e.g., stable2509-3). Base branch is derived by removing the last -N suffix.' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + registry: |
| 11 | + description: 'Registry to publish crates to' |
| 12 | + required: true |
| 13 | + type: choice |
| 14 | + options: |
| 15 | + - staging.crates.io |
| 16 | + - crates.io |
| 17 | + default: staging.crates.io |
| 18 | + is_patch: |
| 19 | + description: 'Is this a patch release? (Set to false for new stable releases)' |
| 20 | + required: true |
| 21 | + type: boolean |
| 22 | + default: true |
| 23 | + dry_run: |
| 24 | + description: 'Dry run - do not actually publish crates' |
| 25 | + required: true |
| 26 | + type: boolean |
| 27 | + default: true |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + |
| 32 | +jobs: |
| 33 | + check-synchronization: |
| 34 | + uses: paritytech-release/sync-workflows/.github/workflows/check-synchronization.yml@main |
| 35 | + secrets: |
| 36 | + fork_writer_app_key: ${{ secrets.UPSTREAM_CONTENT_SYNC_APP_KEY }} |
| 37 | + |
| 38 | + set-image: |
| 39 | + needs: [ check-synchronization ] |
| 40 | + if: needs.check-synchronization.outputs.checks_passed == 'true' |
| 41 | + runs-on: ubuntu-latest |
| 42 | + outputs: |
| 43 | + IMAGE: ${{ steps.set_image.outputs.IMAGE }} |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 47 | + |
| 48 | + - id: set_image |
| 49 | + run: cat .github/env >> $GITHUB_OUTPUT |
| 50 | + |
| 51 | + publish-crates: |
| 52 | + needs: set-image |
| 53 | + runs-on: ubuntu-latest |
| 54 | + environment: release |
| 55 | + env: |
| 56 | + PGP_KMS_KEY: ${{ secrets.PGP_KMS_SIGN_COMMITS_KEY }} |
| 57 | + PGP_KMS_HASH: ${{ secrets.PGP_KMS_HASH }} |
| 58 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 59 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 60 | + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} |
| 61 | + container: |
| 62 | + image: ${{ needs.set-image.outputs.IMAGE }} |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Install pgpkms |
| 66 | + run: | |
| 67 | + # Install pgpkms that is used to sign commits |
| 68 | + pip install git+https://github.com/paritytech-release/pgpkms.git@6cb1cecce1268412189b77e4b130f4fa248c4151 |
| 69 | +
|
| 70 | + - name: Derive stable branch from release name |
| 71 | + id: derive_branch |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + RELEASE_NAME="${{ inputs.release_name }}" |
| 75 | + echo "Release name: $RELEASE_NAME" |
| 76 | +
|
| 77 | + # Extract stable branch by removing the last -N suffix |
| 78 | + # e.g., stable2509-3 -> stable2509 |
| 79 | + if [[ "$RELEASE_NAME" =~ ^(.+)-[0-9]+$ ]]; then |
| 80 | + STABLE_BRANCH="${BASH_REMATCH[1]}" |
| 81 | + else |
| 82 | + # If no suffix, use the release name as-is (first release) |
| 83 | + STABLE_BRANCH="$RELEASE_NAME" |
| 84 | + fi |
| 85 | +
|
| 86 | + echo "Stable branch: $STABLE_BRANCH" |
| 87 | + echo "STABLE_BRANCH=$STABLE_BRANCH" >> $GITHUB_OUTPUT |
| 88 | +
|
| 89 | + echo "CRATES_RELEASE_BRANCH=post-crates-release-$RELEASE_NAME" >> $GITHUB_OUTPUT |
| 90 | +
|
| 91 | + - name: Checkout stable branch |
| 92 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 93 | + with: |
| 94 | + ref: ${{ steps.derive_branch.outputs.STABLE_BRANCH }} |
| 95 | + fetch-depth: 0 |
| 96 | + |
| 97 | + - name: Import GPG keys |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + . ./.github/scripts/common/lib.sh |
| 101 | + import_gpg_keys |
| 102 | +
|
| 103 | + - name: Configure git |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + git config --global --add safe.directory "${GITHUB_WORKSPACE}" |
| 107 | + git config --global commit.gpgsign true |
| 108 | + PGPKMS_PATH=$(which pgpkms-git) |
| 109 | + echo "Using pgpkms-git at: $PGPKMS_PATH" |
| 110 | + git config --global gpg.program "$PGPKMS_PATH" |
| 111 | + git config --global user.name "ParityReleases" |
| 112 | + git config --global user.email "release-team@parity.io" |
| 113 | + git config --global user.signingKey "D8018FBB3F534D866A45998293C5FB5F6A367B51" |
| 114 | +
|
| 115 | + - name: Create or switch to release branch |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + CRATES_RELEASE_BRANCH="${{ steps.derive_branch.outputs.CRATES_RELEASE_BRANCH }}" |
| 119 | +
|
| 120 | + if git rev-parse --verify -q "$CRATES_RELEASE_BRANCH" &>/dev/null; then |
| 121 | + echo "Branch $CRATES_RELEASE_BRANCH already exists, switching to it" |
| 122 | + git checkout "$CRATES_RELEASE_BRANCH" |
| 123 | + else |
| 124 | + echo "Creating branch: $CRATES_RELEASE_BRANCH" |
| 125 | + git checkout -b "$CRATES_RELEASE_BRANCH" |
| 126 | + fi |
| 127 | + echo "On branch $CRATES_RELEASE_BRANCH" |
| 128 | +
|
| 129 | + - name: Install Rust 1.93 |
| 130 | + shell: bash |
| 131 | + run: | |
| 132 | + rustup install 1.93 |
| 133 | + rustup default 1.93 |
| 134 | + echo "Rust version:" |
| 135 | + rustc --version |
| 136 | + cargo --version |
| 137 | +
|
| 138 | + - name: Rust Cache |
| 139 | + uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 |
| 140 | + with: |
| 141 | + cache-on-failure: true |
| 142 | + |
| 143 | + - name: Install parity-publish |
| 144 | + run: | |
| 145 | + apt-get update && apt-get install -y --no-install-recommends libcurl4-openssl-dev pkg-config |
| 146 | + cargo install parity-publish@0.10.10 --locked -q |
| 147 | +
|
| 148 | + - name: Run parity-publish plan |
| 149 | + run: | |
| 150 | + echo "Running parity-publish plan..." |
| 151 | + parity-publish plan --prdoc prdoc |
| 152 | +
|
| 153 | + - name: Save Plan.toml diff |
| 154 | + if: inputs.is_patch |
| 155 | + run: | |
| 156 | + RELEASE_NAME="${{ inputs.release_name }}" |
| 157 | + mkdir -p release-artifacts |
| 158 | +
|
| 159 | + echo "Saving Plan.toml diff..." |
| 160 | + git diff Plan.toml > "release-artifacts/changed_crates_${RELEASE_NAME}.txt" |
| 161 | +
|
| 162 | + echo "Plan.toml changes:" |
| 163 | + cat "release-artifacts/changed_crates_${RELEASE_NAME}.txt" |
| 164 | +
|
| 165 | + - name: Parse crate names for release notes |
| 166 | + if: inputs.is_patch |
| 167 | + shell: bash |
| 168 | + run: | |
| 169 | + RELEASE_NAME="${{ inputs.release_name }}" |
| 170 | +
|
| 171 | + echo "Parsing crate names..." |
| 172 | + python3 scripts/release/parse-crates-names.py \ |
| 173 | + "release-artifacts/changed_crates_${RELEASE_NAME}.txt" \ |
| 174 | + scripts/release/templates/crates_list.md.tera |
| 175 | +
|
| 176 | + echo "Crates list:" |
| 177 | + cat scripts/release/templates/crates_list.md.tera |
| 178 | +
|
| 179 | + - name: Commit Plan.toml and crates list |
| 180 | + shell: bash |
| 181 | + run: | |
| 182 | + . ./.github/scripts/release/release_lib.sh |
| 183 | +
|
| 184 | + git add Plan.toml |
| 185 | + if [ "${{ inputs.is_patch }}" = true ]; then |
| 186 | + git add scripts/release/templates/crates_list.md.tera |
| 187 | + fi |
| 188 | +
|
| 189 | + if [[ -n $(git status --porcelain) ]]; then |
| 190 | + commit_with_message "chore: update Plan.toml and crates list for ${{ inputs.release_name }}" |
| 191 | + echo "Committed Plan.toml and crates list" |
| 192 | + else |
| 193 | + echo "No changes to commit" |
| 194 | + fi |
| 195 | +
|
| 196 | + - name: Run parity-publish apply |
| 197 | + run: | |
| 198 | + echo "Running parity-publish apply..." |
| 199 | + parity-publish apply |
| 200 | +
|
| 201 | + - name: Update Cargo.lock |
| 202 | + run: | |
| 203 | + echo "Updating Cargo.lock..." |
| 204 | + cargo update --workspace --offline || cargo update --workspace |
| 205 | + echo "Cargo.lock updated" |
| 206 | +
|
| 207 | + - name: Commit version bumps |
| 208 | + shell: bash |
| 209 | + run: | |
| 210 | + . ./.github/scripts/release/release_lib.sh |
| 211 | +
|
| 212 | + git add -A |
| 213 | +
|
| 214 | + if [[ -n $(git status --porcelain) ]]; then |
| 215 | + commit_with_message "chore: apply version bumps for ${{ inputs.release_name }}" |
| 216 | + echo "Committed version bumps" |
| 217 | + else |
| 218 | + echo "No changes to commit" |
| 219 | + fi |
| 220 | +
|
| 221 | + - name: Push release branch |
| 222 | + run: | |
| 223 | + CRATES_RELEASE_BRANCH="${{ steps.derive_branch.outputs.CRATES_RELEASE_BRANCH }}" |
| 224 | + echo "Pushing branch $CRATES_RELEASE_BRANCH..." |
| 225 | + git push origin "$CRATES_RELEASE_BRANCH" |
| 226 | + echo "Successfully pushed $CRATES_RELEASE_BRANCH" |
| 227 | +
|
| 228 | + - name: Configure cargo registry |
| 229 | + shell: bash |
| 230 | + run: | |
| 231 | + REGISTRY="${{ inputs.registry }}" |
| 232 | + echo "Configuring cargo for $REGISTRY..." |
| 233 | + mkdir -p ~/.cargo |
| 234 | +
|
| 235 | + if [ "$REGISTRY" = "staging.crates.io" ]; then |
| 236 | + cat >> ~/.cargo/config.toml << 'EOF' |
| 237 | + [registries.crates-io] |
| 238 | + index = "sparse+https://index.staging.crates.io/" |
| 239 | + EOF |
| 240 | + else |
| 241 | + echo "Using default crates.io registry" |
| 242 | + fi |
| 243 | +
|
| 244 | + echo "Cargo config:" |
| 245 | + cat ~/.cargo/config.toml || echo "(using defaults)" |
| 246 | +
|
| 247 | + - name: Publish crates |
| 248 | + shell: bash |
| 249 | + env: |
| 250 | + PARITY_PUBLISH_CRATESIO_TOKEN: ${{ inputs.registry == 'staging.crates.io' && secrets.STAGING_CRATES_IO_API_TOKEN || secrets.CRATES_IO_API_TOKEN }} |
| 251 | + run: | |
| 252 | + DRY_RUN="${{ inputs.dry_run }}" |
| 253 | + REGISTRY="${{ inputs.registry }}" |
| 254 | +
|
| 255 | + if [ "$DRY_RUN" = true ]; then |
| 256 | + echo "DRY RUN - Not actually publishing crates" |
| 257 | + echo "Target registry: $REGISTRY" |
| 258 | + parity-publish apply -p -d |
| 259 | + else |
| 260 | + echo "Publishing crates to $REGISTRY..." |
| 261 | + parity-publish apply -p |
| 262 | + echo "Crates published successfully to $REGISTRY!" |
| 263 | + fi |
0 commit comments