chore: workflow - Run link checker on commit message trigger [link-ch… #84
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 Hugo site to Pages | |
on: | |
push: | |
branches: ["main", "cache-images"] | |
pull_request: # Add this to run on pull requests | |
branches: ["main"] | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
issues: write # Add this permission for creating issues | |
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 | |
link-checker: | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.event_name == 'pull_request' || contains(github.event.head_commit.message, '[link-check]') | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: github-pages | |
path: ./public | |
- name: Restore lychee cache | |
uses: actions/cache@v4 | |
with: | |
path: ./.lycheecache | |
key: lychee-cache-${{ github.ref }} | |
restore-keys: | | |
lychee-cache- | |
- name: Link Checker | |
id: lychee | |
uses: lycheeverse/lychee-action@v2 | |
with: | |
# Check all HTML files in the downloaded public directory | |
args: >- | |
--cache | |
--max-cache-age 1d | |
--verbose | |
--exclude-mail | |
--exclude-all-private | |
--exclude 'https://www.linkedin.com/.*' | |
--exclude 'https://twitter.com/intent/.*' | |
--exclude 'https://github.com/open-neuromorphic/open-neuromorphic.github.io/issues/new/choose' | |
'./public/**/*.html' | |
fail: false # Do not fail the workflow, create an issue instead | |
job_summary: true | |
output: ./lychee-out.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Issue From File | |
if: steps.lychee.outputs.exit_code != 0 | |
uses: peter-evans/create-issue-from-file@v5 | |
with: | |
title: Link Checker Report | |
content-filepath: ./lychee-out.md | |
labels: report, automated, broken-links | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-24.04 | |
needs: build | |
# Only deploy on pushes to the main branch, not on pull requests | |
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/cache-images') | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4.0.5 |