From 011ee854a2e203e64faa9611b2a251c2c5f42828 Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Sat, 4 Nov 2023 19:29:53 +0100 Subject: [PATCH 1/2] Initial workflow config for doc previews on netlify --- .github/workflows/pr_doc_preview.yml | 63 ++++++++++++++++++++++++++++ .github/workflows/push_doc.yml | 30 ++++++++++++- 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pr_doc_preview.yml diff --git a/.github/workflows/pr_doc_preview.yml b/.github/workflows/pr_doc_preview.yml new file mode 100644 index 0000000..d8c6f22 --- /dev/null +++ b/.github/workflows/pr_doc_preview.yml @@ -0,0 +1,63 @@ +name: Preview doc in PRs + +on: + workflow_run: + workflows: ["push_doc"] + types: + - completed + +jobs: + pr_doc_preview: + runs-on: ubuntu-latest + if: ${{github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'}} + steps: + - name: 'Commit Status: Set Workflow Status as Pending' + uses: myrotvorets/set-commit-status-action@1.1.6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: pending + sha: ${{ github.event.workflow_run.head_sha }} + context: 'Doc preview' + + - uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: push_doc.yml + run_id: ${{ github.event.workflow_run.id }} + name: push_doc + + - name: Get pull request number + id: pull-request-number + run: | + export PULL_REQUEST_NUMBER=`cat pull_request_number` + echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" + echo "result=${PULL_REQUEST_NUMBER}" >> $GITHUB_OUTPUT + + - uses: actions/setup-node@v3 + with: + node-version: '16' + - run: npm install --global netlify-cli@6 + - name: Deploy to Netlify + env: + NETLIFY_AUTH_TOKEN: ${{secrets.NETLIFY_AUTH_TOKEN}} + NETLIFY_SITE_ID: ${{secrets.NETLIFY_SITE_ID}} + run: | + echo "Deploying PR ${{steps.pull-request-number.outputs.result}} to Netlify" + netlify deploy --dir=build --alias=pull-request-${{steps.pull-request-number.outputs.result}} + + - name: 'Commit Status: Update deployment status' + uses: myrotvorets/set-commit-status-action@1.1.6 + # Always run this step regardless of job failing early + if: always() + env: + DEPLOY_SUCCESS: Successfully deployed preview. + DEPLOY_FAILURE: Failed to deploy preview. + TARGET_URL_SUCCESS: https://pull-request-${{steps.pull-request-number.outputs.result}}--hazardous-doc.netlify.app/ + TARGET_URL_FAILURE: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status == 'success' && 'success' || 'failure' }} + sha: ${{ github.event.workflow_run.head_sha }} + context: 'Doc preview' + description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }} + targetUrl: ${{ job.status == 'success' && env.TARGET_URL_SUCCESS || env.TARGET_URL_FAILURE }} diff --git a/.github/workflows/push_doc.yml b/.github/workflows/push_doc.yml index d16705d..871909a 100644 --- a/.github/workflows/push_doc.yml +++ b/.github/workflows/push_doc.yml @@ -4,25 +4,51 @@ on: push: branches: - main - workflow_dispatch: + - test-ci* + pull_request: + branches: + - main permissions: contents: write jobs: - deploy: + push_doc: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: '3.10' + - run: pip install .[doc] + - name: Sphinx build run: sphinx-build doc build + + - name: Save the PR number + env: + GITHUB_PULL_REQUEST_NUMBER: ${{github.event.number}} + run: | + echo "Storing PR number ${{github.event.number}} to 'pull_request_number' file" + echo ${{github.event.number}} > pull_request_number + + - name: Upload doc preview + # The publication of the preview itself happens in pr-doc-preview.yml + if: ${{ github.event_name == 'pull_request' }} + uses: actions/upload-artifact@v3 + with: + name: jupyter-book + path: | + ./build + pull_request_number + - name: Deploy + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} uses: peaceiris/actions-gh-pages@v3 with: publish_branch: gh-pages github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./build + commit_message: "[ci skip] ${{ github.event.head_commit.message }}" From d4dc983957511f520d142852916c4197e9c79d37 Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Sat, 4 Nov 2023 19:37:03 +0100 Subject: [PATCH 2/2] Various config fixes --- .github/workflows/pr_doc_preview.yml | 7 +++++-- .github/workflows/push_doc.yml | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr_doc_preview.yml b/.github/workflows/pr_doc_preview.yml index d8c6f22..72c69e1 100644 --- a/.github/workflows/pr_doc_preview.yml +++ b/.github/workflows/pr_doc_preview.yml @@ -24,7 +24,7 @@ jobs: github_token: ${{secrets.GITHUB_TOKEN}} workflow: push_doc.yml run_id: ${{ github.event.workflow_run.id }} - name: push_doc + name: doc-preview - name: Get pull request number id: pull-request-number @@ -38,9 +38,12 @@ jobs: node-version: '16' - run: npm install --global netlify-cli@6 - name: Deploy to Netlify + # The github secrets hold a Personal Access Token (PAT) managed by + # ogrisel on Netlify. I should allow to programmatically upload doc + # previews under the hazardous-doc.netlify.app domain. env: + NETLIFY_SITE_ID: hazardous-doc NETLIFY_AUTH_TOKEN: ${{secrets.NETLIFY_AUTH_TOKEN}} - NETLIFY_SITE_ID: ${{secrets.NETLIFY_SITE_ID}} run: | echo "Deploying PR ${{steps.pull-request-number.outputs.result}} to Netlify" netlify deploy --dir=build --alias=pull-request-${{steps.pull-request-number.outputs.result}} diff --git a/.github/workflows/push_doc.yml b/.github/workflows/push_doc.yml index 871909a..6e4315e 100644 --- a/.github/workflows/push_doc.yml +++ b/.github/workflows/push_doc.yml @@ -1,4 +1,4 @@ -name: Publish documentation +name: Build documentation on: push: @@ -39,7 +39,7 @@ jobs: if: ${{ github.event_name == 'pull_request' }} uses: actions/upload-artifact@v3 with: - name: jupyter-book + name: doc-preview path: | ./build pull_request_number