Skip to content

Simplify GitHub Actions workflow for static assets #17

Simplify GitHub Actions workflow for static assets

Simplify GitHub Actions workflow for static assets #17

Workflow file for this run

name: Deploy to GitHub Pages
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.15.7'
otp-version: '26.2.1'
- name: Restore dependencies
run: |
mix local.hex --force
mix local.rebar --force
mix deps.get
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: 'assets/package-lock.json'
- name: Install Node.js dependencies
working-directory: ./assets
run: |
npm ci --prefer-offline --no-audit
npm install esbuild@0.17.11
- name: Build assets
run: |
# Create necessary directories
mkdir -p priv/static/images
mkdir -p priv/static/assets
# Copy static assets
cp -r priv/static/images/* priv/static/images/ 2>/dev/null || true
cp -r assets/static/* priv/static/ 2>/dev/null || true
# Build and digest assets
mix assets.deploy
mix phx.digest
# Copy the HTML files from lib/kati_portfolio_web/controllers/page_html
cp lib/kati_portfolio_web/controllers/page_html/*.html.heex priv/static/
# Ensure CNAME is present
echo "katibestdesign.com" > priv/static/CNAME
# Create a 404.html for GitHub Pages
echo '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Page Not Found</title></head><body><h1>404 - Page Not Found</h1><p>The page you are looking for does not exist.</p></body></html>' > priv/static/404.html
# Create a _redirects file for Netlify-style redirects
echo "/images/* /images/:splat 200" > priv/static/_redirects
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./priv/static
force_orphan: true