forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: automatically update the fastcrypto pointer
This is a sibling PR to MystenLabs#4393 which allowed logic that would automatically update the NW pointer.
- Loading branch information
1 parent
a05fae1
commit d2d467a
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Update the Fastcrypto pointer Sui | ||
on: | ||
## Allow triggering this workflow manually via GitHub CLI/web | ||
workflow_dispatch: | ||
schedule: | ||
# Update on every hour at 10 past the hour | ||
- cron: '10 * * * *' | ||
|
||
jobs: | ||
update-dep: | ||
runs-on: ubuntu-latest | ||
# Important settings as we don't want to open a PR when the update fails | ||
continue-on-error: false | ||
strategy: | ||
fail-fast: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions-rs/toolchain@v1 | ||
- uses: bmwill/rust-cache@v1 # Fork of 'Swatinem/rust-cache' which allows caching additional paths | ||
- name: Install cargo-hakari, and cache the binary | ||
uses: baptiste0928/cargo-install@v1 | ||
with: | ||
crate: cargo-hakari | ||
locked: true | ||
- name: Update the Narwhal pointer | ||
run: | | ||
scripts/update_fastcrypto.sh | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
# TODO: change the token to something FC-specific? | ||
token: ${{ secrets.NW_AUTO_UPDATE }} | ||
commit-message: chore(deps) Update the Fastcrypto pointer | ||
title: chore(deps) Update the Fastcrypto pointer | ||
body: | | ||
- Update Fastcrypto | ||
Auto-generated by [create-pull-request][1] and the scripts/update_fastcrypto.sh script | ||
|
||
[1]: https://github.com/peter-evans/create-pull-request | ||
branch: update-fastcrypto |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
# Copyright (c) Mysten Labs, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# shellcheck disable=SC2181 | ||
# This script attempts to update the Fastcrypto pointer in Sui | ||
# It is expected to fail in some cases, notably when those updates require code changes | ||
set -e | ||
set -eo pipefail | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
TOPLEVEL="${DIR}/../" | ||
GREP=${GREP:=grep} | ||
|
||
# Crutch for old bash versions | ||
# Very minimal readarray implementation using read. Does NOT work with lines that contain double-quotes due to eval() | ||
readarray() { | ||
while IFS= read -r var; do | ||
MAPFILE+=("$var") | ||
done | ||
} | ||
|
||
|
||
# check for the presence of needed executables: | ||
# - we use GNU grep in perl re mode | ||
# - we use cargo-hakari | ||
function check_gnu_grep() { | ||
GNUSTRING=$($GREP --version|head -n1| grep 'GNU grep') | ||
if [[ -z $GNUSTRING ]]; | ||
then | ||
echo "Could not find GNU grep. This requires GNU grep 3.7 with PCRE expressions"; exit 1 | ||
else | ||
return 0 | ||
fi | ||
} | ||
|
||
function check_cargo_hakari() { | ||
cargo hakari --version > /dev/null 2>&1 | ||
if [[ $? -ne 0 ]]; then | ||
echo "Could not find cargo hakari. Please install"; exit 1 | ||
else | ||
return 0 | ||
fi | ||
} | ||
|
||
|
||
function latest_fc_revision() { | ||
FC_CHECKOUT=$(mktemp -d) | ||
cd "$FC_CHECKOUT" | ||
git clone --depth 1 https://github.com/mystenlabs/fastcrypto | ||
cd fastcrypto | ||
git rev-parse HEAD | ||
} | ||
|
||
function current_fc_revision() { | ||
cd "$TOPLEVEL" | ||
readarray -t <<< "$(find ./ -iname '*.toml' -exec $GREP -oPe 'git = "https://github.com/MystenLabs/fastcrypto", *rev *= *\"\K[0-9a-fA-F]+' '{}' \;)" | ||
watermark=${MAPFILE[0]} | ||
for i in "${MAPFILE[@]}"; do | ||
if [[ "$watermark" != "$i" ]]; then | ||
not_equal=true | ||
break | ||
fi | ||
done | ||
|
||
[[ -n "$not_equal" ]] && echo "Different values found for the current Fastcrypto revision in Sui, aborting" && exit 1 | ||
echo "$watermark" | ||
} | ||
|
||
# Check for tooling | ||
check_gnu_grep | ||
check_cargo_hakari | ||
|
||
# Debug prints | ||
CURRENT_FC=$(current_fc_revision) | ||
LATEST_FC=$(latest_fc_revision) | ||
if [[ "$CURRENT_FC" != "$LATEST_FC" ]]; then | ||
echo "About to replace $CURRENT_FC with $LATEST_FC as the Narwhal pointer in Sui" | ||
else | ||
exit 0 | ||
fi | ||
|
||
# Edit the source & run hakari | ||
find ./ -iname "*.toml" -execdir sed -i '' -re "s/$CURRENT_FC/$LATEST_FC/" '{}' \; | ||
cargo hakari generate |