Ciborg Turbo #512
This file contains hidden or 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: Ciborg Turbo | |
| # Enqueue dispatches N worker runs. Each worker takes one of 15 slots | |
| # (ciborg-turbo-0 .. ciborg-turbo-14). Extra runs sit pending (no runner) | |
| # and drain FIFO — same queue:max trick as fdroid-revanced/build-fdroid.yml. | |
| # Do not cancel a running worker: in-flight docker workers are not restart-safe. | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| jobs: | |
| description: "How many worker jobs to dispatch" | |
| type: number | |
| default: 1 | |
| worker: | |
| description: "Internal — run a worker (set by enqueue)" | |
| type: boolean | |
| default: false | |
| slot: | |
| description: "Internal — concurrency slot 0-14 (set by enqueue)" | |
| type: number | |
| default: 0 | |
| schedule: | |
| - cron: '30 9 * * *' | |
| jobs: | |
| enqueue: | |
| name: Enqueue | |
| if: github.event_name == 'workflow_dispatch' && !inputs.worker | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| actions: write | |
| steps: | |
| - name: Dispatch worker jobs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| REPO="${{ github.repository }}" | |
| COUNT="${{ inputs.jobs }}" | |
| if [ -z "${COUNT}" ] || [ "${COUNT}" = "null" ]; then | |
| COUNT=1 | |
| fi | |
| COUNT="$(printf '%.0f' "$COUNT")" | |
| if [ "$COUNT" -lt 1 ]; then COUNT=1; fi | |
| SLOTS=15 | |
| echo "Dispatching $COUNT worker(s) across $SLOTS slots" | |
| for i in $(seq 0 $((COUNT - 1))); do | |
| slot=$((i % SLOTS)) | |
| gh workflow run ciborg-turbo.yml -R "$REPO" -f worker=true -f slot="$slot" | |
| echo " kicked $((i + 1))/$COUNT slot=$slot" | |
| done | |
| work: | |
| name: "Work" | |
| if: github.event_name == 'schedule' || inputs.worker | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: ciborg-turbo-${{ inputs.slot || 0 }} | |
| cancel-in-progress: false | |
| queue: max | |
| steps: | |
| - uses: jdx/mise-action@6d1e696aa24c1aa1bcc1adea0212707c71ab78a8 # v3 | |
| - name: "Run worker" | |
| env: | |
| MISE_CI_TOKEN: ${{ secrets.MISE_CI_TOKEN }} | |
| MISE_CI_CALLBACK: ${{ secrets.MISE_CI_CALLBACK }} | |
| run: | | |
| version=$(curl -fsSL "$MISE_CI_CALLBACK/version.txt") | |
| image="ghcr.io/lewtec/ciborg:$version" | |
| docker pull $image | |
| for i in $(seq 4); do | |
| sudo systemd-run \ | |
| --unit="miseci-$i" \ | |
| --property=Restart=on-success \ | |
| --property=RestartSec=0s \ | |
| docker run --rm \ | |
| -e "MISE_CI_TOKEN=$MISE_CI_TOKEN" \ | |
| -e "MISE_CI_CALLBACK=$MISE_CI_CALLBACK" \ | |
| $image worker | |
| done | |
| sudo journalctl -f -u "miseci-*" & | |
| echo "Workers started. Waiting for them to finish (they stop on error)..." | |
| while true; do | |
| if ! systemctl is-active --quiet "miseci-1" "miseci-2" "miseci-3" "miseci-4"; then | |
| # Se alguma não está ativa, verificamos se TODAS pararam | |
| active_count=$(systemctl is-active "miseci-1" "miseci-2" "miseci-3" "miseci-4" | grep -c "^active" || true) | |
| if [ "$active_count" -eq 0 ]; then | |
| break | |
| fi | |
| fi | |
| sleep 10 | |
| done | |
| echo "All workers stopped." |