feat: implement GitHub Actions workflow for automated deployment to G… #1
This file contains hidden or 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: Deploy to GitHub Pages | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment per environment | |
concurrency: | |
group: "pages-${{ github.ref_name }}" | |
cancel-in-progress: false | |
jobs: | |
# Build job | |
build: | |
runs-on: ubuntu-latest | |
env: | |
HUGO_VERSION: 0.128.0 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v3 | |
with: | |
hugo-version: '${{ env.HUGO_VERSION }}' | |
extended: true | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Load environment variables (Production) | |
if: github.ref == 'refs/heads/main' | |
run: | | |
if [ -f config/deploy-prod.env ]; then | |
echo "Loading production environment..." | |
export $(grep -v '^#' config/deploy-prod.env | xargs) | |
echo "BASE_URL=${BASE_URL}" >> $GITHUB_ENV | |
echo "HUGO_ENVIRONMENT=${HUGO_ENVIRONMENT}" >> $GITHUB_ENV | |
fi | |
- name: Load environment variables (Staging) | |
if: github.ref == 'refs/heads/develop' | |
run: | | |
if [ -f config/deploy-staging.env ]; then | |
echo "Loading staging environment..." | |
export $(grep -v '^#' config/deploy-staging.env | xargs) | |
echo "BASE_URL=${BASE_URL}" >> $GITHUB_ENV | |
echo "HUGO_ENVIRONMENT=${HUGO_ENVIRONMENT}" >> $GITHUB_ENV | |
fi | |
- name: Generate CDN Headers | |
run: npm run headers | |
- name: Build with Hugo (Production) | |
if: github.ref == 'refs/heads/main' | |
run: | | |
hugo \ | |
--gc \ | |
--minify \ | |
--baseURL "${{ env.BASE_URL }}" \ | |
--environment "${{ env.HUGO_ENVIRONMENT }}" | |
- name: Build with Hugo (Staging) | |
if: github.ref == 'refs/heads/develop' | |
run: | | |
hugo \ | |
--minify \ | |
--baseURL "${{ env.BASE_URL }}" \ | |
--environment "${{ env.HUGO_ENVIRONMENT }}" | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./public | |
# Deployment job for Production | |
deploy-production: | |
if: github.ref == 'refs/heads/main' | |
environment: | |
name: production | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
# Deployment job for Staging | |
deploy-staging: | |
if: github.ref == 'refs/heads/develop' | |
environment: | |
name: staging | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |