|
| 1 | +name: Update Chain Registry Versions |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_info: |
| 7 | + description: "Version information in JSON format" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + version_info: |
| 13 | + description: "Version information in JSON format" |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | +jobs: |
| 18 | + update-versions: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + network: |
| 26 | + - name: testnet |
| 27 | + versions_file: "public/chain-registry/testnets/xiontestnet2/versions.json" |
| 28 | + chain_file: "public/chain-registry/testnets/xiontestnet2/chain.json" |
| 29 | + - name: mainnet |
| 30 | + versions_file: "public/chain-registry/xion/versions.json" |
| 31 | + chain_file: "public/chain-registry/xion/chain.json" |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Check out code |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 # Ensure we can create branches |
| 38 | + |
| 39 | + - name: Extract version name |
| 40 | + id: version_info |
| 41 | + run: | |
| 42 | + # Set variables using heredoc |
| 43 | + VERSION_INFO='${{ inputs.version_info }}' |
| 44 | + VERSION_TAG=$(echo "$VERSION_INFO" | jq -r '.tag') |
| 45 | + VERSION_NAME=$(echo "$VERSION_INFO" | jq -r '.name') |
| 46 | + VERSIONS_FILE="${{ matrix.network.versions_file }}" |
| 47 | + CHAIN_FILE="${{ matrix.network.chain_file }}" |
| 48 | + NEW_BRANCH="upgrade/${{ matrix.network.name }}-$VERSION_TAG" |
| 49 | +
|
| 50 | +
|
| 51 | + echo "VERSION_INFO=$VERSION_INFO" >> $GITHUB_ENV |
| 52 | + echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV |
| 53 | + echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV |
| 54 | + echo "CHAIN_FILE=$CHAIN_FILE" >> $GITHUB_ENV |
| 55 | + echo "VERSIONS_FILE=$VERSIONS_FILE" >> $GITHUB_ENV |
| 56 | + echo "NEW_BRANCH=$NEW_BRANCH" >> $GITHUB_ENV |
| 57 | +
|
| 58 | + - name: Create new branch |
| 59 | + run: | |
| 60 | + # Check if the branch already exists |
| 61 | + if git show-ref --verify --quiet "refs/heads/${NEW_BRANCH}"; then |
| 62 | + git checkout ${NEW_BRANCH} |
| 63 | + else |
| 64 | + git checkout -b $NEW_BRANCH |
| 65 | + git push --set-upstream origin $NEW_BRANCH |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Update file ${{ matrix.network.versions_file }} |
| 69 | + id: update_version_json |
| 70 | + run: | |
| 71 | + # Check if version already exists and update or append |
| 72 | + if jq -e --arg name "$VERSION_NAME" '.versions[] | select(.name == $name)' "$VERSIONS_FILE" > /dev/null; then |
| 73 | + echo "Version $VERSION_NAME already exists, updating..." |
| 74 | + jq --arg name "$VERSION_NAME" --argjson new "$VERSION_INFO" ' |
| 75 | + .versions = (.versions | map(if .name == $name then ($new + .) else . end)) |
| 76 | + ' "$VERSIONS_FILE" > "$VERSIONS_FILE.tmp" && mv "$VERSIONS_FILE.tmp" "$VERSIONS_FILE" |
| 77 | + else |
| 78 | + echo "Version $VERSION_NAME does not exist, appending..." |
| 79 | + jq --arg name "$VERSION_NAME" --argjson new "$VERSION_INFO" ' |
| 80 | + .versions += [$new] |
| 81 | + ' "$VERSIONS_FILE" > "$VERSIONS_FILE.tmp" && mv "$VERSIONS_FILE.tmp" "$VERSIONS_FILE" |
| 82 | + fi |
| 83 | + |
| 84 | + - name: Update file ${{ matrix.network.chain_file }} |
| 85 | + run: | |
| 86 | + # Update chain.json |
| 87 | + echo "Updating chain.json for version: $VERSION_NAME" |
| 88 | + jq --arg name "$VERSION_NAME" --argjson new "$VERSION_INFO" ' |
| 89 | + .codebase = (.codebase | map(if .name == $name then ($new | with_entries(select(.key | IN(keys_unsorted(.)))) + .) else . end)) |
| 90 | + ' "$CHAIN_FILE" > "$CHAIN_FILE.tmp" && mv "$CHAIN_FILE.tmp" "$CHAIN_FILE" |
| 91 | + cat "$CHAIN_FILE" |
| 92 | +
|
| 93 | + - name: Commit changes |
| 94 | + id: commit_changes |
| 95 | + uses: pirafrank/github-commit-sign@v0 |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + COMMIT_MESSAGE: "upgrade: upgrade ${{ matrix.network.name }} to ${{ steps.extract_version.outputs.VERSION_TAG }} in versions.json and chain.json" |
| 99 | + with: |
| 100 | + args: | |
| 101 | + commit \ |
| 102 | + --owner=${{ github.repository_owner }} \ |
| 103 | + --repo=${{ github.event.repository.name }} \ |
| 104 | + --branch=${{ env.NEW_BRANCH }} \ |
| 105 | + --commitMessage='${{ env.COMMIT_MESSAGE }}' \ |
| 106 | + --changed="${{ matrix.network.chain_file }}" \ |
| 107 | + --changed="${{ matrix.network.versions_file}}" |
| 108 | + |
| 109 | + - name: Create Pull Request - ${{ matrix.network.name }} |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + run: | |
| 113 | + gh pr create \ |
| 114 | + --base main \ |
| 115 | + --title "upgrade: upgrade ${{ env.VERSION_TAG }} to ${{ matrix.network.name }} chain registry" \ |
| 116 | + --body "Updates ${{ matrix.network.name }} versions.json and chain.json with ${{ env.VERSION_TAG }} release information" \ |
| 117 | + --head "upgrade/${{ matrix.network.name }}-${{ env.VERSION_TAG }}" \ |
| 118 | + --reviewer "2xburnt" \ |
| 119 | + --reviewer "wehappyfew" |
0 commit comments