Update Chain Registry Versions #40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Chain Registry Versions | |
on: | |
workflow_dispatch: | |
inputs: | |
release_tag: | |
description: 'Release tag to update the chain registry with' | |
required: true | |
type: string | |
workflow_call: | |
inputs: | |
release_tag: | |
description: 'Release tag to update the chain registry with' | |
required: true | |
type: string | |
jobs: | |
get-version-info: | |
runs-on: ubuntu-latest | |
outputs: | |
version_info: ${{ steps.extract_info.outputs.version_info }} | |
env: | |
release_tag: ${{ inputs.release_tag }} | |
steps: | |
- name: Generate Binary Info | |
id: binary_info | |
run: | | |
set -Eeuo pipefail | |
release_base_url="https://github.com/burnt-labs/xion/releases/download/$release_tag" | |
checksums_file_url="$release_base_url/xiond-$(echo "$release_tag" | sed 's/^v//')-checksums.txt" | |
# Read checksums from the file using curl | |
binaries=$(paste -s -d "," <(curl -sSL "$checksums_file_url" | awk '/xiond_.*\.tar\.gz/ && !/xiond_.*darwin_all/' | while read checksum filename; do | |
platform=$(basename "$filename" ".tar.gz" | cut -d_ -f3- | sed -E 's/^rc[0-9]*-//g; s/_/\//g') | |
echo "\"$platform\": \"$release_base_url/$filename?checksum=sha256:$checksum\"" | |
done)) | |
echo "binaries_json={\"binaries\": {$binaries}}" >> $GITHUB_OUTPUT | |
- name: Generate Version Info | |
id: extract_info | |
env: | |
release_tag: ${{ env.release_tag }} | |
binaries_json: ${{ steps.binary_info.outputs.binaries_json }} | |
run: | | |
set -Eeuo pipefail | |
upgrade_name=$(echo $release_tag | cut -d. -f1) | |
curl -sSL "https://raw.githubusercontent.com/burnt-labs/xion/$release_tag/go.mod" -o go.mod | |
VERSION_INFO=$( | |
go mod edit -json | | |
jq --argjson binaries "$binaries_json" --arg name "$upgrade_name" --arg tag "$release_tag" '{ | |
name: $name, | |
tag: $tag, | |
recommended_version: $tag, | |
language: { | |
type: "go", | |
version: ("v" + (.Go | split(".") | first + "." + (.[1] // ""))) | |
}, | |
binaries: $binaries.binaries, | |
sdk: { | |
type: "cosmos", | |
version: (.Require[] | select(.Path == "github.com/cosmos/cosmos-sdk") | .Version) | |
}, | |
consensus: { | |
type: "cometbft", | |
version: (.Require[] | select(.Path == "github.com/cometbft/cometbft") | .Version) | |
}, | |
cosmwasm: { | |
version: (.Require[] | select(.Path == "github.com/CosmWasm/wasmd") | .Version), | |
enabled: (.Require[] | select(.Path == "github.com/CosmWasm/wasmd") != null) | |
}, | |
ibc: { | |
type: "go", | |
version: (.Require[] | select(.Path == "github.com/cosmos/ibc-go/v8") | .Version) | |
} | |
}' -c) | |
echo "version_info=$VERSION_INFO" >> $GITHUB_OUTPUT | |
update-versions: | |
needs: get-version-info | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
strategy: | |
matrix: | |
network: | |
- name: testnet | |
versions_file: "public/chain-registry/testnets/xiontestnet2/versions.json" | |
chain_file: "public/chain-registry/testnets/xiontestnet2/chain.json" | |
- name: mainnet | |
versions_file: "public/chain-registry/xion/versions.json" | |
chain_file: "public/chain-registry/xion/chain.json" | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Ensure we can create branches | |
- name: Extract version name | |
id: version_info | |
env: | |
VERSION_INFO: ${{ needs.get-version-info.outputs.version_info }} | |
run: | | |
set -Eeuo pipefail | |
# Set variables using heredoc | |
echo "version_tag=$(echo "$VERSION_INFO" | jq -r '.tag')" >> $GITHUB_OUTPUT | |
echo "version_name=$(echo "$VERSION_INFO" | jq -r '.name')" >> $GITHUB_OUTPUT | |
- name: Create new branch | |
id: create_branch | |
env : | |
NEW_BRANCH: "upgrade/${{ matrix.network.name }}/${{ steps.version_info.outputs.version_tag }}" | |
run: | | |
set -Eeuo pipefail | |
# Check if the branch already exists | |
if git show-ref --verify --quiet "refs/heads/${NEW_BRANCH}"; then | |
git checkout ${NEW_BRANCH} | |
else | |
git checkout -b $NEW_BRANCH | |
git push --set-upstream origin $NEW_BRANCH | |
fi | |
echo "new_branch=$NEW_BRANCH" >> $GITHUB_OUTPUT | |
- name: Update file ${{ matrix.network.versions_file }} | |
id: update_version_json | |
env: | |
VERSION_INFO: ${{ needs.get-version-info.outputs.version_info }} | |
VERSIONS_FILE: ${{ matrix.network.versions_file }} | |
VERSION_NAME: ${{ steps.version_info.outputs.version_name }} | |
run: | | |
set -Eeuo pipefail | |
# Check if version already exists and update or append | |
if jq -e --arg name "$VERSION_NAME" '.versions[] | select(.name == $name)' "$VERSIONS_FILE" > /dev/null; then | |
echo "Version $VERSION_NAME already exists, updating..." | |
jq --arg name "$VERSION_NAME" --argjson new "$VERSION_INFO" ' | |
.versions = (.versions | map(if .name == $name then . + $new else . end)) | |
' "$VERSIONS_FILE" > "$VERSIONS_FILE.tmp" && mv "$VERSIONS_FILE.tmp" "$VERSIONS_FILE" | |
else | |
echo "Version $VERSION_NAME does not exist, appending..." | |
jq --arg name "$VERSION_NAME" --argjson new "$VERSION_INFO" ' | |
.versions += [$new] | |
' "$VERSIONS_FILE" > "$VERSIONS_FILE.tmp" && mv "$VERSIONS_FILE.tmp" "$VERSIONS_FILE" | |
fi | |
- name: Update file ${{ matrix.network.chain_file }} | |
env: | |
VERSION_INFO: ${{ needs.get-version-info.outputs.version_info }} | |
CHAIN_FILE: ${{ matrix.network.chain_file }} | |
run: | | |
set -Eeuo pipefail | |
# Update chain.json | |
echo "Updating chain.json with new version info" | |
jq --argjson new "$VERSION_INFO" ' | |
.codebase += $new | |
' "$CHAIN_FILE" > "$CHAIN_FILE.tmp" && mv "$CHAIN_FILE.tmp" "$CHAIN_FILE" | |
cat "$CHAIN_FILE" | |
- name: Commit changes | |
id: commit_changes | |
uses: pirafrank/github-commit-sign@v0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
args: | | |
commit \ | |
--owner=${{ github.repository_owner }} \ | |
--repo=${{ github.event.repository.name }} \ | |
--branch=${{ steps.create_branch.outputs.new_branch }} \ | |
--commitMessage="upgrade ${{ matrix.network.name }} to ${{ steps.version_info.outputs.version_tag }} in versions.json and chain.json" \ | |
--changed="${{ matrix.network.chain_file }}" \ | |
--changed="${{ matrix.network.versions_file}}" | |
- name: Create Pull Request - ${{ matrix.network.name }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NETWORK_NAME: ${{ matrix.network.name }} | |
NEW_BRANCH: ${{ steps.create_branch.outputs.new_branch }} | |
VERSION_TAG: ${{ steps.version_info.outputs.version_tag }} | |
run: | | |
set -Eeuo pipefail | |
gh pr create \ | |
--base main \ | |
--draft \ | |
--title "upgrade: upgrade $VERSION_TAG to $NETWORK_NAME chain registry" \ | |
--body "Updates $NETWORK_NAME versions.json and chain.json with $VERSION_TAG release information" \ | |
--head "$NEW_BRANCH" \ | |
--reviewer "2xburnt" \ | |
--reviewer "wehappyfew" |