Skip to content

Merge remote-tracking branch 'origin/main' #95

Merge remote-tracking branch 'origin/main'

Merge remote-tracking branch 'origin/main' #95

Workflow file for this run

name: Deploy Hugo site to Pages
on:
push:
branches: ["main", "cache-images"]
permissions:
contents: read
pages: write
id-token: write
env:
HUGO_ENV: production
HUGO_VERSION: "0.147.7"
GO_VERSION: "1.24.3"
NODE_VERSION: "22.x" # Use major version for setup-node
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Install Hugo
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Go
run: |
wget -O ${{ runner.temp }}/go.tar.gz https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz \
&& sudo tar -C /usr/local -xzf ${{ runner.temp }}/go.tar.gz \
&& sudo ln -s /usr/local/go/bin/go /usr/local/bin/go
- name: Checkout
uses: actions/checkout@v4.2.2
with:
submodules: recursive
fetch-depth: 0
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install npm dependencies
run: npm ci
- name: Cache and Restore OG Images
uses: actions/cache@v4
id: og-cache
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/template.html', 'assets/images/ONM-logo.png') }}
restore-keys: |
${{ runner.os }}-og-images-
- name: Generate OG Images
run: npm run og-images
- name: Determine Base URL
id: base_url
run: |
if [[ "${{ github.repository_owner }}.github.io" == "open-neuromorphic.github.io" && "${{ github.ref_name }}" == "main" ]]; then
BASE_URL="https://open-neuromorphic.org/"
elif [[ "${{ github.repository_owner }}.github.io" == "open-neuromorphic.github.io" && "${{ github.ref_name }}" == "refactor" ]]; then
BASE_URL="https://open-neuromorphic.github.io/refactor-preview/" # Example preview URL
else
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 BASE_URL: $BASE_URL"
- name: Modify hugo.toml
run: |
echo "Attempting to set baseURL to $BASE_URL in hugo.toml"
sed -i "s|baseURL = .*|baseURL = \"$BASE_URL\"|" hugo.toml
echo "hugo.toml after modification:"
cat hugo.toml
- name: Build Hugo Site
run: |
echo "Starting Hugo site build..."
npm run hugo-build
echo "Hugo site build completed."
echo "Contents of public directory after build:"
ls -la public
- name: Create and Populate .htaccess
run: |
echo "Creating and populating .htaccess in public directory"
mkdir -p public
cat .github/config/htaccess.template > public/.htaccess
echo ".htaccess created and populated."
echo "Contents of public/.htaccess:"
cat public/.htaccess
- name: Modify .htaccess (Prevent Indexing if not production Open Neuromorphic)
run: |
echo "Current BASE_URL for .htaccess modification: $BASE_URL"
if [[ "$BASE_URL" != "https://open-neuromorphic.org/" ]]; then
echo "Modifying .htaccess to prevent indexing for $BASE_URL"
chmod u+w public/.htaccess
echo "" >> public/.htaccess
echo "# Rules to prevent indexing on non-production deployments" >> public/.htaccess
echo "Header set X-Robots-Tag \"noindex, nofollow\"" >> public/.htaccess
echo ".htaccess modified."
echo "Final contents of public/.htaccess:"
cat public/.htaccess
else
echo ".htaccess modification skipped for production URL."
fi
- name: Create robots.txt (Prevent Indexing if not production)
run: |
echo "Current BASE_URL for robots.txt creation: $BASE_URL"
if [[ "$BASE_URL" != "https://open-neuromorphic.org/" ]]; then
echo "Creating robots.txt to prevent indexing for $BASE_URL"
echo "User-agent: *" > public/robots.txt
echo "Disallow: /" >> public/robots.txt
echo "robots.txt created."
echo "Contents of public/robots.txt:"
cat public/robots.txt
else
echo "robots.txt creation skipped for production URL."
fi
- name: Upload artifact
uses: actions/upload-pages-artifact@v3.0.1
with:
path: ./public
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.0.5