From 19e396413f8469ff3b3755e37c926048d896139f Mon Sep 17 00:00:00 2001 From: "Abdel @ StarkWare" Date: Mon, 2 Sep 2024 17:28:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20generate=20docs=20and=20deploy?= =?UTF-8?q?=20in=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check.yml | 2 +- .github/workflows/docs.yml | 55 +++++++++++++++++++++++++++++++++++++ build.zig | 10 +++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ee3f503..4eb5ce2 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -7,7 +7,7 @@ on: branches: [main] env: - ZIG_VERSION: 0.14.0-dev.1402+cad65307b + ZIG_VERSION: 0.14.0-dev.1409+6d2945f1f jobs: build: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..5aaaa3d --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,55 @@ +name: Generate and Deploy Docs + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: write-all + +env: + ZIG_VERSION: 0.14.0-dev.1409+6d2945f1f + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Cache Zig + uses: actions/cache@v3 + with: + path: ~/zig + key: ${{ runner.os }}-zig-${{ env.ZIG_VERSION }} + + - name: Install Zig + if: steps.cache.outputs.cache-hit != 'true' + run: | + wget https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz + tar -xf zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz + mv zig-linux-x86_64-${{ env.ZIG_VERSION }} ~/zig + + - name: Add Zig to PATH + run: echo "${HOME}/zig" >> $GITHUB_PATH + + - name: Cache Zig build artifacts + uses: actions/cache@v3 + with: + path: | + zig-cache + ~/.cache/zig + key: ${{ runner.os }}-zig-build-${{ hashFiles('**/*.zig') }} + restore-keys: | + ${{ runner.os }}-zig-build- + + - name: Build Docs + run: zig build docs + + - name: Deploy + if: ${{ github.ref == 'refs/heads/main' }} && steps.check_changes.outcome == 'success' + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: zig-out/docs diff --git a/build.zig b/build.zig index ccfa57f..82a799a 100644 --- a/build.zig +++ b/build.zig @@ -232,4 +232,14 @@ pub fn build(b: *std.Build) !void { const bench_step = b.step("bench", "Run benchmarks"); bench_step.dependOn(&run_bench.step); + + // Add documentation generation step + const install_docs = b.addInstallDirectory(.{ + .source_dir = lib.getEmittedDocs(), + .install_dir = .prefix, + .install_subdir = "docs", + }); + + const docs_step = b.step("docs", "Generate documentation"); + docs_step.dependOn(&install_docs.step); }