|
1 | 1 | name: Preview docs |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: |
| 4 | + workflow_run: |
| 5 | + workflows: [docs] |
| 6 | + types: [completed] |
5 | 7 |
|
6 | 8 | jobs: |
| 9 | + fail-early: |
| 10 | + if: github.repository == 'mlflow/mlflow' && github.event.workflow_run.status == 'completed' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + pull-requests: write # To post comments on PRs |
| 14 | + timeout-minutes: 10 |
| 15 | + outputs: |
| 16 | + should_continue: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 17 | + pr_number: ${{ steps.pr_number.outputs.pr_number }} |
| 18 | + steps: |
| 19 | + - uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 |
| 20 | + with: |
| 21 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + run-id: ${{ github.event.workflow_run.id }} |
| 23 | + name: pr_number |
| 24 | + path: /tmp |
| 25 | + - name: Set PR number |
| 26 | + id: pr_number |
| 27 | + run: | |
| 28 | + cat /tmp/pr_number.txt |
| 29 | + echo "pr_number=$(cat /tmp/pr_number.txt)" >> $GITHUB_OUTPUT |
| 30 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 31 | + if: github.event.workflow_run.conclusion == 'failure' |
| 32 | + with: |
| 33 | + sparse-checkout: | |
| 34 | + .github |
| 35 | + - name: Handle docs workflow failure |
| 36 | + if: github.event.workflow_run.conclusion == 'failure' |
| 37 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 38 | + env: |
| 39 | + COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} |
| 40 | + PULL_NUMBER: ${{ steps.pr_number.outputs.pr_number }} |
| 41 | + WORKFLOW_RUN_ID: ${{ github.run_id }} |
| 42 | + STAGE: failed |
| 43 | + DOCS_WORKFLOW_RUN_URL: ${{ github.event.workflow_run.html_url }} |
| 44 | + with: |
| 45 | + script: | |
| 46 | + const script = require( |
| 47 | + `${process.env.GITHUB_WORKSPACE}/.github/workflows/preview-comment.js` |
| 48 | + ); |
| 49 | + await script({ context, github, env: process.env }); |
| 50 | +
|
7 | 51 | main: |
8 | | - if: github.repository == 'mlflow/mlflow' |
| 52 | + needs: [fail-early] |
| 53 | + if: needs.fail-early.outputs.should_continue == 'true' |
9 | 54 | runs-on: ubuntu-latest |
10 | 55 | permissions: |
11 | | - statuses: read # preview_docs.py checks PR statuses |
12 | | - pull-requests: write # preview_docs.py comments on PRs |
| 56 | + pull-requests: write # To post comments on PRs |
| 57 | + actions: write # To delete artifacts |
13 | 58 | timeout-minutes: 10 |
14 | 59 | steps: |
15 | 60 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
16 | | - - uses: ./.github/actions/setup-python |
17 | | - - name: Install dependencies |
18 | | - run: | |
19 | | - pip install requests |
| 61 | + with: |
| 62 | + sparse-checkout: | |
| 63 | + .github |
| 64 | + - name: Download build artifact |
| 65 | + uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1 |
| 66 | + with: |
| 67 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + run-id: ${{ github.event.workflow_run.id }} |
| 69 | + name: docs-build-${{ github.event.workflow_run.id }} |
| 70 | + path: downloaded-artifact |
| 71 | + - uses: ./.github/actions/setup-node |
| 72 | + - name: Deploy to Netlify |
| 73 | + id: netlify_deploy |
| 74 | + working-directory: downloaded-artifact |
| 75 | + env: |
| 76 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 77 | + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 78 | + PR_NUMBER: ${{ needs.fail-early.outputs.pr_number }} |
| 79 | + RUN_ID: ${{ github.run_id }} |
| 80 | + run: |- |
| 81 | + OUTPUT=$(npx -y netlify-cli deploy \ |
| 82 | + --dir=. \ |
| 83 | + --no-build \ |
| 84 | + --message="PR Preview #${PR_NUMBER} - GitHub Run ID: $RUN_ID" \ |
| 85 | + --alias="pr-${PR_NUMBER}" \ |
| 86 | + --json) |
| 87 | + DEPLOY_URL=$(echo "$OUTPUT" | jq -r '.deploy_url') |
| 88 | + echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT |
| 89 | + continue-on-error: true |
20 | 90 | - name: Create preview link |
| 91 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
21 | 92 | env: |
22 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
23 | | - CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} |
24 | | - run: | |
25 | | - python dev/preview_docs.py \ |
26 | | - --commit-sha ${{ github.event.pull_request.head.sha }} \ |
27 | | - --pull-number ${{ github.event.pull_request.number }} \ |
28 | | - --workflow-run-id ${{ github.run_id }} |
| 93 | + COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} |
| 94 | + PULL_NUMBER: ${{ needs.fail-early.outputs.pr_number }} |
| 95 | + WORKFLOW_RUN_ID: ${{ github.run_id }} |
| 96 | + STAGE: ${{ steps.netlify_deploy.outcome == 'success' && 'completed' || 'failed' }} |
| 97 | + NETLIFY_URL: ${{ steps.netlify_deploy.outputs.deploy_url }} |
| 98 | + DOCS_WORKFLOW_RUN_URL: ${{ github.event.workflow_run.html_url }} |
| 99 | + with: |
| 100 | + script: | |
| 101 | + const script = require( |
| 102 | + `${process.env.GITHUB_WORKSPACE}/.github/workflows/preview-comment.js` |
| 103 | + ); |
| 104 | + await script({ context, github, env: process.env }); |
| 105 | + - name: Delete Build Artifact |
| 106 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 107 | + env: |
| 108 | + RUN_ID: ${{ github.event.workflow_run.id }} |
| 109 | + ARTIFACT_NAME: docs-build-${{ github.event.workflow_run.id }} |
| 110 | + with: |
| 111 | + script: | |
| 112 | + const script = require( |
| 113 | + `${process.env.GITHUB_WORKSPACE}/.github/workflows/delete-artifact.js` |
| 114 | + ); |
| 115 | + await script({ context, github, env: process.env }); |
0 commit comments