Skip to content

Update templates for Hugo #229

Update templates for Hugo

Update templates for Hugo #229

# Main Workflow
# Trigger on every commit to staging
name: Action on push to staging
on:
push:
branches:
- staging
pull_request:
branches:
- staging
workflow_dispatch:
jobs:
sync-branches:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all branches
- name: Configure Git
run: |
git config user.name "1bl4z3r"
git config user.email "[email protected]"
- name: Setup branches and directories
run: |
# Ensure we have the latest from both branches
git fetch origin staging
git fetch origin main
# Create temp directory to store files
mkdir -p /tmp/staging_files
- name: Checkout staging and capture commit message
run: |
# Switch to staging branch
git checkout staging || git checkout -b staging origin/staging
git pull origin staging
# Get the latest commit message from staging branch
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
# Generate file list from staging
find . -type f | grep -v 'resources\|git\|static\|content\|public\|hugo.toml$\|assets/custom\|assets/images\|928-600x400.jpg\|images/favicon.svg\|hugo_build.lock\|i18n\|hermit.webp\|gitignore' > /tmp/staging_files/staging_files.txt
echo "Files to sync from staging to main:"
cat /tmp/staging_files/staging_files.txt
- name: Checkout main and generate file list
run: |
# Switch to main branch
git checkout main || git checkout -b main origin/main
git pull origin main
# Generate file list from main
find . -type f | grep -v 'resources\|git\|static\|content\|public\|hugo.toml$\|assets/custom\|assets/images\|928-600x400.jpg\|images/favicon.svg\|hugo_build.lock\|i18n\|hermit.webp\|gitignore' > /tmp/staging_files/main_files.txt
- name: Sync changes to main branch
run: |
# Get lists of files
STAGING_FILES=$(cat /tmp/staging_files/staging_files.txt)
MAIN_FILES=$(cat /tmp/staging_files/main_files.txt)
# 1 & 2. Copy/create files from staging that should be synced
for file in $STAGING_FILES; do
# Create directory if it doesn't exist
mkdir -p $(dirname "$file")
# Copy the file from staging branch
git checkout staging -- "$file"
echo "Copied/updated: $file"
done
# 3. Delete files that exist in main but not in staging
for file in $MAIN_FILES; do
if ! grep -q "^$file$" /tmp/staging_files/staging_files.txt; then
git rm -f "$file" || echo "Could not remove $file"
echo "Deleted: $file"
fi
done
# Commit changes if any
if git status --porcelain | grep .; then
git add --all
git commit -m "${{ env.COMMIT_MESSAGE || 'Sync changes from staging to main' }}"
# Push changes to main
git push origin main
echo "Changes synced from staging to main"
else
echo "No changes to sync"
fi
- name: Clean up
if: always()
run: |
rm -rf /tmp/staging_files
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
build-and-deploy-site:
name: Build and Deploy Hugo
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: 'latest'
extended: true
- name: Build site with Hugo
run: hugo --minify --noBuildLock --ignoreCache --gc --logLevel debug && cp public/en/404.html public/404.html
- name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/staging'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
publish_branch: gh-pages