From 107c2cf3ab3a37f0c7961b35f4a0bcb971aa2211 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 12 Jun 2024 20:13:03 +0000 Subject: [PATCH 1/2] Remove generated site files --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b8cc71c44..e60dee1f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ .yardoc/ _site/ -brew/ +brew vendor/ Gemfile.lock + +# Exclude the generated site files +docs/ +!docs/_config.yml +!docs/CNAME \ No newline at end of file From ea210d1c71fbb2d4c3150f58efc3a03c3a95b113 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 12 Jun 2024 20:18:47 +0000 Subject: [PATCH 2/2] Update scheduled workflow to use pages v4 --- .github/workflows/scheduled.yml | 85 +++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index 40c37c1e3..f80c13401 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -2,23 +2,24 @@ name: Scheduled regeneration on: push: - paths: - - .github/workflows/scheduled.yml + branches: + - master + pull_request: schedule: # Once every hour - cron: "30 * * * *" + workflow_dispatch: concurrency: - group: scheduled + group: scheduled-${{ github.ref }}-${{ github.event_name }} cancel-in-progress: true -permissions: - contents: write - jobs: generate: if: startsWith( github.repository, 'Homebrew/' ) - runs-on: ubuntu-22.04 + name: Generate and build documentation site + runs-on: ubuntu-latest + timeout-minutes: 20 steps: - name: Set up Git repository uses: actions/checkout@v4 @@ -33,26 +34,68 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@78c01b705fd9d5ad960d432d3a0cfa341d50e410 # v1.179.1 with: - ruby-version: "3.1" bundler-cache: true - - name: Configure Git user - uses: Homebrew/actions/git-user-config@master - with: - username: BrewTestBot - - name: Generate site run: | ln -s $(brew --repo) brew bundle exec rake yard build - - name: Commit changes + - name: Upload pages artifact + uses: actions/upload-pages-artifact@v3 + + deploy: + needs: generate + if: ${{ github.ref_name == 'master' }} + 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@v4 + + deploy-issue: + name: Open/close deploy issue + needs: [generate, deploy] + if: ${{ always() && github.ref_name == 'master' }} + env: + GH_TOKEN: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }} + REPO: ${{ github.repository }} + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Find existing deploy failure issue run: | - git reset origin/master - git add docs - if ! git diff --no-patch --exit-code HEAD -- docs; then - git commit -m "docs: updates from Homebrew/brew" docs - fi + EXISTING_ISSUE=$(gh issue list --repo "$REPO" --author BrewTestBot --label 'deploy failure' | awk '{print $1}') + echo "EXISTING_ISSUE=$EXISTING_ISSUE" >> $GITHUB_ENV + echo "WORKFLOW_URL=https://github.com/Homebrew/rubydoc.brew.sh/actions/runs/$RUN_ID" >> $GITHUB_ENV + env: + RUN_ID: ${{ github.run_id }} - - name: Push commits - uses: Homebrew/actions/git-try-push@master + - name: Report deploy failure + if: ${{ contains(needs.*.result, 'failure') }} + run: | + ISSUE_TITLE="rubydoc.brew.sh deployment failed!" + ISSUE_BODY="The most recent [rubydoc.brew.sh deployment failed]($WORKFLOW_URL)." + if [ -n "$EXISTING_ISSUE" ]; then + gh issue edit "$EXISTING_ISSUE" --repo "$REPO" --body "$(echo -e "$ISSUE_BODY")" + else + gh issue create --repo "$REPO" --title "$ISSUE_TITLE" --label "deploy failure" --body "$(echo -e "$ISSUE_BODY")" + fi + + - name: Report deploy success + if: ${{ needs.deploy.result == 'success' }} + run: | + COMMENT_BODY="The most recent [rubydoc.brew.sh deployment succeeded]($WORKFLOW_URL). Closing issue." + if [ -n "$EXISTING_ISSUE" ]; then + gh issue comment "$EXISTING_ISSUE" --repo "$REPO" --body "$(echo -e "$COMMENT_BODY")" + gh issue close "$EXISTING_ISSUE" --repo "$REPO" + fi \ No newline at end of file