Skip to content

Build and Deploy

Build and Deploy #100

Workflow file for this run

# 🧠 Thought process:
# This workflow builds and deploys the website and CV.
# - On push to main: build only, no deploy
# - On release tag: build (if artifact is not present) and deploy both
# - Using composite action to avoid code duplication
name: Build and Deploy
on:
push:
branches:
- main
release:
types: [created]
workflow_dispatch:
# Cancel any previous workflow.
# This can happen when we merge a PR that triggers a new release
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pages: write
id-token: write
jobs:
build-web:
if: >
(github.event_name == 'release' && github.event.action == 'created' ) ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main')) ||
(github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
outputs:
neovim-lines: ${{ steps.lines.outputs.count }}
steps:
- uses: actions/checkout@v4
- name: Checkout NeoVim config
uses: actions/checkout@v4
with:
repository: 'c3n21/nvim-configuration'
path: './neovim_config'
- id: lines
name: Calculate total lines in NeoVim config
run: |
COUNT=$(find . -path './.git*' -prune -o -type f -exec wc -l {} \; | awk '{sum+=$1} END {print sum}')
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
echo "NEOVIM_CONFIG_LINES=$COUNT" >> "$GITHUB_ENV"
working-directory: './neovim_config'
- name: Set CV_LOCATION environment variable
run: |
TAG_NAME=${GITHUB_REF_NAME#refs/tags/}
PDF_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG_NAME}/cv.pdf"
echo "CV_LOCATION=$PDF_URL" >> $GITHUB_ENV
- uses: ./.github/actions/build-with-cv
with:
cv: ${{ secrets.CV }}
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./dist/
build-cv:
if: >
(github.event_name == 'release' && github.event.action == 'created' ) ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main')) ||
(github.event_name == 'workflow_dispatch')
needs: build-web # leverage pnpm cache reuse
runs-on: ubuntu-latest
env:
GITHUB_RUN_NUMBER: ${{ github.run_number }}
NEOVIM_CONFIG_LINES: ${{ needs.build-web.outputs.neovim-lines }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.local/share/pnpm/store/v3
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-
- uses: ./.github/actions/build-with-cv
with:
cv: ${{ secrets.CV }}
env:
CV: dark
- name: Install chrome for Puppeteer
run: |
sudo npx puppeteer browsers install chrome --install-deps
- name: Generate PDF from built site
run: |
pnpm run export-pdf
- name: Upload CV Artifact
uses: actions/upload-artifact@v4
with:
name: cv
path: ./cv.pdf
deploy-cv:
if: github.event_name == 'release' && github.event.action == 'created' || github.event_name == 'workflow_dispatch'
needs: build-cv
runs-on: ubuntu-latest
env:
GITHUB_RUN_NUMBER: ${{ github.run_number }}
NEOVIM_CONFIG_LINES: ${{ needs.build-web.outputs.neovim-lines }}
steps:
- name: Download CV Artifact
uses: actions/download-artifact@v4
with:
name: cv
path: ./cv.pdf
- name: Upload PDF as Release Asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
files: ./cv.pdf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy-web:
if: github.event_name == 'release' && github.event.action == 'created' || github.event_name == 'workflow_dispatch'
needs: build-web
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4