Skip to content

Check and Update Algorand Version #22

Check and Update Algorand Version

Check and Update Algorand Version #22

name: Check and Update Algorand Version
on:
schedule:
- cron: "0 0,12 * * *" # Runs at 00:00 and 12:00 UTC every day
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
check-and-update-algorand-version:
runs-on: macos-15
concurrency:
group: algorand-updater
cancel-in-progress: false
steps:
- name: Checkout homebrew-tap repository
uses: actions/checkout@v4
- name: Get version from algorand.rb
id: get_version
run: |
current_version=$(grep -E '^\s*url\s+"https://github.com/algorand/go-algorand/releases/download/v[0-9]+\.[0-9]+\.[0-9]+-stable/node_stable_darwin-universal_[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz"' Formula/algorand.rb | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/^v//')
echo "current_version=$current_version" >> "$GITHUB_OUTPUT"
- name: Fetch latest go-algorand stable tag
id: fetch_tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/algorand/go-algorand/tags")
latest_tag=$(echo "$response" | jq -r '[.[] | select(.name | contains("-stable"))][0].name' | sed 's/^v//; s/-stable$//')
if [ -z "$latest_tag" ]; then
echo "Error: Failed to fetch the latest stable tag."
exit 1
fi
echo "latest_tag=$latest_tag" >> "$GITHUB_OUTPUT"
- name: Compare versions
id: compare_versions
run: |
homebrew_version="${{ steps.get_version.outputs.current_version }}"
latest_tag="${{ steps.fetch_tag.outputs.latest_tag }}"
echo "Homebrew version: $homebrew_version"
echo "Latest tag: $latest_tag"
if [ "$homebrew_version" != "$latest_tag" ]; then
echo "mismatch=true" >> "$GITHUB_OUTPUT"
else
echo "mismatch=false" >> "$GITHUB_OUTPUT"
fi
- name: Fetch checksum for latest release
if: steps.compare_versions.outputs.mismatch == 'true'
id: fetch_checksum
run: |
checksum=$(curl -sL "https://github.com/algorand/go-algorand/releases/download/v${{ steps.fetch_tag.outputs.latest_tag }}-stable/node_stable_darwin-universal_${{ steps.fetch_tag.outputs.latest_tag }}.tar.gz" | shasum -a 256 | awk '{print $1}')
echo "checksum=$checksum" >> "$GITHUB_OUTPUT"
- name: Update algorand.rb
if: steps.compare_versions.outputs.mismatch == 'true'
run: |
sed -i '' "s|url \"https://github.com/algorand/go-algorand/releases/download/v[0-9.]*-stable/node_stable_darwin-universal_[0-9.]*.tar.gz\"|url \"https://github.com/algorand/go-algorand/releases/download/v${{ steps.fetch_tag.outputs.latest_tag }}-stable/node_stable_darwin-universal_${{ steps.fetch_tag.outputs.latest_tag }}.tar.gz\"|" Formula/algorand.rb
sed -i '' "s/sha256 \".*\"/sha256 \"${{ steps.fetch_checksum.outputs.checksum }}\"/" Formula/algorand.rb
- name: Test formula installation
if: steps.compare_versions.outputs.mismatch == 'true'
run: |
brew install --build-from-source ./Formula/algorand.rb --formula 2>&1
brew --prefix algorand --installed
"$(brew --prefix algorand)/bin/algod" -v
brew uninstall algorand
- name: Commit and push changes
if: steps.compare_versions.outputs.mismatch == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/algorand.rb
git commit -m "Update Algorand version to ${{ steps.fetch_tag.outputs.latest_tag }}"
git push