Skip to content

Commit

Permalink
Merge branch 'main' into scottyhq-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyhq authored Jun 20, 2024
2 parents 1a12065 + 8fbcf21 commit 3ca2032
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 1 deletion.
40 changes: 40 additions & 0 deletions .github/workflows/buildonly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: PR Build

on:
pull_request:
# when using teardown: 'true', add default event types + closed event type
types: [opened, synchronize, reopened, closed]

#permissions:
# pull-requests: write # allow surge-preview to create/update PR comments

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
# environment: SurgePreviewPR
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Conda environment with Micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
cache-environment: true

- name: Build JupyterBook
run: |
jb build book
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: html
path: book/_build/html
61 changes: 61 additions & 0 deletions .github/workflows/deployonly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: PR Preview

on:
workflow_run:
workflows: ["PR Build"]
types:
- completed

permissions:
pull-requests: write # allow surge-preview to create/update PR comments

concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.id }}
cancel-in-progress: true

jobs:
preview:
# environment: SurgePreviewPR
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}

steps:
# - name: Debug step
# run: |
# echo "workflow_run: ${{toJSON(github.event.workflow_run)}}"
# echo "workflow_run.head_sha: ${{github.event.workflow_run.head_sha}}"

- uses: actions/download-artifact@v4
with:
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}
path: html
# name: my-other-artifact
# github-token: ${{ secrets.GH_PAT }} # token with actions:read permissions on target repo
# repository: actions/toolkit
# run-id: 1234

- name: List directory contents
run: |
pwd
ls -lh
ls html
ls html/*
du -sh *
# - name: download dist artifact
# uses: dawidd6/action-download-artifact@v5
# with:
# workflow: ${{ github.event.workflow_run.workflow_id }}
# name: pr-build-dist # must be kept in sync with the artifact name downloaded in the build stage
# path: site/

- name: Manage Surge deployment
uses: afc163/surge-preview@v1
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
build: ls *
dist: html
failOnError: true
teardown: true
6 changes: 5 additions & 1 deletion .github/workflows/surgedeploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: PR Preview

on: [pull_request]
on:
pull_request:
# when using teardown: 'true', add default event types + closed event type
types: [opened, synchronize, reopened, closed]

permissions:
pull-requests: write # allow surge-preview to create/update PR comments
Expand Down Expand Up @@ -35,6 +38,7 @@ jobs:
uses: afc163/surge-preview@v1
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dist: book/_build/html
teardown: true
failOnError: true
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/surgedeployPRT.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: PRT Preview

# based on https://michaelheap.com/access-secrets-from-forks/
on:
pull_request_target:
# when using teardown: 'true', add default event types + closed event type
types: [opened, synchronize, reopened, closed]

permissions:
pull-requests: write # allow surge-preview to create/update PR comments

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
preview:
# environment: SurgePreviewPR
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Get User Permission
id: checkAccess
uses: actions-cool/check-user-permission@v2
with:
require: write
username: ${{ github.triggering_actor }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check User Permission
if: steps.checkAccess.outputs.require-result == 'false'
run: |
echo "${{ github.triggering_actor }} does not have permissions on this repo."
echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}"
echo "Job originally triggered by ${{ github.actor }}"
exit 1
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # This is dangerous without the first access check

- name: Install Conda environment with Micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
cache-environment: true

- name: Build JupyterBook
run: |
jb build book
- name: Build and Publish to Surge
id: preview_step
uses: afc163/surge-preview@v1
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dist: book/_build/html
teardown: true
failOnError: true
# website already built in previous step, just list existing folder
build: echo 'skipping website build'

- 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 "${{ steps.format_url.outputs.url_text }}"

- name: Generate summary
run: |
echo "#### ${{ steps.format_url.outputs.url_text }}" >> $GITHUB_STEP_SUMMARY

0 comments on commit 3ca2032

Please sign in to comment.