CI #53326
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: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| schedule: | |
| # Every 15 minutes | |
| - cron: "*/15 * * * *" | |
| workflow_dispatch: | |
| concurrency: | |
| group: scheduled-${{ github.ref }}-${{ github.event_name }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| jobs: | |
| generate-cask: | |
| if: startsWith( github.repository, 'Homebrew/' ) | |
| name: Generate homebrew/cask data, pages and API | |
| runs-on: macos-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Set up Homebrew | |
| id: set-up-homebrew | |
| uses: Homebrew/actions/setup-homebrew@main | |
| with: | |
| core: false | |
| cask: true | |
| - run: brew generate-cask-api | |
| env: | |
| HOMEBREW_DEVELOPER: 1 | |
| - name: Archive data | |
| run: tar czvf data-cask.tar.gz _data/cask/ api/cask/ api/cask-source/ api/cask_tap_migrations.json api/internal/cask.* cask/ | |
| - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: data-cask | |
| path: data-cask.tar.gz | |
| retention-days: 1 | |
| generate-core: | |
| if: startsWith( github.repository, 'Homebrew/' ) | |
| name: Generate homebrew/core data, pages and API | |
| runs-on: macos-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Set up Homebrew | |
| id: set-up-homebrew | |
| uses: Homebrew/actions/setup-homebrew@main | |
| with: | |
| core: true | |
| cask: false | |
| - run: brew generate-formula-api | |
| env: | |
| HOMEBREW_DEVELOPER: 1 | |
| - name: Archive data | |
| run: tar czvf data-core.tar.gz _data/formula/ _data/formula_canonical.json api/formula/ api/formula_tap_migrations.json api/internal/formula.* formula/ | |
| - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: data-core | |
| path: data-core.tar.gz | |
| retention-days: 1 | |
| generate-analytics: | |
| if: startsWith( github.repository, 'Homebrew/' ) | |
| name: Generate analytics data | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Set up Homebrew | |
| id: set-up-homebrew | |
| uses: Homebrew/actions/setup-homebrew@main | |
| with: | |
| core: false | |
| cask: false | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0 | |
| with: | |
| bundler-cache: true | |
| - name: Get Python version file | |
| id: get-python-version | |
| run: | | |
| echo "python-version-file=$(brew --repo)/Library/Homebrew/formula-analytics/.python-version" >> "$GITHUB_OUTPUT" | |
| - name: Set up Python | |
| uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 | |
| with: | |
| python-version-file: ${{ steps.get-python-version.outputs.python-version-file }} | |
| - name: Create directories | |
| run: mkdir -p _data/analytics api/analytics | |
| - name: Determine analytics cache date | |
| id: analytics-cache-date | |
| run: echo "date=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT" | |
| - name: Cache analytics data | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| with: | |
| path: | | |
| _data/analytics | |
| api/analytics | |
| key: analytics-data-${{ steps.analytics-cache-date.outputs.date }} | |
| restore-keys: analytics-data- | |
| - name: Update analytics data | |
| run: | | |
| set -euo pipefail | |
| analytics_backup_path="$(mktemp -d)" | |
| mv -v "_data/analytics" "${analytics_backup_path}/data_analytics" | |
| mv -v "api/analytics" "${analytics_backup_path}/api_analytics" | |
| if brew generate-analytics-api; then | |
| exit 0 | |
| fi | |
| rm -rf "_data/analytics" "api/analytics" | |
| mv -v "${analytics_backup_path}/data_analytics" "_data/analytics" | |
| mv -v "${analytics_backup_path}/api_analytics" "api/analytics" | |
| echo "::notice title=Analytics fallback::Restored cached analytics data after brew generate-analytics-api failure." | |
| if: github.ref_name == 'main' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false && github.event.pull_request.user.login != 'dependabot[bot]') | |
| env: | |
| HOMEBREW_INFLUXDB_TOKEN: ${{ secrets.HOMEBREW_INFLUXDB_READ_TOKEN }} | |
| - name: Archive data | |
| run: tar czvf data-analytics.tar.gz _data/analytics api/analytics | |
| - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: data-analytics | |
| path: data-analytics.tar.gz | |
| retention-days: 1 | |
| build: | |
| needs: [generate-cask, generate-core, generate-analytics] | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Set up Git repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Homebrew | |
| id: set-up-homebrew | |
| uses: Homebrew/actions/setup-homebrew@main | |
| with: | |
| core: false | |
| cask: false | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # v1.268.0 | |
| with: | |
| bundler-cache: true | |
| - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| - name: Move artifacts into place | |
| run: | | |
| tar xvf data-analytics/data-analytics.tar.gz | |
| tar xvf data-cask/data-cask.tar.gz | |
| tar xvf data-core/data-core.tar.gz | |
| - name: Install oras for pulling from GitHub Packages | |
| run: brew install oras | |
| - name: Pull executables.txt from GitHub Packages | |
| run: oras pull ghcr.io/homebrew/command-not-found/executables:latest --output api/internal | |
| - name: Generate API samples | |
| run: | | |
| GENERATE_SAMPLES="${{ github.ref_name == 'main' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false && github.event.pull_request.user.login != 'dependabot[bot]') }}" | |
| if [ "$GENERATE_SAMPLES" = "true" ]; then | |
| ruby script/generate-api-samples.rb | |
| else | |
| ruby script/generate-api-samples.rb --template | |
| fi | |
| - name: Build site | |
| run: bundle exec jekyll build | |
| - name: Validate build | |
| run: ./script/validate-build.rb | |
| - name: Sign API | |
| if: github.ref_name == 'main' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false && github.event.pull_request.user.login != 'dependabot[bot]') | |
| env: | |
| JWS_SIGNING_KEY_ID: homebrew-1 | |
| JWS_SIGNING_KEY: ${{ secrets.JWS_HOMEBREW_1 }} | |
| run: ./script/sign-json.rb | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 | |
| deploy: | |
| needs: build | |
| if: ${{ github.ref_name == 'main' }} | |
| permissions: | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| outputs: | |
| deploy_url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 | |
| deploy-issue: | |
| name: Open/close deploy issues | |
| needs: [generate-cask, generate-core, generate-analytics, build, deploy] | |
| if: ${{ always() && github.ref_name == 'main' }} | |
| env: | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| issues: write # for Homebrew/actions/create-or-update-issue | |
| steps: | |
| - name: Open, update, or close deploy issue | |
| uses: Homebrew/actions/create-or-update-issue@main | |
| with: | |
| token: ${{ github.token }} | |
| repository: ${{ github.repository }} | |
| title: formulae.brew.sh deployment failed! | |
| body: The most recent [formulae.brew.sh deployment failed](${{ env.RUN_URL }}). | |
| labels: deploy failure | |
| update-existing: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} | |
| close-existing: ${{ needs.deploy.result == 'success' }} | |
| close-from-author: github-actions[bot] | |
| close-comment: The most recent [formulae.brew.sh deployment succeeded](${{ env.RUN_URL }}). Closing issue. |