From 888dba91ca4cfe9deae5c6fa7d978e5a3b1f1fc3 Mon Sep 17 00:00:00 2001 From: Jason I Date: Mon, 29 Apr 2024 08:41:34 -0700 Subject: [PATCH] chore: add workflow to update ic commit and ic artifacts in dfx cache --- .github/workflows/provision-darwin.sh | 8 +++ .github/workflows/provision-linux.sh | 7 +++ .github/workflows/update-dfx-cache.sh | 32 ++++++++++ .github/workflows/update-ic-commit.yml | 85 ++++++++++++++++++++++++++ .ic-commit | 1 + 5 files changed, 133 insertions(+) create mode 100755 .github/workflows/update-dfx-cache.sh create mode 100644 .github/workflows/update-ic-commit.yml create mode 100644 .ic-commit diff --git a/.github/workflows/provision-darwin.sh b/.github/workflows/provision-darwin.sh index c36d51657..e6dab0630 100755 --- a/.github/workflows/provision-darwin.sh +++ b/.github/workflows/provision-darwin.sh @@ -24,6 +24,14 @@ echo "$HOME/Library/Application Support/org.dfinity.dfx/bin" >> $GITHUB_PATH source "$HOME/Library/Application Support/org.dfinity.dfx/env" dfx cache install +# check the current ic-commit found in the main branch, check if it differs from the one in this PR branch +# if so, update the dfx cache with the latest ic artifacts +stable_sha=$(curl https://raw.githubusercontent.com/dfinity/examples/master/.ic-commit) +current_sha=$(sed <.ic-commit 's/#.*$//' | sed '/^$/d') +if [ "$current_sha" != "$stable_sha" ]; then + ./update-dfx-cache.sh +fi + # Install ic-repl version=0.7.0 curl --location --output ic-repl "https://github.com/chenyan2002/ic-repl/releases/download/$version/ic-repl-macos" diff --git a/.github/workflows/provision-linux.sh b/.github/workflows/provision-linux.sh index c417e5e08..64ebeaa4a 100755 --- a/.github/workflows/provision-linux.sh +++ b/.github/workflows/provision-linux.sh @@ -18,6 +18,13 @@ rm install-dfx.sh echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH source "$HOME/.local/share/dfx/env" dfx cache install +# check the current ic-commit found in the main branch, check if it differs from the one in this PR branch +# if so, update the dfx cache with the latest ic artifacts +stable_sha=$(curl https://raw.githubusercontent.com/dfinity/examples/master/.ic-commit) +current_sha=$(sed <.ic-commit 's/#.*$//' | sed '/^$/d') +if [ "$current_sha" != "$stable_sha" ]; then + ./update-dfx-cache.sh +fi # Install ic-repl version=0.7.0 diff --git a/.github/workflows/update-dfx-cache.sh b/.github/workflows/update-dfx-cache.sh new file mode 100755 index 000000000..a3f57ef1e --- /dev/null +++ b/.github/workflows/update-dfx-cache.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Download latest ic artifacts +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/replica.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/canister_sandbox.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/ic-admin.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/ic-btc-adapter.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/ic-https-outcalls-adapter.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/ic-nns-init.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/ic-starter.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/sandbox_launcher.gz" +curl -O "https://download.dfinity.systems/ic/$latest_sha/binaries/x86_64-linux/sns.gz" + +# Overwrite artifacts in dfx cache +gzip -d replica.gz +mv replica $(dfx cache show) +gzip -d canister_sandbox.gz +mv canister_sandbox $(dfx cache show) +gzip -d ic-admin.gz +mv ic-admin $(dfx cache show) +gzip -d ic-btc-adapter.gz +mv ic-btc-adapter $(dfx cache show) +gzip -d ic-https-outcalls-adapter.gz +mv ic-https-outcalls-adapter $(dfx cache show) +gzip -d ic-nns-init.gz +mv ic-nns-init $(dfx cache show) +gzip -d ic-starter.gz +mv ic-starter $(dfx cache show) +gzip -d sandbox_launcher.gz +mv sandbox_launcher $(dfx cache show) +gzip -d sns.gz +mv sns $(dfx cache show) \ No newline at end of file diff --git a/.github/workflows/update-ic-commit.yml b/.github/workflows/update-ic-commit.yml new file mode 100644 index 000000000..ad104d7f5 --- /dev/null +++ b/.github/workflows/update-ic-commit.yml @@ -0,0 +1,85 @@ +# A GitHub Actions workflow that regularly creates a pull request to update the IC artifacts +name: IC Artifacts Update + +on: + # TODO: remove `push` trigger. this is just for testing + push: + schedule: + # create a new pull request every monday + - cron: '0 0 * * MON' + +jobs: + ic-update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # First, check if there is a newer version and update the file referencing the version + - name: Check new ic version + id: update + run: | + # Not all ic commits are built and released, so we go through the last commits until we found one + # which has associated artefacts + while read -r sha + do + echo "sha: $sha" + # Send a HEAD to the URL to see if it exists + if curl --fail --head --silent --location \ + "https://download.dfinity.systems/ic/$sha/binaries/x86_64-linux/ic-test-state-machine.gz" + then + echo "$sha appears to have associated binary, using" + latest_sha="$sha" + break + else + echo "$sha does not seem to have associated binary" + fi + done < <(curl \ + -SsL \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/dfinity/ic/commits | jq -cMr '.[] | .sha') + + # If we couldn't find any sha with associated artefacts, abort + if [ -z "${latest_sha:-}" ] + then + echo no sha found + exit 1 + fi + + # Compare the current and latest shas, and potentially update the relevant files + current_sha=$(sed <.ic-commit 's/#.*$//' | sed '/^$/d') + + echo current sha is "$current_sha" + + if [ "$current_sha" != "$latest_sha" ]; then + echo "updating $current_sha to $latest_sha" + sed -i -e \ + "s/$current_sha/$latest_sha/g" \ + ".ic-commit" + + # This updates the download hint when tests are run with a missing binary + sed -i -e \ + "s/$current_sha/$latest_sha/g" \ + "src/canister_tests/src/framework.rs" + echo "updated=1" >> "$GITHUB_OUTPUT" + else + echo "not updating $current_sha" + echo "updated=0" >> "$GITHUB_OUTPUT" + fi + + cat ".ic-commit" + + # If the ic commit was updated, create a PR. + - name: Create Pull Request + if: ${{ steps.update.outputs.updated == '1' }} + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GIX_BOT_PAT }} + base: main + add-paths: ./.ic-commit + commit-message: Update commit of IC artifacts + committer: GitHub + author: SDK + branch: bot-ic-update + delete-branch: true + title: 'Update commit of IC artefacts' \ No newline at end of file diff --git a/.ic-commit b/.ic-commit new file mode 100644 index 000000000..8b38a1293 --- /dev/null +++ b/.ic-commit @@ -0,0 +1 @@ +63acf4f88b20ec0c6384f4e18f0f6f69fc5d9b9f \ No newline at end of file