Trigger web publish on merged PRs #103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Web Page | |
on: | |
workflow_dispatch: | |
workflow_run: | |
workflows: | |
- Continuous Integration | |
types: | |
- completed | |
branches: | |
- main | |
pull_request: | |
types: [closed] | |
push: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/publish-web.yml' | |
- 'schemius-web/**.css' | |
- 'schemius-web/**.html' | |
- 'schemius-web/**.js' | |
env: | |
WORK_DIR: ./schemius-web | |
WEB_PAGE: index.html | |
WEB_PAGE_SOURCE: schemius.html | |
WEB_PAGE_JS: schemius.js | |
ARTIFACTS: artifacts | |
PUBLISH_DIR: ./dist | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
if: | | |
github.event_name == 'push' || | |
github.event_name == 'dispatch' || | |
github.event.workflow_run.conclusion == 'success' || | |
github.event.pull_request.merged == true | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install rustup | |
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
- name: Produce WASM package | |
run: | | |
cargo install wasm-pack | |
rustup target add wasm32-unknown-unknown | |
wasm-pack build --release --target web | |
working-directory: ${{ env.WORK_DIR }} | |
- name: Generate final web page | |
run: | | |
cp $WEB_PAGE_SOURCE $WEB_PAGE | |
sed -i "s/DATETIME_PLACEHOLDER/$(date -u '+Published %F %H:%M:%S UTC')/g" $WEB_PAGE_JS | |
working-directory: ${{ env.WORK_DIR }} | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACTS }} | |
path: | | |
${{ env.WORK_DIR }}/${{ env.WEB_PAGE }} | |
${{ env.WORK_DIR }}/${{ env.WEB_PAGE_JS }} | |
${{ env.WORK_DIR }}/pkg | |
if-no-files-found: error | |
deploy: | |
name: Deploy | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACTS }} | |
path: ${{ env.PUBLISH_DIR }} | |
- name: Remove vicious .gitignore | |
run: rm ${{ env.PUBLISH_DIR }}/pkg/.gitignore | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ${{ env.PUBLISH_DIR }} |