diff --git a/.github/actions/determine-auto-action.sh b/.github/actions/determine-auto-action.sh new file mode 100644 index 00000000..6f7cc960 --- /dev/null +++ b/.github/actions/determine-auto-action.sh @@ -0,0 +1,28 @@ +# Script copied from https://github.com/rossjrw/pr-preview-action/blob/main/lib/determine-auto-action.sh + +case $GITHUB_EVENT_NAME in + "pull_request" | "pull_request_target") + echo "event_name is $GITHUB_EVENT_NAME; proceeding" + ;; + *) + echo "unknown event $GITHUB_EVENT_NAME; no action to take" + echo "action=none" >> "$GITHUB_ENV" + exit 0 + ;; +esac + +event_type=$(jq -r ".action" "$GITHUB_EVENT_PATH") +echo "event_type is $event_type" + +case $event_type in + "opened" | "reopened" | "synchronize") + echo "action=deploy" >> "$GITHUB_ENV" + ;; + "closed") + echo "action=remove" >> "$GITHUB_ENV" + ;; + *) + echo "unknown event type $event_type; no action to take" + echo "action=none" >> "$GITHUB_ENV" + ;; +esac \ No newline at end of file diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 00000000..0fd2d1a7 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,118 @@ +name: Deploy PR previews + +on: + workflow_dispatch: + pull_request: + branches: main + types: + - opened + - reopened + - synchronize + - closed + +permissions: + contents: read + pages: write + id-token: write + pull-requests: write + +concurrency: preview-${{ github.ref }} + +env: + INPUT_PATH: "." + PREVIEW_FOLDER: "/pr-preview" # subfolder + pr: ${{ github.event.number }} + OSSI_SITE_TOKEN: ${{ secrets.GITHUB_TOKEN }} + action: auto + preview-branch: main + actionref: ${{ github.action_ref }} + actionrepo: ${{ github.action_repository }} + deployrepo: ${{ github.repository }} + +jobs: + build: + runs-on: composite + + steps: + - name: Store environment variables + run: | + org=$(echo "${{env.deployrepo}}" | cut -d "/" -f 1) + thirdleveldomain=$(echo "${{env.deployrepo}}" | cut -d "/" -f 2) + + if [ "${org}.github.io" == "$thirdleveldomain" ]; then + pagesurl="${org}.github.io" + else + pagesurl=$(echo "${{env.deployrepo}}" | sed 's/\//.github.io\//') + fi + echo "pagesurl=$pagesurl" >> $GITHUB_ENV + echo "PREVIEW_PATH=${{env.PREVIEW_FOLDER}}/pr-${{env.pr}}" >> $GITHUB_ENV + echo "emptydir=$(mktemp -d)" >> $GITHUB_ENV + echo "datetime=$(date '+%Y-%m-%d %H:%M %Z')" >> $GITHUB_ENV + shell: bash + + - name: Checkout + uses: actions/checkout@v4 + + - name: Determine auto action + run: .github/actions/determine-auto-action.sh + shell: bash + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: npm + cache-dependency-path: ${{ env.INPUT_PATH }}/package-lock.json + + - name: Setup Pages + id: pages + uses: actions/configure-pages@v4 + + - name: Install dependencies + run: npm ci + working-directory: ${{ env.INPUT_PATH }} + + - name: Build with Astro + run: | + npx --no-install astro build \ + --site "https://${{ env.pagesurl }}" \ + --base "${{ env.PREVIEW_PATH }}" + --outdir "${{env.PREVIEW_PATH}}/dist" + --cachedir "${{env.PREVIEW_PATH}}/node_modules/.astro" + working-directory: ${{ env.INPUT_PATH}} + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: $${{env.PREVIEW_PATH}}/dist + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: build + runs-on: ubuntu-latest + name: Deploy + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + + - name: Expose deployment URL + id: url + run: echo "url=https://${{ env.pagesurl }}/${{ env.PREVIEW_PATH }}/" >> $GITHUB_OUTPUT + shell: bash + + - name: Leave a comment after deployment + uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0 + with: + header: pr-preview + message: " + :rocket: Deployed preview to + https://${{ env.pagesurl }}/${{ env.PREVIEW_PATH }}/ + + on branch [`${{ env.preview-branch }}`](\ + ${{ github.server_url }}/${{ env.deployrepo }}\ + /tree/${{ env.preview-branch }}) + at ${{ env.datetime }} + " diff --git a/pr-preview/text.txt b/pr-preview/text.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 465f826e..2897449d 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -5,6 +5,9 @@ import janeliaLogoBlack from "../assets/images/HHMI_Janelia_Logo-Black.png"; import janeliaLogoWhite from "../assets/images/HHMI_Janelia_Logo-White.png"; const baseUrl = import.meta.env.BASE_URL; +const previewPath = import.meta.env.PREVIEW_PATH + ? import.meta.env.PREVIEW_PATH + : ""; ---