Rebuild Bottles (all) #36
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: Rebuild Bottles | |
| run-name: Rebuild Bottles (${{ github.event.inputs.formula || 'all' }}) | |
| permissions: {} | |
| on: | |
| schedule: | |
| - cron: '0 2 * * 0' # Run weekly on Sunday at 2 AM UTC | |
| workflow_dispatch: | |
| inputs: | |
| formula: | |
| description: 'Formula name to rebuild (e.g., sunshine, sunshine-beta, cuda@13.1)' | |
| required: true | |
| type: string | |
| jobs: | |
| detect-formulas: | |
| name: Detect Formulas | |
| outputs: | |
| formulas: ${{ steps.detect.outputs.formulas }} | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Detect formula files | |
| id: detect | |
| env: | |
| INPUT_FORMULA: ${{ github.event.inputs.formula }} | |
| run: | | |
| if [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then | |
| # Manual trigger - use the input formula name | |
| FORMULAS="[\"${INPUT_FORMULA}\"]" | |
| else | |
| # Scheduled - find all formula files and extract names | |
| FORMULA_FILES=$(find Formula -name '*.rb' -type f) | |
| ALL_FORMULAS=$(echo "$FORMULA_FILES" | xargs -I {} basename {} .rb | jq -R -s -c 'split("\n")[:-1]') | |
| # Load skip list | |
| SKIP_LIST=$(jq -c '.formulas' ci_config/rebuild_bottles_skiplist.json) | |
| # Filter out formulas in the skip list | |
| FORMULAS=$(echo "$ALL_FORMULAS" | jq -c --argjson skip "$SKIP_LIST" '. - $skip') | |
| echo "All formulas: ${ALL_FORMULAS}" | |
| echo "Skip list: ${SKIP_LIST}" | |
| fi | |
| echo "formulas=${FORMULAS}" >> "${GITHUB_OUTPUT}" | |
| echo "Formulas to rebuild: ${FORMULAS}" | |
| rebuild: | |
| name: Rebuild ${{ matrix.formula }} | |
| env: | |
| COMMIT_MESSAGE: 'chore: ${{ matrix.formula }}: rebuild bottles' | |
| MATRIX_FORMULA: ${{ matrix.formula }} | |
| PR_BRANCH_NAME: bot/update-${{ matrix.formula }}-formula | |
| needs: detect-formulas | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| formula: ${{ fromJson(needs.detect-formulas.outputs.formulas) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Find formula file | |
| id: find | |
| run: | | |
| # Find the formula file path from the formula name | |
| FORMULA_NAME="${MATRIX_FORMULA}" | |
| FORMULA_FILE=$(find Formula -name "${FORMULA_NAME}.rb" -type f | head -n 1) | |
| if [ -z "${FORMULA_FILE}" ]; then | |
| echo "Error: Formula file for '${FORMULA_NAME}' not found" | |
| exit 1 | |
| fi | |
| echo "formula_file=${FORMULA_FILE}" >> "${GITHUB_OUTPUT}" | |
| echo "Found formula file: ${FORMULA_FILE}" | |
| - name: Update formula with rebuild comment | |
| id: update | |
| env: | |
| FORMULA_FILE: ${{ steps.find.outputs.formula_file }} | |
| run: | | |
| # Current rebuild number (timestamp-based for uniqueness) | |
| REBUILD_NUM=$(date -u +%s) | |
| COMMENT="# rebuild: ${REBUILD_NUM}" | |
| # Check if a rebuild comment already exists | |
| if grep -q "^# rebuild:" "${FORMULA_FILE}"; then | |
| # Update existing comment | |
| sed -i "s/^# rebuild:.*/${COMMENT}/" "${FORMULA_FILE}" | |
| echo "action=updated" >> "${GITHUB_OUTPUT}" | |
| else | |
| # Add new comment at the end of the file | |
| echo "${COMMENT}" >> "${FORMULA_FILE}" | |
| echo "action=added" >> "${GITHUB_OUTPUT}" | |
| fi | |
| # Show the changes | |
| echo "Changes made to ${FORMULA_FILE}:" | |
| git diff "${FORMULA_FILE}" | |
| - name: Push changes | |
| uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # v1.5 | |
| with: | |
| author_email: ${{ secrets.GH_BOT_EMAIL }} | |
| author_name: ${{ vars.GH_BOT_NAME }} | |
| branch: ${{ env.PR_BRANCH_NAME }} | |
| github_token: ${{ secrets.GH_BOT_TOKEN }} | |
| message: ${{ env.COMMIT_MESSAGE }} | |
| force: true | |
| - name: Create or update Pull Request | |
| env: | |
| ACTION: ${{ steps.update.outputs.action }} | |
| GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }} | |
| run: | | |
| # Check if PR already exists | |
| EXISTING_PR=$(gh pr list --head "${PR_BRANCH_NAME}" --json number --jq '.[0].number' || echo "") | |
| if [ -z "${EXISTING_PR}" ]; then | |
| echo "Creating new PR..." | |
| PR_URL=$(gh pr create \ | |
| --title "${COMMIT_MESSAGE}" \ | |
| --body "Automatic rebuild bottles for \`${MATRIX_FORMULA}\`." \ | |
| --head "${PR_BRANCH_NAME}" \ | |
| --base master) | |
| PR_NUMBER=$(echo "${PR_URL}" | grep -oE '[0-9]+$') | |
| echo "Created new PR #${PR_NUMBER}: ${PR_URL}" | |
| # Enable auto-merge | |
| echo "Enabling auto-merge for PR #${PR_NUMBER}..." | |
| gh pr merge "${PR_NUMBER}" \ | |
| --auto \ | |
| --delete-branch \ | |
| --squash \ | |
| --subject "${COMMIT_MESSAGE}" | |
| echo "Auto-merge enabled" | |
| fi |