Skip to content

Commit

Permalink
chore: add workflow to update ic commit and ic artifacts in dfx cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason I committed Apr 29, 2024
1 parent 2270eac commit 888dba9
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/provision-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/provision-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/update-dfx-cache.sh
Original file line number Diff line number Diff line change
@@ -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)
85 changes: 85 additions & 0 deletions .github/workflows/update-ic-commit.yml
Original file line number Diff line number Diff line change
@@ -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 <noreply@github.com>
author: SDK <team-sdk@dfinity.org>
branch: bot-ic-update
delete-branch: true
title: 'Update commit of IC artefacts'
1 change: 1 addition & 0 deletions .ic-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
63acf4f88b20ec0c6384f4e18f0f6f69fc5d9b9f

0 comments on commit 888dba9

Please sign in to comment.