Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lthiery committed Jan 31, 2024
1 parent 82953fa commit b26f3d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
29 changes: 12 additions & 17 deletions .github/scripts/idl-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function get_tags() {
-H "X-GitHub-Api-Version: 2022-11-28" \
"$URL")


# check if curl command failed
status_code=$?
if [ $status_code -ne 0 ]; then
Expand Down Expand Up @@ -63,7 +62,6 @@ function get_tags() {
function update_idl() {
PROGRAM=$1
TAG=$2
echo "updating idl $PROGRAM to $TAG"
# download the json idl file from the tags assets
URL="https://github.com/${OWNER}/${REPO}/releases/download/${TAG}/${PROGRAM}.json"

Expand Down Expand Up @@ -100,38 +98,34 @@ function get_cargo_version() {
echo "$CARGO_VERSION"
}

function random_delay() {
# Generate a random integer between 10 and 3276
random_int=$((RANDOM % (3276 - 10 + 1) + 10))
# Convert the random integer to a floating-point number between 0.1 and 1
random_float=$(echo "scale=1; $random_int / 3276" | bc)
sleep $random_float
}

function check_rate_limit() {
RESPONSE=$(curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/rate_limit)

echo "$RESPONSE" | jq -r '.rate.remaining'
REMAINING=$(echo "$RESPONSE" | jq -r '.rate.remaining')
if [ "$REMAINING" -eq 0 ]; then
RESET_TIME=$(echo "$RESPONSE" | jq -r '.rate.reset')
echo "Rate limit exceeded, reset at $RESET_TIME"
exit 1
fi
}

P=$1
# replace underscores with hyphens
PREFIX=program-${P//_/-}
PAGE=1
while true; do
# check if rate limit is 0 remaining
REMAINING=$(check_rate_limit)
if [ "$REMAINING" -eq 0 ]; then
echo "Rate limit exceeded"
# bail out early if we are rate limited.
check_rate_limit
status_code=$?
if [ $status_code -ne 0 ]; then
exit 1
fi

TAG=$(get_tags "$PREFIX" "$PAGE")
random_delay
#if tag exited with non-zero, exit
status_code=$?
if [ $status_code -ne 0 ]; then
Expand All @@ -146,10 +140,11 @@ while true; do
# extract the version from the name (eg program-data-credits-0.2.1 -> 0.2.1)
VERSION=$(version_from_tag "$TAG" "$PREFIX")
CARGO_VERSION=$(get_cargo_version "$P")
echo "Latest version of $P is $VERSION and Cargo.toml version is $CARGO_VERSION"
# if VERSION and CARGO_VERSION are different, update the JSON
if [ "$VERSION" != "$CARGO_VERSION" ]; then
update_idl "${P}" "${TAG}"
echo "${TAG}"
exit 0
fi
break
fi
Expand Down
42 changes: 20 additions & 22 deletions .github/workflows/idl-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ jobs:

strategy:
matrix:
program: [ circuit_breaker,
data_credits,
fanout,
program: [
#circuit_breaker,
#data_credits,
#fanout,
helium_entity_manager,
helium_sub_daos,
hexboosting,
lazy_distributor,
lazy_transactions,
mobile_entity_manager,
no_emit,
price_oracle,
rewards_oracle,
treasury_management,
voter_stake_registry
#helium_sub_daos,
hexboosting
#lazy_distributor,
#lazy_transactions,
#mobile_entity_manager,
#no_emit,
#price_oracle,
#rewards_oracle,
#treasury_management,
#voter_stake_registry
]
max-parallel: 1

Expand All @@ -36,17 +37,14 @@ jobs:
id: update-idls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: .github/scripts/idl-update.sh ${{ matrix.program }}

# if the idl download occurred, we trigger a build which generates new Rust code
- name: Cargo Build
id: cargo-build
run: cargo build --verbose
run: |
TAG=$(.github/scripts/idl-update.sh ${{ matrix.program }})
# creates a pull request with the updated idl
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
if: env.TAG != ''
with:
commit-message: update idl
title: Update IDLs
branch: update-idls
commit-message: update idl ${{ env.TAGS }}
title: ${{ env.TAGS }} IDL
branch: update-idl-${{ env.TAGS }}

0 comments on commit b26f3d2

Please sign in to comment.