name: Pick runner on: workflow_call: outputs: labels: value: ${{ jobs.pick.outputs.labels }} secrets: RUNNER_STATUS_TOKEN: required: false permissions: {} jobs: pick: name: Pick runner runs-on: ubuntu-24.04 timeout-minutes: 2 outputs: labels: ${{ steps.runner.outputs.labels || steps.fork.outputs.labels || '"ubuntu-24.04"' }} steps: - name: Pick the compile runner id: runner if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository continue-on-error: true env: GH_TOKEN: ${{ secrets.RUNNER_STATUS_TOKEN }} run: | set -euo pipefail labels='"ubuntu-24.04"' if [ -n "$GH_TOKEN" ]; then idle=$(gh api "orgs/${GITHUB_REPOSITORY_OWNER}/actions/runners" --jq '[.runners[] | select(.status == "online" and .busy == false and any(.labels[]; .name == "droiddeck-ws"))] | length' 2>/dev/null || echo 0) if [ "${idle:-0}" -gt 0 ]; then labels='["self-hosted","droiddeck-ws"]' fi fi echo "labels=$labels" >> "$GITHUB_OUTPUT" echo "Compile runner: \`$labels\`" >> "$GITHUB_STEP_SUMMARY" - name: Pick the fork runner id: fork if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository continue-on-error: true env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail labels='"ubuntu-24.04"' gist=https://api.github.com/gists/0c7ed7ad6d6493de84f5123689c64ae6 body=$(curl -fsS --max-time 15 -H "Authorization: Bearer $GH_TOKEN" "$gist" 2>/dev/null || curl -fsS --max-time 15 "$gist" 2>/dev/null || echo '{}') IDLE_AT=$(jq -r 'select(.owner.login == "maxjivi05") | .files["idle-at"].content // "0"' <<< "$body" 2>/dev/null || echo 0) echo "Heartbeat: ${IDLE_AT:-none}" age=-1 if [[ "${IDLE_AT:-0}" =~ ^[0-9]+$ ]] && [ "${IDLE_AT:-0}" -gt 0 ]; then age=$(( $(date +%s) - IDLE_AT )) fi if [ "$age" -ge 0 ] && [ "$age" -lt 180 ]; then labels='"droiddeck-fork"' fi echo "labels=$labels" >> "$GITHUB_OUTPUT" echo "Compile runner: \`$labels\`" >> "$GITHUB_STEP_SUMMARY"