-
Notifications
You must be signed in to change notification settings - Fork 5
58 lines (50 loc) · 2.31 KB
/
v2-schedule-unstakes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 }}