diff --git a/.github/workflows/pr-close.yml b/.github/workflows/pr-close.yml deleted file mode 100644 index d8833f18..00000000 --- a/.github/workflows/pr-close.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: delete preview on PR close -on: - pull_request_target: - types: [closed] - -jobs: - delete_preview: - runs-on: ubuntu-latest - env: - PR_PATH: pull/${{github.event.number}} - steps: - - name: Checkout website repo - uses: actions/checkout@v4 - with: - ref: gh-pages - - - name: Delete preview - run: | - git rm -r ${{ env.PR_PATH }} - git commit -m "Delete preview for PR #${{ github.event.number }}" - git push origin gh-pages - - - name: Comment on PR - uses: hasura/comment-progress@v2.2.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ github.repository }} - number: ${{ github.event.number }} - id: deploy-preview - message: "🪓 PR closed, deleted preview at https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/" \ No newline at end of file diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml deleted file mode 100644 index 966ab968..00000000 --- a/.github/workflows/pr-comment.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Comment on the pull request. - -on: - workflow_run: - workflows: ["Github Pages"] - types: [in_progress, completed] - -jobs: - in-progress: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.status == 'in_progress' }} - steps: - - name: 'Comment on PR - Waiting for deployment' - uses: hasura/comment-progress@v2.3.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ github.repository }} - number: ${{ github.event.workflow_run.pull_requests.number }} - id: deploy-preview - message: "Starting deployment of preview ⏳..." - on-failure: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }} - steps: - - name: 'Comment on PR - Waiting for deployment' - uses: hasura/comment-progress@v2.3.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ github.repository }} - number: ${{ github.event.workflow_run.pull_requests.number }} - id: deploy-preview - message: "⚠️⚠️⚠️ Build Failed: No preview available." - on-success: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} - env: - PR_PATH: dipy.org/pull/${{github.event.workflow_run.pull_requests.number}} - BASE_URL: https://dipy.github.io/dipy-preview - steps: - - name: Update comment - uses: hasura/comment-progress@v2.3.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ github.repository }} - number: ${{ github.event.workflow_run.pull_requests.number }} - id: deploy-preview - message: "A preview of ${{ github.event.workflow_run.head_commit }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }}/${{ env.PR_PATH }} ✨\n\nChanges may take a few minutes to propagate. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/" - diff --git a/.github/workflows/preview-html.yml b/.github/workflows/preview-html.yml new file mode 100644 index 00000000..7e6bbda8 --- /dev/null +++ b/.github/workflows/preview-html.yml @@ -0,0 +1,111 @@ +name: Comment on the pull request. + +on: + workflow_run: + workflows: ["Github Pages"] + types: [in_progress, completed] + pull_request_target: + types: [closed] + +jobs: + get-pr-number: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.event == 'pull_request' }} + outputs: + output1: ${{ steps.echo_pr_nb.outputs.pr_number }} + steps: + - name: Download workflow artifact + uses: dawidd6/action-download-artifact@v2.11.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: publish.yml + run_id: ${{ github.event.workflow_run.id }} + - name: Read the pull_request_number.txt file + id: pull_request_number_reader + uses: juliangruber/read-file-action@v1.0.0 + with: + path: ./pull_request_number/pull_request_number.txt + - name: Echo pull_request_number + id: echo_pr_nb + run: echo "pr_number=${{ steps.pull_request_number_reader.outputs.content }}" >> $GITHUB_OUTPUT + + in-progress: + runs-on: ubuntu-latest + needs: get-pr-number + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.status == 'in_progress' }} + steps: + - name: 'Comment on PR - Waiting for deployment' + uses: hasura/comment-progress@v2.3.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ needs.get-pr-number.outputs.output1 }} + id: deploy-preview + message: "Starting deployment of preview ⏳..." + on-failure: + runs-on: ubuntu-latest + needs: get-pr-number + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure' }} + steps: + - name: 'Comment on PR - Waiting for deployment' + uses: hasura/comment-progress@v2.3.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ needs.get-pr-number.outputs.output1 }} + id: deploy-preview + message: "⚠️⚠️⚠️ Build Failed: No preview available." + on-success: + runs-on: ubuntu-latest + needs: get-pr-number + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + env: + PR_PATH: dipy.org/pull/${{needs.get-pr-number.outputs.output1}} + BASE_URL: https://dipy.github.io/dipy-preview + steps: + - name: Deploy to PR preview + uses: peaceiris/actions-gh-pages@v3 + with: + deploy_key: ${{ secrets.ACTIONS_DEPLOY_TOKEN }} + external_repository: dipy/preview-html + publish_dir: ./_build/html + publish_branch: main + destination_dir: ${{ env.PR_PATH }} + keep_files: true + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' + commit_message: ${{ github.event.head_commit.message }} + - name: Update comment + uses: hasura/comment-progress@v2.3.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ needs.get-pr-number.outputs.output1 }} + id: deploy-preview + message: "A preview of ${{ github.event.workflow_run.head_commit }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }}/${{ env.PR_PATH }} ✨\n\nChanges may take a few minutes to propagate. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/" + on-closed: + runs-on: ubuntu-latest + if: ${{ github.event.action == 'pull_request_target' }} + env: + PR_PATH: pull/${{github.event.number}} + steps: + - name: Checkout website repo + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Delete preview + run: | + git rm -r ${{ env.PR_PATH }} + git commit -m "Delete preview for PR #${{ github.event.number }}" + git push origin gh-pages + + - name: Comment on PR + uses: hasura/comment-progress@v2.2.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.number }} + id: deploy-preview + message: "🪓 PR closed, deleted preview at https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/" + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5a5a1511..c27d3578 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,6 +22,18 @@ jobs: REF: ${{github.ref}} STATUS: ${{github.event.pull_request.head.repo.full_name != github.repository}} steps: + - name: Save the PR number in an artifact + shell: bash + env: + PULL_REQUEST_NUMBER: ${{ github.event.number }} + run: echo $PULL_REQUEST_NUMBER > pull_request_number.txt + + - name: Upload the PULL REQUEST number + uses: actions/upload-artifact@v2 + with: + name: pull_request_number + path: ./pull_request_number.txt + - name: Checkout website repo uses: actions/checkout@v4 @@ -40,7 +52,7 @@ jobs: make -C . html - name: Upload HTML - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v2 with: name: DocumentationHTML path: _build/html/ @@ -55,19 +67,3 @@ jobs: user_email: 'github-actions[bot]@users.noreply.github.com' commit_message: ${{ github.event.head_commit.message }} # cname: ${{ env.DOMAIN # TODO: set this if you're using a custom domain. - - - name: Deploy to PR preview - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.event.pull_request.head.repo.full_name != '' && github.event.pull_request.head.repo.full_name != github.repository }} - secrets: inherit - with: - deploy_key: ${{ secrets.ACTIONS_DEPLOY_TOKEN }} - external_repository: dipy/preview-html - publish_dir: ./_build/html - publish_branch: main - destination_dir: ${{ env.PR_PATH }} - keep_files: true - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' - commit_message: ${{ github.event.head_commit.message }} -