-
Notifications
You must be signed in to change notification settings - Fork 5
140 lines (119 loc) · 5.39 KB
/
prepare-scoring.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Prepare Scoring
on:
workflow_dispatch:
repository_dispatch:
types: [trigger_scoring]
jobs:
scoring:
runs-on: ubuntu-latest
steps:
- name: Set start timestamp
run: |
start_timestamp=$(date +%s)
echo "start_timestamp=$start_timestamp" >> $GITHUB_ENV
- uses: actions/checkout@master
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-pandoc@v2
with:
pandoc-version: 3.1.1
- run: |
cat <<EOF > DESCRIPTION
Package: rprojroot
Version: 0.0.1
EOF
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::dotenv
any::data.table
any::dplyr
any::rmarkdown
any::treemapify
any::gridExtra
any::semver
# - name: Install packages
# run: |
# bash -c "$(curl -sSfL https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-install.bash)"
- name: Prepare target directory
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)
scoring_id="$current_epoch.$slot_index"
echo "scoring_id=$scoring_id" >> $GITHUB_ENV
scoring_path="scoring/$scoring_id"
echo "scoring_path=$scoring_path" >> $GITHUB_ENV
mkdir -p "$scoring_path"
- name: Load Data
run: |
cd "${{ env.scoring_path }}"
bash -c "$(curl -sSfL https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-fetch-inputs.bash)"
- name: Score
run: |
cd "${{ env.scoring_path }}"
export SCORING_R=$(mktemp)
export SCORING_WORKING_DIRECTORY="."
wget https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring.R -O "$SCORING_R"
bash -c "$(curl -sSfL https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-run.bash)"
if ! [[ -f scores.csv ]]
then
echo "Scores file was not produced!"
exit 1
fi
- name: Score - Report
run: |
cd "${{ env.scoring_path }}"
export SCORING_REPORT_RMD=$(mktemp --suffix=.Rmd)
export SCORING_WORKING_DIRECTORY="."
wget https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-report.Rmd -O "$SCORING_REPORT_RMD"
bash -c "$(curl -sSfL https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-report.bash)" - "${{ env.scoring_id }}"
- name: Score - Summary
run: |
cd "${{ env.scoring_path }}"
export SCORING_SUMMARY_RMD=$(mktemp --suffix=.Rmd)
export SCORING_WORKING_DIRECTORY="."
wget https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-summary.Rmd -O "$SCORING_SUMMARY_RMD"
bash -c "$(curl -sSfL https://raw.githubusercontent.com/marinade-finance/delegation-strategy-2/master/scripts/scoring-summary.bash)" - "${{ env.scoring_id }}"
- name: Update job status and compute job duration
run: |
start_timestamp=${{ env.start_timestamp }}
duration=$(($(date +%s) - $start_timestamp))
curl -sLfS "https://validators-api.marinade.finance/admin/metrics?job_success=true&prepare_scoring_duration=$duration" -X POST \
-H "Authorization: ${{ secrets.VALIDATORS_API_ADMIN_TOKEN }}"
- name: Report job failure
if: ${{ failure() }}
run: |
start_timestamp=${{ env.start_timestamp }}
duration=$(($(date +%s) - $start_timestamp))
curl -sLfS "https://validators-api.marinade.finance/admin/metrics?job_error=true&prepare_scoring_duration=$duration" -X POST \
-H "Authorization: ${{ secrets.VALIDATORS_API_ADMIN_TOKEN }}"
- name: Make a Pull Request
run: |
scoring_id="${{ env.scoring_id }}"
scoring_branch="scoring/$scoring_id"
git config --global user.name 'Autonomous Scoring Pipeline'
git config --global user.email '[email protected]'
git checkout -b "$scoring_branch"
git add scoring
! [ -z "$(git status --porcelain)" ] && git commit -m "scoring run $scoring_id" && git push -u origin "$scoring_branch" || echo "No changes to be committed"
pr_url=$(gh pr create -B master -H "$scoring_branch" --title "Publish Scoring Results ($scoring_id)" --body-file "${{ env.scoring_path }}/summary.md")
echo "pr_url=$pr_url" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Send Discord Notification
run: |
scoring_id="${{ env.scoring_id }}"
pr_url="${{ env.pr_url }}"
curl "$DISCORD_WEBHOOK" -H "Content-Type: application/json" -d '{
"username": "Delegation Strategy",
"avatar_url": "https://public.marinade.finance/ds-scoring-bot.png",
"embeds": [
{
"title": "Scoring PR ('"$scoring_id"') is prepared.",
"url": "'"$pr_url"'",
"color": "5661687"
}
]
}'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}