|
| 1 | +name: Release Contract Manifest |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [playground-registry-deployed] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + network: |
| 9 | + description: "CDM network to install from" |
| 10 | + required: false |
| 11 | + default: "paseo" |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +env: |
| 18 | + CDM_NETWORK: ${{ github.event.client_payload.network || github.event.inputs.network || 'paseo' }} |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: release-contract-manifest-${{ github.ref }} |
| 22 | + cancel-in-progress: false |
| 23 | + |
| 24 | +jobs: |
| 25 | + sync: |
| 26 | + runs-on: ${{ github.repository_owner == 'paritytech' && 'parity-default' || 'ubuntu-latest' }} |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + ref: main |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - uses: oven-sh/setup-bun@v2 |
| 34 | + with: |
| 35 | + bun-version: "1.2.x" |
| 36 | + |
| 37 | + - uses: pnpm/action-setup@v4 |
| 38 | + |
| 39 | + - uses: actions/setup-node@v4 |
| 40 | + with: |
| 41 | + node-version: "22" |
| 42 | + |
| 43 | + - run: pnpm install |
| 44 | + |
| 45 | + - name: Install CDM CLI |
| 46 | + run: | |
| 47 | + curl -fsSL https://raw.githubusercontent.com/paritytech/contract-dependency-manager/main/install.sh | bash |
| 48 | + echo "$HOME/.cdm/bin" >> "$GITHUB_PATH" |
| 49 | + export PATH="$HOME/.cdm/bin:$PATH" |
| 50 | + cdm --version |
| 51 | +
|
| 52 | + - name: Install latest contract manifest |
| 53 | + run: cdm i -n "${CDM_NETWORK}" |
| 54 | + |
| 55 | + - name: Detect manifest changes |
| 56 | + id: manifest |
| 57 | + run: | |
| 58 | + if git diff --quiet -- cdm.json; then |
| 59 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 60 | + else |
| 61 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 62 | + echo "cdm.json changed after cdm i -n ${CDM_NETWORK}." >> "$GITHUB_STEP_SUMMARY" |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Check current release |
| 66 | + if: steps.manifest.outputs.changed == 'false' |
| 67 | + id: current_release |
| 68 | + env: |
| 69 | + GH_TOKEN: ${{ github.token }} |
| 70 | + run: | |
| 71 | + VERSION=$(node -p "require('./package.json').version") |
| 72 | + TAG="v${VERSION}" |
| 73 | + COMMIT=$(git rev-parse HEAD) |
| 74 | +
|
| 75 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 76 | + echo "commit=${COMMIT}" >> "$GITHUB_OUTPUT" |
| 77 | +
|
| 78 | + EXPECTED_ASSETS=(dot-linux-x64 dot-linux-arm64 dot-darwin-x64 dot-darwin-arm64) |
| 79 | + if ! RELEASE_ASSETS=$(gh release view "${TAG}" --json assets --jq '.assets[].name' 2>/dev/null); then |
| 80 | + echo "missing=true" >> "$GITHUB_OUTPUT" |
| 81 | + echo "cdm.json is unchanged, but ${TAG} has no GitHub release. Rebuilding the current version." >> "$GITHUB_STEP_SUMMARY" |
| 82 | + exit 0 |
| 83 | + fi |
| 84 | +
|
| 85 | + missing_assets=() |
| 86 | + for asset in "${EXPECTED_ASSETS[@]}"; do |
| 87 | + if ! grep -Fxq "${asset}" <<< "${RELEASE_ASSETS}"; then |
| 88 | + missing_assets+=("${asset}") |
| 89 | + fi |
| 90 | + done |
| 91 | +
|
| 92 | + if [ "${#missing_assets[@]}" -eq 0 ]; then |
| 93 | + echo "missing=false" >> "$GITHUB_OUTPUT" |
| 94 | + echo "cdm.json already matches the latest ${CDM_NETWORK} contract manifest and ${TAG} already has all binary assets." >> "$GITHUB_STEP_SUMMARY" |
| 95 | + else |
| 96 | + echo "missing=true" >> "$GITHUB_OUTPUT" |
| 97 | + echo "${TAG} is missing binary assets: ${missing_assets[*]}. Rebuilding the current version." >> "$GITHUB_STEP_SUMMARY" |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Create patch changeset |
| 101 | + if: steps.manifest.outputs.changed == 'true' |
| 102 | + run: | |
| 103 | + mkdir -p .changeset |
| 104 | + CHANGESET=".changeset/release-contract-manifest-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}.md" |
| 105 | + { |
| 106 | + echo '---' |
| 107 | + echo '"playground-cli": patch' |
| 108 | + echo '---' |
| 109 | + echo '' |
| 110 | + echo 'Refresh the bundled Playground contract manifest.' |
| 111 | + } > "$CHANGESET" |
| 112 | + echo "Created $CHANGESET" >> "$GITHUB_STEP_SUMMARY" |
| 113 | +
|
| 114 | + - name: Version packages |
| 115 | + if: steps.manifest.outputs.changed == 'true' |
| 116 | + run: pnpm changeset version |
| 117 | + |
| 118 | + - name: Format |
| 119 | + if: steps.manifest.outputs.changed == 'true' |
| 120 | + run: pnpm format |
| 121 | + |
| 122 | + - name: Generate release tag |
| 123 | + if: steps.manifest.outputs.changed == 'true' |
| 124 | + id: tag |
| 125 | + run: | |
| 126 | + VERSION=$(node -p "require('./package.json').version") |
| 127 | + TAG="v${VERSION}" |
| 128 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 129 | +
|
| 130 | + - name: Compile CLI binaries |
| 131 | + if: steps.manifest.outputs.changed == 'true' || steps.current_release.outputs.missing == 'true' |
| 132 | + run: | |
| 133 | + bun build --compile --target=bun-linux-x64 src/index.ts --outfile dot-linux-x64 |
| 134 | + bun build --compile --target=bun-linux-arm64 src/index.ts --outfile dot-linux-arm64 |
| 135 | + bun build --compile --target=bun-darwin-x64 src/index.ts --outfile dot-darwin-x64 |
| 136 | + bun build --compile --target=bun-darwin-arm64 src/index.ts --outfile dot-darwin-arm64 |
| 137 | +
|
| 138 | + - name: Commit release changes |
| 139 | + if: steps.manifest.outputs.changed == 'true' |
| 140 | + id: commit |
| 141 | + run: | |
| 142 | + git config user.name "github-actions[bot]" |
| 143 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 144 | + git add cdm.json package.json CHANGELOG.md pnpm-lock.yaml |
| 145 | + git diff --cached --quiet || git commit -m "chore: release contract manifest update" |
| 146 | + echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
| 147 | + git push origin HEAD:main |
| 148 | +
|
| 149 | + - name: Create GitHub Release |
| 150 | + if: steps.manifest.outputs.changed == 'true' || steps.current_release.outputs.missing == 'true' |
| 151 | + uses: softprops/action-gh-release@v2 |
| 152 | + with: |
| 153 | + tag_name: ${{ steps.manifest.outputs.changed == 'true' && steps.tag.outputs.tag || steps.current_release.outputs.tag }} |
| 154 | + target_commitish: ${{ steps.manifest.outputs.changed == 'true' && steps.commit.outputs.commit || steps.current_release.outputs.commit }} |
| 155 | + name: Release ${{ steps.manifest.outputs.changed == 'true' && steps.tag.outputs.tag || steps.current_release.outputs.tag }} |
| 156 | + files: | |
| 157 | + dot-linux-x64 |
| 158 | + dot-linux-arm64 |
| 159 | + dot-darwin-x64 |
| 160 | + dot-darwin-arm64 |
| 161 | + overwrite_files: true |
| 162 | + generate_release_notes: true |
0 commit comments