Deploy HTML to GitHub Pages (for testing!) #18
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
# Simple workflow for deploying static content to GitHub Pages | |
name: Deploy static content to Pages | |
run-name: Deploy HTML to GitHub Pages (for testing!) | |
on: | |
# Runs on pushes targeting the specific branch | |
push: | |
branches: ["website"] | |
paths-ignore: | |
- '.github/**' | |
- 'README.md' | |
- '.gitattributes' | |
- '.gitignore' | |
- '.vscode/**' | |
- 'LICENSE' | |
# Allows you to run this workflow manually from the Actions tab or via another workflow | |
workflow_dispatch: | |
# Allows the workflow to be triggered from another workflow | |
workflow_call: | |
inputs: | |
triggerUser: | |
required: true | |
type: string | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
check-trigger: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Trigger Event | |
id: check_trigger_event | |
run: | | |
echo "GITHUB_WORKSPACE is $GITHUB_WORKSPACE" # Debugging: Print GITHUB_WORKSPACE | |
# Ensure the GITHUB_WORKSPACE directory exists | |
mkdir -p $GITHUB_WORKSPACE | |
# Write trigger message based on event type | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
echo "TRIGGER_MESSAGE=\"This workflow was triggered manually by ${{ github.actor }}.\"" > $GITHUB_WORKSPACE/trigger_message.env | |
else | |
echo "TRIGGER_MESSAGE=\"This workflow was triggered by ${{ github.event_name }}.\"" > $GITHUB_WORKSPACE/trigger_message.env | |
fi | |
echo "Contents of $GITHUB_WORKSPACE/trigger_message.env:" | |
cat $GITHUB_WORKSPACE/trigger_message.env # Debugging: Print contents of the created file | |
print-trigger-message: | |
needs: [check-trigger] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print Trigger Message | |
env: | |
TRIGGER_MESSAGE_FILE: $GITHUB_WORKSPACE/trigger_message.env | |
run: | | |
source $TRIGGER_MESSAGE_FILE || true # Use '|| true' to suppress error if file not found | |
echo "$TRIGGER_MESSAGE" | |
deploy: | |
needs: [print-trigger-message] | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: website # Ensure the correct branch is checked out | |
- name: Cache Node.js modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '14' | |
- name: Install Dependencies | |
run: npm install | |
working-directory: ./docs | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
# Upload the 'docs' folder | |
path: 'docs' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |