Repository navigation
77 lines (75 loc) · 2.54 KB
/
Copy pathdocs.yaml
File metadata and controls
77 lines (75 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Docs
on:
push:
branches:
- main
paths:
- modules/**
- hosts/**
- lib/docs/**
- users.nix
- flake.nix
- flake.lock
- .github/workflows/docs.yaml
pull_request:
paths:
- modules/**
- hosts/**
- lib/docs/**
- users.nix
- flake.nix
- flake.lock
- .github/workflows/docs.yaml
workflow_dispatch:
jobs:
generate:
runs-on: ubuntu-24.04
# Forked PRs can't be pushed to with the workflow token.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: write
pull-requests: write
id-token: write
env:
GH_TOKEN: ${{ github.token }}
BASE: ${{ github.ref_name }}
BRANCH: docs/${{ github.ref_name }}
HEAD_REF: ${{ github.head_ref }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}
- uses: DeterminateSystems/nix-installer-action@v22
- run: nix run .#docs
- name: Commit updated docs to the PR branch
if: github.event_name == 'pull_request'
run: |
if [[ -z $(git status --porcelain docs/) ]]; then
echo "docs/ is up to date."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add docs/
git commit -m "docs: regenerate [skip ci]"
git push origin HEAD:"$HEAD_REF"
- name: Create or update docs PR
if: github.event_name != 'pull_request'
run: |
if [[ -z $(git status --porcelain docs/) ]]; then
echo "docs/ is up to date."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$BRANCH"
git add docs/
git commit -m "docs: regenerate [skip ci]"
git push --force origin "$BRANCH"
if [[ -z $(gh pr list --head "$BRANCH" --base "$BASE" --state open --json number --jq '.[].number') ]]; then
gh pr create --head "$BRANCH" --base "$BASE" \
--title "docs: regenerate ($BASE)" \
--body "Auto-generated by \`nix run .#docs\`. Triggered by ${{ github.event_name }} on \`$BASE\`."
else
echo "PR already open for $BRANCH -> $BASE; branch updated."
fi