name: Lint, build, test and deploy on: push: branches: [master] workflow_dispatch: jobs: # ------------------------------------------------------------ style checks # Runs in parallel with build; both must pass before the site is tested. lint: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: '22' - name: Install dependencies run: yarn install --frozen-lockfile - name: Lint Markdown run: npx markdownlint-cli2 # ------------------------------------------------------------ build # Produces the static site once and shares it as an artifact so the # test and deploy stages never rebuild. build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: '22' - name: Install hexo-cli run: npm install -g hexo-cli - name: Install dependencies run: yarn install --frozen-lockfile - name: Build site run: hexo generate # Best-effort image optimization at build time: originals in source/ # stay untouched, only the built artifact shrinks (~58% on this site). - name: Optimize images run: | apt-get update -qq && apt-get install -y -qq pngquant oxipng jpegoptim find public -type f -name '*.png' -exec sh -c 'pngquant --quality=80-95 --strip --force --skip-if-larger --output "$1" "$1"; oxipng -o max -q "$1"' _ {} \; find public -type f \( -name '*.jpg' -o -name '*.jpeg' \) -exec jpegoptim --max=90 --strip-all --threshold=5 -q {} \; echo "site size after optimization: $(du -sh public | cut -f1)" - name: Upload site artifact uses: actions/upload-artifact@v4 with: name: site path: public/ # ------------------------------------------------------------ test # Validates the built site locally. Never touches production. Deploy # physically cannot run unless this job passes. test: needs: [lint, build] runs-on: ubuntu-latest steps: - name: Download site artifact uses: actions/download-artifact@v4 with: name: site path: public - name: Structural checks run: | test -f public/index.html test "$(find public -type f | wc -l)" -gt 100 test -f public/css/index.css test -f public/js/utils.js grep -q "