Update Chain Registry Versions #4
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: | |
version_info: | |
description: "Version information in JSON format" | |
required: true | |
type: string | |
workflow_call: | |
inputs: | |
version_info: | |
description: "Version information in JSON format" | |
required: true | |
type: string | |
jobs: | |
update-versions: | |
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 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Extract version name | |
id: version_info | |
run: | | |
# Extract version name (e.g. v99 from v99.0.0) | |
VERSION_NAME=$(echo ${{ inputs.version_info }} | jq -r .tag | cut -d. -f1) | |
echo "VERSION_NAME=${VERSION_NAME}" >> $GITHUB_ENV | |
- name: Update file ${{ matrix.network.name }} | |
id: update_json | |
run: | | |
# Set variables based on network | |
VERSIONS_FILE="${{ matrix.network.versions_file }}" | |
CHAIN_FILE="${{ matrix.network.chain_file }}" | |
# Extract version name from input | |
VERSION_NAME=$(echo '${{ inputs.version_info }}' | jq -r '.name') | |
VERSION_TAG=$(echo '${{ inputs.version_info }}' | jq -r '.tag') | |
# 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 '${{ inputs.version_info }}' ' | |
.versions = (.versions | map(if .name == $name then $new else . end)) | |
' "$VERSIONS_FILE" > temp.json | |
else | |
echo "Version $VERSION_NAME does not exist, appending..." | |
jq --arg name "$VERSION_NAME" --argjson new '${{ inputs.version_info }}' ' | |
.versions += [$new] | |
' "$VERSIONS_FILE" > temp.json | |
fi | |
mv temp.json "$VERSIONS_FILE" | |
cat $VERSIONS_FILE | |
# Update chain.json | |
echo "Updating chain.json with version tag: $VERSION_TAG" | |
jq --arg version_tag "$VERSION_TAG" '.code_info.version = $version_tag' "$CHAIN_FILE" > temp_chain.json | |
mv temp_chain.json "$CHAIN_FILE" | |
cat "$CHAIN_FILE" | |
- name: Extract version tag for PR - ${{ matrix.network.name }} | |
id: extract_version | |
run: | | |
VERSION_TAG=$(echo '${{ inputs.version_info }}' | jq -r '.tag') | |
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_OUTPUT | |
- name: Create Pull Request - ${{ matrix.network.name }} | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
commit-message: "upgrade: upgrade ${{ matrix.network.name }} to ${{ steps.extract_version.outputs.VERSION_TAG }} in versions.json and chain.json" | |
title: "upgrade: upgrade ${{ steps.extract_version.outputs.VERSION_TAG }} to ${{ matrix.network.name }} chain registry" | |
body: | | |
Updates ${{ matrix.network.name }} versions.json and chain.json with ${{ steps.extract_version.outputs.VERSION_TAG }} release information | |
branch: "upgrade/${{ matrix.network.name }}-${{ steps.extract_version.outputs.VERSION_TAG }}" | |
delete-branch: true | |
base: main | |
reviewers: "2xburnt,wehappyfew" |