Trigger day run & schedule benchmarks #176
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: Trigger day run & schedule benchmarks | |
on: | |
workflow_dispatch: | |
inputs: | |
day: | |
description: "Day to run benchmarks for" | |
required: true | |
owner: | |
description: "Owner of the repository" | |
required: false | |
skip_scheduling: | |
description: "Skip scheduling the run" | |
type: boolean | |
default: false | |
permissions: | |
contents: write | |
actions: write | |
jobs: | |
get-repos: | |
runs-on: ubuntu-24.04 | |
outputs: | |
repositories: ${{ steps.data.outputs.matrix }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: data | |
run: | | |
MATRIX=$(jq -c . < ./data/repositories.json) | |
if [ -n "${{ inputs.owner }}" ]; then | |
MATRIX=$(echo $MATRIX | jq -c '[.[] | select(.owner == "${{ inputs.owner }}")]') | |
fi | |
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT | |
schedule: | |
runs-on: ubuntu-24.04 | |
needs: get-repos | |
strategy: | |
fail-fast: false | |
matrix: | |
repository: ${{fromJson(needs.get-repos.outputs.repositories)}} | |
steps: | |
- name: Print metadata | |
run: | | |
echo "Owner: ${{ matrix.repository.owner }}" | |
echo "Name: ${{ matrix.repository.name }}" | |
echo "Crate: ${{ matrix.repository.crate }}" | |
echo "Toolchain: ${{ matrix.repository.toolchain }}" | |
- uses: actions/checkout@v4 | |
- name: Setup rust toolchain | |
uses: moonrepo/setup-rust@v1 | |
with: | |
profile: minimal | |
channel: ${{ matrix.repository.toolchain }} | |
- name: Prepare the runner | |
working-directory: ./rust-runner | |
run: | | |
REPO_URL="https://github.com/${{ matrix.repository.owner }}/${{ matrix.repository.name }}" | |
if [ -n "${{ matrix.repository.crate }}" ]; then | |
cargo add --git $REPO_URL ${{ matrix.repository.crate }} --rename solution | |
else | |
cargo add --git $REPO_URL --rename solution | |
fi | |
echo "[toolchain]" > ../rust-toolchain.toml | |
echo "channel = \"${{ matrix.repository.toolchain }}\"" >> ../rust-toolchain.toml | |
- name: Check solution conformity | |
id: input_repo_check | |
working-directory: ./rust-runner | |
env: | |
DAY_NUMBER: ${{ inputs.day }} | |
RUSTFLAGS: "-C target-cpu=native" | |
run: | | |
if ! cargo build --test test_build ; then | |
echo "::warning::The day ${{ inputs.day }} module is missing or malformed. Skipping the run." | |
echo "valid=false" >> $GITHUB_OUTPUT | |
else | |
echo "Solution is valid" | |
echo "valid=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Prepare the branch & schedule the run | |
if: ${{ !inputs.skip_scheduling && steps.input_repo_check.outputs.valid == 'true' }} | |
run: | | |
git config --global user.name "codspeed-advent[bot]" | |
git config --global user.email "codspeed-advent-bot@@users.noreply.github.com" | |
git add rust-runner/ rust-toolchain.toml | |
BRANCH_NAME="run/${{ matrix.repository.owner }}/${{ matrix.repository.name }}/${{ inputs.day }}" | |
git checkout -b $BRANCH_NAME | |
git commit -m "Run: $BRANCH_NAME" | |
git push --force origin $BRANCH_NAME | |
sleep 5 # wait for the branch to be created | |
gh workflow run run-day.yml --ref $BRANCH_NAME --repo ${{ github.repository }} | |
sleep 5 # wait for the run to be scheduled | |
RUN_ID=$(gh run list --repo ${{ github.repository }} --limit 1 --branch ${BRANCH_NAME} --json databaseId | jq '.[0].databaseId') | |
echo "Scheduled the run for $BRANCH_NAME" | |
echo "::notice::Measurement Job URL: https://github.com/${{ github.repository }}/actions/runs/$RUN_ID" | |
env: | |
GH_TOKEN: ${{ github.token }} |