name: Lint, build, test and deploy on: push: branches: [master] workflow_dispatch: jobs: # ------------------------------------------------------------ build # Single dependency install serves both the lint check and the build. # Lint failures fail this job, which gates test and deploy. 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: Lint Markdown run: npx markdownlint-cli2 - name: Build site run: hexo generate # Best-effort image optimization at build time: originals in source/ # stay untouched, only the built artifact shrinks (~56% on this site). # Note: oxipng is not packaged in the runner's Ubuntu apt repos; pngquant # provides nearly all of the savings on its own. - name: Optimize images run: | apt-get update -qq && apt-get install -y -qq pngquant jpegoptim find public -type f -name '*.png' -exec sh -c 'pngquant --quality=80-95 --strip --force --skip-if-larger --output "$1" "$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: 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 "