From 7dba477831656931dd58288f10f9052cab3afb53 Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Fri, 2 Jun 2023 17:12:57 -0700 Subject: [PATCH 1/9] Setup PR Preview workflow --- .github/workflows/preview.yaml | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/preview.yaml diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml new file mode 100644 index 00000000..444f7f71 --- /dev/null +++ b/.github/workflows/preview.yaml @@ -0,0 +1,39 @@ +name: PR Preview + +on: [pull_request] + +permissions: + pull-requests: write # allow surge-preview to create/update PR comments + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - uses: ./.github/actions/setupconda + + - name: Build JupyterBook + # NOTE: login shell activates conda environment + shell: bash -l {0} + run: | + jupyter-book build ./ --warningiserror --keep-going + + - name: Dump Build Logs + if: always() + run: | + if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi + + - name: Publish to Surge + id: preview_step + uses: afc163/surge-preview@v1 + with: + surge_token: ${{ secrets.SURGE_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} + dist: _build/html + build: | + npm install surge + + - name: Get the preview_url + run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" From d718bc09b09e97d7f80b312eb3808db59adac782 Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Fri, 2 Jun 2023 17:25:51 -0700 Subject: [PATCH 2/9] Fix trailing whitespace --- .github/workflows/preview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 444f7f71..83b4faba 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -34,6 +34,6 @@ jobs: dist: _build/html build: | npm install surge - + - name: Get the preview_url run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" From de3c04d890fb5abe07c509824c7f8e0b63f5a2ae Mon Sep 17 00:00:00 2001 From: Don Setiawan Date: Tue, 13 Jun 2023 12:10:57 -0700 Subject: [PATCH 3/9] Update .github/workflows/preview.yaml Co-authored-by: Anderson Banihirwe <13301940+andersy005@users.noreply.github.com> --- .github/workflows/preview.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 83b4faba..24f03025 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -12,7 +12,19 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - uses: ./.github/actions/setupconda + - name: Setup JupyterBook Cache + uses: actions/cache@v3 + with: + path: _build + # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache + key: jupyterbook-20230602 + + - name: Install Conda environment with Micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: conda/conda-lock.yml + environment-name: xarray-tutorial + cache-environment: true - name: Build JupyterBook # NOTE: login shell activates conda environment From 58eb85b944b808e3534fd13db8dda3abc1d07756 Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Tue, 13 Jun 2023 12:16:46 -0700 Subject: [PATCH 4/9] Fix syntax error --- .github/workflows/preview.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 24f03025..2dca4af1 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -12,12 +12,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Setup JupyterBook Cache - uses: actions/cache@v3 - with: - path: _build - # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache - key: jupyterbook-20230602 + - name: Setup JupyterBook Cache + uses: actions/cache@v3 + with: + path: _build + # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache + key: jupyterbook-20230613 - name: Install Conda environment with Micromamba uses: mamba-org/setup-micromamba@v1 From 47528512675d03e22ef74160a2e4a11ee25a3aff Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Tue, 13 Jun 2023 12:18:22 -0700 Subject: [PATCH 5/9] Fix another indent --- .github/workflows/preview.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 2dca4af1..004e3568 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -13,11 +13,11 @@ jobs: uses: actions/checkout@v3 - name: Setup JupyterBook Cache - uses: actions/cache@v3 - with: - path: _build - # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache - key: jupyterbook-20230613 + uses: actions/cache@v3 + with: + path: _build + # NOTE: change key to "jupyterbook-DATE" to force rebuilding cache + key: jupyterbook-20230613 - name: Install Conda environment with Micromamba uses: mamba-org/setup-micromamba@v1 From cea4ee5c96575c877e97f5898c249ac9520201b2 Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Tue, 13 Jun 2023 12:33:06 -0700 Subject: [PATCH 6/9] Add step summary --- .github/workflows/preview.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 004e3568..a68dd0dd 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -48,4 +48,8 @@ jobs: npm install surge - name: Get the preview_url - run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" + run: echo "url => https://${{ steps.preview_step.outputs.preview_url }}" + + - name: Generate summary + run: | + echo "### :rocket: Preview url deployed at https://${{ steps.preview_step.outputs.preview_url }}" >> $GITHUB_STEP_SUMMARY From d32b32be3ba4f251c503655da4b15a9cf2a338de Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Tue, 13 Jun 2023 13:13:56 -0700 Subject: [PATCH 7/9] Add preview url formatting and manual PR comment --- .github/workflows/preview.yaml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index a68dd0dd..6b71c284 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -46,10 +46,25 @@ jobs: dist: _build/html build: | npm install surge + + - name: Format preview url + id: format_url + run: | + echo "url_text=:rocket: Preview deployed at https://${{ steps.preview_step.outputs.preview_url }}" >> $GITHUB_OUTPUT - name: Get the preview_url - run: echo "url => https://${{ steps.preview_step.outputs.preview_url }}" + run: echo "${{ steps.format_url.outputs.url_text }}" - name: Generate summary run: | - echo "### :rocket: Preview url deployed at https://${{ steps.preview_step.outputs.preview_url }}" >> $GITHUB_STEP_SUMMARY + echo "#### ${{ steps.format_url.outputs.url_text }}" >> $GITHUB_STEP_SUMMARY + + - uses: actions/github-script@v6 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '${{ steps.format_url.outputs.url_text }}' + }) From ab6515c3acbbd6b2ded90548509f455573ef3a1f Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Tue, 13 Jun 2023 13:50:47 -0700 Subject: [PATCH 8/9] Remove trying to do PR comment, looks like it doesn't work for fork PR --- .github/workflows/preview.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index 6b71c284..be7e0ed5 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -58,13 +58,3 @@ jobs: - name: Generate summary run: | echo "#### ${{ steps.format_url.outputs.url_text }}" >> $GITHUB_STEP_SUMMARY - - - uses: actions/github-script@v6 - with: - script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: '${{ steps.format_url.outputs.url_text }}' - }) From 84d808d6077b7bf907f0cea1f110195cbf945ef7 Mon Sep 17 00:00:00 2001 From: Landung 'Don' Setiawan Date: Tue, 13 Jun 2023 13:52:47 -0700 Subject: [PATCH 9/9] Remove trailing whitespace --- .github/workflows/preview.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml index be7e0ed5..0b96db81 100644 --- a/.github/workflows/preview.yaml +++ b/.github/workflows/preview.yaml @@ -46,7 +46,7 @@ jobs: dist: _build/html build: | npm install surge - + - name: Format preview url id: format_url run: |