Skip to content

Update static-deployment.yml #5

Update static-deployment.yml

Update static-deployment.yml #5

# .github/workflows/deploy-to-pages.yml
name: Deploy to GitHub Pages
on:
push:
branches:
- '**' # Trigger on all branches
release:
types:
- created # Trigger on release creation
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Deploy to GitHub Pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Determine deployment path based on event type
if [ "${{ github.event_name }}" == "release" ]; then
DEPLOY_PATH="releases/${{ github.event.release.tag_name }}"
else
DEPLOY_PATH="branches/${{ github.ref_name }}"
fi
# Define the output directory for GitHub Pages
OUTPUT_DIR="public"
# Create the deploy directory if it doesn't exist
mkdir -p "${OUTPUT_DIR}/${DEPLOY_PATH}"
# Copy all repository files to the appropriate subfolder
cp -r ./* "${OUTPUT_DIR}/${DEPLOY_PATH}/"
# Initialize a temporary Git repo in the output directory
cd $OUTPUT_DIR
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Deploy to GitHub Pages - $DEPLOY_PATH"
git push -f "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:gh-pages