Update static-deployment.yml #4
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
# .github/workflows/deploy-to-pages.yml | |
name: Deploy to GitHub Pages | |
on: | |
push: | |
branches: | |
- '**' # Triggers on all branches | |
release: | |
types: | |
- created # Triggers 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: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: npm install | |
- name: Build project | |
run: npm run build | |
- name: Deploy to GitHub Pages | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Get branch or tag name | |
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 deploy directory if it doesn't exist | |
mkdir -p "${OUTPUT_DIR}/${DEPLOY_PATH}" | |
# Copy build files to the appropriate subfolder | |
cp -r ./dist/* "${OUTPUT_DIR}/${DEPLOY_PATH}/" | |
# Initialize a temporary Git repo to push to Pages | |
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 |