Skip to content

feat(ci): update workflow trigger for temp-devnet #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 115 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build story binary, reset internal-devnet, run l1 tests
name: Build story binary, reset temp-devnet, run l1 tests

on:
workflow_dispatch:
Expand Down Expand Up @@ -104,18 +104,20 @@ jobs:
path: ${{ env.ARCHIVE_NAME }}
destination: ${{ env.GCP_BUCKET }}/${{ env.BIN_NAME }}

- name: Reset internal-devnet network
- name: Reset temp-devnet network
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT_INTERNAL_DEVNET_WF_DISPATCH }}
repository: piplabs/internal-devnet
repository: piplabs/temp-devnet
event-type: network-update
client-payload: |
{
"action": "reset",
"environment": "temp-devnet",
"version": "${{ env.VERSION }}",
"version_meta": "${{ env.VERSION_META }}",
"commit_hash": "${{ env.COMMIT_HASH }}"
"commit_hash": "${{ env.COMMIT_HASH }}",
"repo_type": "public"
}

- name: Verify the above workflow was completed successfully
Expand All @@ -129,7 +131,7 @@ jobs:

GITHUB_TOKEN="${{ secrets.PAT_INTERNAL_DEVNET_WF_DISPATCH }}"
OWNER="piplabs"
REPO="internal-devnet"
REPO="temp-devnet"
TRIGGER_EVENT="repository_dispatch"
MAX_RETRIES=60
SLEEP_INTERVAL=20
Expand Down Expand Up @@ -200,28 +202,31 @@ jobs:
echo "Proceeding to the next step."
echo "success=true" >> $GITHUB_OUTPUT

- name: Wait for internal-devnet network to be up and producing blocks
- name: Wait for temp-devnet network to be up and producing blocks and height is larger than 200
if: ${{ steps.verify-workflow.outputs.success == 'true' }}
run: |
echo "Checking internal-devnet network at https://devnet.storyscan.xyz/api/v2/blocks?type=block ..."
echo "Checking temp-devnet network with rpc call eth_blockNumber..."
retries=60
delay=20
for i in $(seq 1 $retries); do
block1=$(curl -s -X GET "https://devnet.storyscan.xyz/api/v2/blocks?type=block" -H "accept: application/json" | jq '.items[0].height')
block1=$(curl -s -X POST --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://35.211.189.137:8545 | jq -r ".result")
sleep $delay
block2=$(curl -s -X GET "https://devnet.storyscan.xyz/api/v2/blocks?type=block" -H "accept: application/json" | jq '.items[0].height')
block2=$(curl -s -X POST --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://35.211.189.137:8545 | jq -r ".result")
sleep $delay
block3=$(curl -s -X GET "https://devnet.storyscan.xyz/api/v2/blocks?type=block" -H "accept: application/json" | jq '.items[0].height')
block3=$(curl -s -X POST --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://35.211.189.137:8545 | jq -r ".result")

if [ "$block1" != "null" ] && [ "$block2" != "null" ] && [ "$block3" != "null" ] && \
[ -n "$block1" ] && [ -n "$block2" ] && [ -n "$block3" ]; then

# Compare block numbers to ensure they are increasing
if [ "$block1" -lt "$block2" ] && [ "$block2" -lt "$block3" ]; then
echo "Network is up and producing blocks: $block1 -> $block2 -> $block3"
block1_dec=$((block1))
block2_dec=$((block2))
block3_dec=$((block3))
if [ "$block3_dec" -gt 200 ] && [ "$block1_dec" -lt "$block2_dec" ] && [ "$block2_dec" -lt "$block3_dec" ]; then
echo "Network is up and producing blocks: $block1_dec -> $block2_dec -> $block3_dec"
exit 0
else
echo "Blocks are not increasing as expected: $block1 -> $block2 -> $block3. Retrying..."
echo "Blocks are not increasing as expected: $block1_dec -> $block2_dec -> $block3_dec. Retrying..."
fi
else
echo "Invalid block data received. Retrying..."
Expand All @@ -240,5 +245,101 @@ jobs:
client-payload: |
{
"version": "${{ env.VERSION }}",
"commit_hash": "${{ env.COMMIT_HASH }}"
"commit_hash": "${{ env.COMMIT_HASH }}",
"devnet_version": "temp-devnet"
}

- name: Verify the above workflow was completed
id: verify-l1-tests
run: |
#!/bin/bash

# Set a manual delay to allow the workflow to be triggered
sleep 15

GITHUB_TOKEN="${{ secrets.PAT_INTERNAL_DEVNET_WF_DISPATCH }}"
OWNER="storyprotocol"
REPO="l1-tests"
TRIGGER_EVENT="repository_dispatch"
# 120 retries * 300 seconds = 36000 seconds = 10 hours
MAX_RETRIES=120
SLEEP_INTERVAL=300

check_workflow_status() {
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${OWNER}/${REPO}/actions/runs?event=${TRIGGER_EVENT}")

run=$(echo "$response" | jq '
.workflow_runs
| map(select(.status == "in_progress" or .status == "queued"))
| sort_by(.run_number)
| last
')
echo "$run"
}

check_workflow_by_id() {
local id=$1
curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$id" | \
jq '.'
}

echo "--------- print result check_workflow_status----------"
result=$(check_workflow_status)

# If no live run is found, the result will be an empty object "{}"
if [ "$(echo "$result" | jq -r 'if . == {} or . == null then "empty" else "found" end')" = "empty" ]; then
echo "No in-progress workflow found. Exiting."
exit 1
fi

run_status=$(echo "$result" | jq -r '.status')
run_conclusion=$(echo "$result" | jq -r '.conclusion')
echo "Current status: ${run_status}, conclusion: ${run_conclusion}"

run_id=$(echo "$result" | jq -r '.id')
echo "Found in_progress workflow with ID: $run_id"

attempt=1
while [ $attempt -le $MAX_RETRIES ]; do
result_by_id=$(check_workflow_by_id $run_id)
status_by_id=$(echo "$result_by_id" | jq -r '.status')
conclusion_by_id=$(echo "$result_by_id" | jq -r '.conclusion')
echo "Current status: ${status_by_id}, conclusion: ${conclusion_by_id}"

if [ "$status_by_id" == "completed" ] || [ "$status_by_id" == "cancelled" ]; then
echo "Workflow run ${status_by_id} with conclusion: ${conclusion_by_id}"
break
fi

echo "Workflow run is still in progress or not found. Waiting for ${SLEEP_INTERVAL} seconds..."
sleep $SLEEP_INTERVAL
attempt=$((attempt + 1))

done

if [ $attempt -gt $MAX_RETRIES ]; then
echo "Workflow run did not complete within the allotted time."
exit 1
fi

echo "Proceeding to the next step."
echo "completed=true" >> $GITHUB_OUTPUT

- name: delete temp-devnet network
if: always()
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.PAT_INTERNAL_DEVNET_WF_DISPATCH }}
repository: piplabs/temp-devnet
event-type: network-update
client-payload: |
{
"action": "delete",
"environment": "temp-devnet",
"version": "${{ env.VERSION }}",
"version_meta": "${{ env.VERSION_META }}",
"commit_hash": "${{ env.COMMIT_HASH }}",
"repo_type": "public"
}
Loading