Skip to content

Commit

Permalink
Configure publishing to github pages (#20)
Browse files Browse the repository at this point in the history
* Configure publishing to github pages
  • Loading branch information
MarcusLongmuir authored Dec 1, 2023
1 parent 9391ccb commit ea90729
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/actions/npm-install-build-and-cache/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ runs:
name: build-artifacts
path: |
tools/**/build/*
github-pages-publisher/build/*
if-no-files-found: error
28 changes: 27 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "NPM Install, Build, and Cache"
Expand All @@ -32,6 +33,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
Expand All @@ -49,6 +51,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
Expand All @@ -66,6 +69,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
Expand All @@ -75,9 +79,30 @@ jobs:
- name: Lint
run: npm run lint-all

publish-gh-pages:
name: Publish GitHub Pages
needs: [build, test, type-check, lint]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
id: retrieve-deps-and-build
uses: ./.github/actions/retrieve-deps-and-build

- name: Deploy the build to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./github-pages-publisher/build

summary:
name: Summary
needs: [build, test, type-check, lint]
needs: [build, test, type-check, lint, publish-gh-pages]
runs-on: ubuntu-latest
steps:
- name: Summary
Expand All @@ -86,3 +111,4 @@ jobs:
echo "Test: ${{ needs.test.result }}"
echo "Type Check: ${{ needs.type-check.result }}"
echo "Lint: ${{ needs.lint.result }}"
echo "Publish GitHub Pages: ${{ needs.publish-gh-pages.result }}"
31 changes: 31 additions & 0 deletions .github/workflows/pr-close.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: delete preview on PR close

# only trigger on pull request closed events
on:
pull_request:
types: [closed]

jobs:
delete_preview:
runs-on: ubuntu-20.04
env:
PR_PATH: pull/${{github.event.number}}
steps:
- name: make empty dir
run: mkdir empty-dir

- name: delete folder
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./empty-dir
destination_dir: ${{ env.PR_PATH }}

- name: Comment on PR
uses: hasura/[email protected]
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 }}/"
40 changes: 40 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "NPM Install, Build, and Cache"
Expand All @@ -32,6 +33,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
Expand All @@ -49,6 +51,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
Expand All @@ -66,6 +69,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
Expand All @@ -75,6 +79,42 @@ jobs:
- name: Lint
run: npm run lint-all

publish-gh-pages:
name: Publish GitHub Pages
needs: [build]
runs-on: ubuntu-latest
env:
PR_PATH: pull/${{github.event.number}}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
lfs: true
persist-credentials: false

- name: "Retrieve Dependencies and Build Artifacts"
id: retrieve-deps-and-build
uses: ./.github/actions/retrieve-deps-and-build

- name: Set base URL for preview if PR
run: echo "BASE_URL=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.PR_PATH }}/" >> $GITHUB_ENV

- name: Deploy to PR preview
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./github-pages-publisher/build
destination_dir: ${{ env.PR_PATH }}

- name: Add PR Preview comment
uses: hasura/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
number: ${{ github.event.number }}
id: deploy-preview
message: "A preview of ${{ github.event.after }} is uploaded and can be seen here:\n\n ✨ ${{ env.BASE_URL }} ✨\n\nChanges may take a few minutes to propagate. The source is here: https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/"

summary:
name: Summary
needs: [build, test, type-check, lint]
Expand Down
3 changes: 3 additions & 0 deletions github-pages-publisher/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="tools/gltf-avatar-exporter/">
GLTF Avatar Exporter
</a>
10 changes: 10 additions & 0 deletions github-pages-publisher/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "github-pages-publisher",
"private": true,
"scripts": {
"build": "./publish.sh"
},
"devDependencies": {
"@mml-io/gltf-avatar-exporter": "file:../tools/gltf-avatar-exporter"
}
}
16 changes: 16 additions & 0 deletions github-pages-publisher/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Exit on error and echo each command
set -ex

# Set the working directory to the location of this script
cd "$(dirname "$0")"

# Create the build directory
mkdir -p ./build/tools

# Copy the index.html file that references the different tools into the build directory
cp ./index.html ./build/index.html

# Copy the files for each tool into the build directory
cp -r ../tools/gltf-avatar-exporter/build ./build/tools/gltf-avatar-exporter
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
},
"workspaces": [
"packages/*",
"tools/*"
"tools/*",
"github-pages-publisher"
],
"devDependencies": {
"@types/jest": "29.5.4",
Expand Down

0 comments on commit ea90729

Please sign in to comment.