Schedule Unstakes V2 #3191
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
name: Schedule Unstakes V2 | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '50 0/1 * * *' | |
jobs: | |
trigger_unstakes_v2_if_needed: | |
name: Schedule Unstakes V2 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@master | |
with: | |
fetch-depth: 20 | |
- name: Check epoch timing | |
run: | | |
epoch_info=$(curl -sfLS "http://api.mainnet-beta.solana.com" -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getEpochInfo"}') | |
current_epoch=$(<<<"$epoch_info" jq '.result.epoch' -r) | |
slot_index=$(<<<"$epoch_info" jq '.result.slotIndex' -r) | |
last_v2_scoring_epoch_from_dir=$(find scoring-v2 -type d | sort -n | tail -1 | cut -d/ -f2 | cut -d. -f1) | |
last_v2_scoring_epoch_from_git=$(gh pr list --state open --json headRefName,isCrossRepository --jq '.[] | select(.isCrossRepository == false) | .headRefName' | grep unstakes/ | sort -n | tail -1 | cut -d/ -f2| cut -d. -f1) | |
last_v2_unstakes_epoch_from_git=$(gh pr list --state merged --json headRefName,isCrossRepository --jq '.[] | select(.isCrossRepository == false) | .headRefName' | grep unstakes/ | sort -n | tail -1 | cut -d/ -f2| cut -d. -f1) | |
echo "Last V2 scoring epoch (git): $last_v2_scoring_epoch_from_git" | |
echo "Last V2 scoring epoch (dir): $last_v2_scoring_epoch_from_dir" | |
echo "Current epoch: $current_epoch" | |
echo "Current slot: $slot_index" | |
if (( slot_index < 259200 )) | |
then | |
echo "Too early in the epoch!" | |
exit 0 | |
fi | |
if [[ -z $last_v2_scoring_epoch_from_dir ]] && (( last_v2_scoring_epoch_from_dir == current_epoch )) | |
then | |
echo "Scoring didn't run or wasn't merged!" | |
exit 0 | |
fi | |
if ! [[ -z $last_v2_scoring_epoch_from_git ]] && (( last_v2_scoring_epoch_from_git == current_epoch )) | |
then | |
echo "Scoring PR is not merged!" | |
exit 0 | |
fi | |
if [[ -n $last_v2_unstakes_epoch_from_git ]] && (( last_v2_unstakes_epoch_from_git == current_epoch )) | |
then | |
echo "Late unstakes PR was already merged" | |
exit 0 | |
fi | |
echo "Triggering the V2 late unstake pipeline..." | |
gh workflow run v2-prepare-unstakes.yml | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |