feat: Add blog contribute CTA component #20
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", "design-adjustments"] | |
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: | |
# Switched to a standard x86_64 runner for better package compatibility | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Install Hugo | |
run: | | |
# Updated to use amd64 for the new runner | |
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: | | |
# Updated to use amd64 for the new runner | |
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: Install wkhtmltopdf | |
run: | | |
sudo apt update | |
sudo apt install wkhtmltopdf imagemagick -y | |
- name: Checkout | |
uses: actions/checkout@v4.2.2 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup Pages | |
id: pages | |
uses: actions/configure-pages@v5 | |
# Best practice: Use setup-node with caching | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: 'npm' | |
- name: Install npm dependencies | |
run: npm ci # Use npm ci for faster, more reliable CI builds | |
- 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) | |
# For forks or other repositories, adjust as needed | |
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 site | |
run: | | |
echo "Starting site build..." | |
npm run build | |
echo "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 }} | |
# Switched to a standard x86_64 runner for consistency | |
runs-on: ubuntu-24.04 | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4.0.5 |