Skip to content

Merge branch 'refs/heads/fixes' into staging #379

Merge branch 'refs/heads/fixes' into staging

Merge branch 'refs/heads/fixes' into staging #379

Workflow file for this run

name: Deploy Hugo site to Pages
on:
push:
branches: ["main", "staging"]
# Standard permissions required for GitHub Pages deployment.
permissions:
contents: read
pages: write
id-token: write
# Environment variables accessible to all jobs and steps.
env:
HUGO_ENV: production
HUGO_VERSION: "0.147.7"
GO_VERSION: "1.24.3"
NODE_VERSION: "22.x"
jobs:
build:
runs-on: ubuntu-24.04
steps:
# 1. Prepare the environment by checking out code and setting up tools.
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # Needed for Hugo's .Lastmod feature
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: ${{ env.HUGO_VERSION }}
extended: true
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true # Enable Go module caching
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm' # Enable caching for npm dependencies
- name: Install npm dependencies
run: npm ci
# 2. Configure GitHub Pages deployment target.
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
# 3. Cache and run pre-build scripts to generate dynamic content.
- name: Cache and Restore OG Images
uses: actions/cache@v4
with:
path: |
content/**/*-og-*.jpg
static/images/og-image-*.jpg
tmp/og-cache-manifest.json
key: ${{ runner.os }}-og-images-${{ hashFiles('**/content/**/index.md', '**/content/**/_index.md', 'assets/og-template/**', 'scripts/**') }}
restore-keys: |
${{ runner.os }}-og-images-
- name: Generate OG Images
run: npm run og-images
- name: Fetch GitHub Stars
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run fetch-stars
- name: Update Mission Board
env:
PAT_FOR_ISSUES: ${{ secrets.PAT_FOR_ISSUES }}
run: npm run update-mission-board
continue-on-error: true
# 4. Dynamically configure the site's baseURL based on the deployment branch.
- name: Determine Base URL
id: base_url
run: |
if [[ "${{ github.repository }}" == "open-neuromorphic/open-neuromorphic.github.io" && "${{ github.ref_name }}" == "main" ]]; then
BASE_URL="https://open-neuromorphic.org/"
elif [[ "${{ github.repository }}" == "open-neuromorphic/open-neuromorphic.github.io" && "${{ github.ref_name }}" == "staging" ]]; then
BASE_URL="https://open-neuromorphic.github.io/staging-preview/"
else
# Fallback for forks or other branches to prevent broken links.
REPO_NAME=$(echo "${{ github.repository }}" | cut -d '/' -f 2)
BASE_URL="https://${{ github.repository_owner }}.github.io/${REPO_NAME}/"
fi
echo "BASE_URL=${BASE_URL}" >> $GITHUB_ENV
echo "Determined baseURL: ${BASE_URL}"
- name: Modify hugo.toml for deployment
run: |
echo "Setting baseURL to ${{ env.BASE_URL }} in hugo.toml"
# Use '|' as a sed delimiter to avoid conflicts with slashes in the URL.
sed -i "s|^baseURL = .*|baseURL = \"${{ env.BASE_URL }}\"|" hugo.toml
echo "--- hugo.toml after modification ---"
cat hugo.toml
echo "------------------------------------"
# 5. Build the static site.
- name: Build Hugo Site
run: npm run hugo-build
# 6. Prepare deployment artifacts, including SEO configurations for non-production sites.
- name: Create .htaccess from template
run: |
cat .github/config/htaccess.template > public/.htaccess
echo ".htaccess created."
- name: Prevent Indexing on Non-Production Deployments
if: env.BASE_URL != 'https://open-neuromorphic.org/'
run: |
echo "Applying noindex rules for baseURL: ${{ env.BASE_URL }}"
# Modify .htaccess to add a noindex header
echo "" >> public/.htaccess
echo "# Rules to prevent indexing on non-production deployments" >> public/.htaccess
echo "Header set X-Robots-Tag \"noindex, nofollow\"" >> public/.htaccess
# Create robots.txt to disallow all crawlers
echo "User-agent: *" > public/robots.txt
echo "Disallow: /" >> public/robots.txt
echo "--- .htaccess final content ---"
cat public/.htaccess
echo "--- robots.txt content ---"
cat public/robots.txt
# 7. Upload the prepared static site as an artifact for the deploy job.
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
# --- DEPLOYMENT JOB ---
# This job runs after the build job is successful.
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-24.04
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4