ci: use Nix on CI #82
This file contains 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: "CI/CD" | |
"on": | |
pull_request: {} | |
push: | |
branches: ["**"] | |
tags: ["**"] | |
env: | |
DOCKER_BUILDKIT: 1 | |
defaults: | |
run: | |
# For the windows phase | |
shell: bash | |
jobs: | |
nix: | |
runs-on: ubuntu-latest | |
name: "Build using Nix" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- | |
name: Install Nix | |
uses: cachix/install-nix-action@v20 | |
with: | |
nix_path: nixpkgs=channel:nixos-unstable | |
- | |
name: Tangle code and export HTML | |
run: "nix build .#dist" | |
- | |
name: "Test: integration test" | |
run: nix flake check | |
- | |
name: "Test: vendored script equals build" | |
run: diff -u ./tomono result/bin/tomono | |
- | |
name: Create artifact bundle | |
run: | | |
(cd result/bin && tar cvf $OLDPWD/artifacts.tar tomono) | |
(cd result/doc && tar rvf $OLDPWD/artifacts.tar index.html style.css) | |
- | |
uses: actions/upload-artifact@v3 | |
with: | |
name: bundle-${{github.sha}} | |
path: artifacts.tar | |
docker: | |
timeout-minutes: 10 | |
name: "Build using Docker" | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- | |
name: Checkout | |
uses: actions/checkout@v2 | |
- # This is very wasteful but caching docker images on GH actions is | |
# INSANELY DIFFICULT!!! Honestly they bring it on themselves, this is | |
# not an abstruse setup. But until I can cache docker images (let alone | |
# layers), without pollution between branches / PRs, and without | |
# 1873907182301273 lines of code, config and separate auths and external | |
# services, I’ll just stick to rebuilding the entire image every time. | |
name: Build the Docker image | |
run: docker compose build | |
- | |
name: Tangle code and export HTML | |
run: docker compose run --rm build | |
deploy_pages: | |
timeout-minutes: 10 | |
if: ${{ github.ref_type == 'branch' && github.ref == 'refs/heads/master' }} | |
name: "Deploy the HTML to GitHub Pages" | |
runs-on: ubuntu-latest | |
needs: nix | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
ref: gh-pages | |
- name: Remove files before artifact download | |
run: rm -f artifacts.tar | |
- | |
uses: actions/download-artifact@v3 | |
with: | |
name: bundle-${{github.sha}} | |
- name: Unpack artifacts | |
run: | | |
tar xvf artifacts.tar index.html style.css | |
rm -f artifacts.tar | |
- | |
name: configure git | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "<>" | |
- | |
name: "Commit the HTML to gh-pages branch" | |
run: | | |
git add -A | |
git commit -m "Update gh-pages from ${{github.ref}} @ ${{github.sha}}" | |
git push origin gh-pages |