Prepare Scoring #136
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: 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 }} |