From 17a5d0cab447fe24bf97bb67253ed43316eefb60 Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Tue, 7 Nov 2023 17:34:17 +0100 Subject: [PATCH] ci: add bitcoin workflow --- .github/workflows/bitcoin-canister-update.yml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/bitcoin-canister-update.yml diff --git a/.github/workflows/bitcoin-canister-update.yml b/.github/workflows/bitcoin-canister-update.yml new file mode 100644 index 0000000000..55dad64246 --- /dev/null +++ b/.github/workflows/bitcoin-canister-update.yml @@ -0,0 +1,69 @@ +name: Check Bitcoin Canister Release Update + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * *' # Runs at UTC midnight every day + +jobs: + check-update: + runs-on: ubuntu-latest + + steps: + - name: Checkout dfx repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Fetch Bitcoin Canister latest release tag + env: + GH_TOKEN: "${{ secrets.NIV_UPDATER_TOKEN }}" + run: | + LATEST_TAG=$(gh release view --repo dfinity/bitcoin-canister --json tagName -q .tagName) + echo "Latest tag is $LATEST_TAG" + echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV + + - name: Check if the latest release tag has been updated + run: | + URL_ENCODED_CURRENT_TAG=$(jq -r '.["ic-btc-canister"].version' nix/sources.json) + CURRENT_TAG=$(python -c "import sys, urllib.parse as ul; print(ul.unquote_plus(sys.argv[1]))" "$URL_ENCODED_CURRENT_TAG") + echo "Current tag is $CURRENT_TAG" + if [[ "$CURRENT_TAG" == "$LATEST_TAG" ]]; then + echo "No update is required." + exit 1 + else + echo "An update is required." + fi + + + - name: install Nix + uses: cachix/install-nix-action@v21 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - name: install niv (dependency manager for Nix projects) + run: nix-env -i niv -f '' + + - name: install packages from nix/sources.json + run: niv update + + - name: update sources + run: | + URL_ENCODED_LATEST_TAG=$(echo -n "$LATEST_TAG" | python -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip(), safe=""))') + niv update ic-btc-canister -a version=$URL_ENCODED_LATEST_TAG + ./scripts/write-dfx-asset-sources.sh + + - name: Update dfx to use the latest Bitcoin Canister version + env: + GH_TOKEN: "${{ secrets.NIV_UPDATER_TOKEN }}" + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git checkout -b bot/update-bitcoin-canister/$LATEST_TAG + git add . + git commit -m "Update Bitcoin Canister to $LATEST_TAG" + git push --set-upstream origin bot/update-bitcoin-canister/$LATEST_TAG + PR_TITLE="chore: Update Bitcoin Canister Version to $LATEST_TAG" + PR_BODY="This PR updates the Bitcoin Canister version to the latest tag: $LATEST_TAG" + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base master --head $(git branch --show-current) +