Skip to content

Commit b16e324

Browse files
virajbhartiyarvagg
authored andcommitted
feat(docs): add workflow to generate documentation on PR merge
1 parent 99dcb12 commit b16e324

File tree

2 files changed

+124
-72
lines changed

2 files changed

+124
-72
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Check and Generate
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
workflow_dispatch:
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
check-gen:
21+
name: Check (gen-check)
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.head_ref }}
27+
submodules: 'recursive'
28+
fetch-depth: 0
29+
- uses: ./.github/actions/install-system-dependencies
30+
- uses: ./.github/actions/install-go
31+
- uses: ./.github/actions/make-deps
32+
- run: make gen
33+
- run: git diff --exit-code
34+
check-lint:
35+
name: Check (lint-all)
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
with:
40+
submodules: 'recursive'
41+
fetch-depth: 0
42+
- uses: ./.github/actions/install-system-dependencies
43+
- uses: ./.github/actions/install-go
44+
- uses: ./.github/actions/make-deps
45+
- run: go install github.com/golangci/golangci-lint/cmd/[email protected]
46+
- run: golangci-lint run -v --timeout 10m --concurrency 4
47+
check-fmt:
48+
name: Check (gofmt)
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
submodules: 'recursive'
54+
fetch-depth: 0
55+
- uses: ./.github/actions/install-go
56+
- run: go fmt ./...
57+
- run: git diff --exit-code
58+
check-mod-tidy:
59+
name: Check (mod-tidy-check)
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v4
63+
with:
64+
submodules: 'recursive'
65+
fetch-depth: 0
66+
- uses: ./.github/actions/install-go
67+
- run: go mod tidy -v
68+
- run: git diff --exit-code
69+
generate-docs:
70+
name: Generate Documentation
71+
runs-on: ubuntu-latest
72+
permissions:
73+
contents: write
74+
steps:
75+
- uses: actions/checkout@v4
76+
with:
77+
submodules: 'recursive'
78+
fetch-depth: 0
79+
80+
- uses: ./.github/actions/install-system-dependencies
81+
- uses: ./.github/actions/install-go
82+
- uses: ./.github/actions/make-deps
83+
84+
- name: Generate API documentation using docsgen-cli
85+
run: |
86+
make docsgen-cli || {
87+
echo "Error: Documentation generation failed"
88+
exit 1
89+
}
90+
91+
- name: Check for documentation changes
92+
id: check_changes
93+
run: |
94+
if [ -n "$(git status --porcelain)" ]; then
95+
echo "::set-output name=changes::true"
96+
else
97+
echo "::set-output name=changes::false"
98+
fi
99+
100+
- name: Commit and push if documentation changed
101+
if: steps.check_changes.outputs.changes == 'true'
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
run: |
105+
# Bot email is configured from: https://github.com/orgs/community/discussions/26560
106+
git config user.name "github-actions[bot]"
107+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
108+
git commit -am "docs: update API documentation via docsgen-cli"
109+
REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.event.pull_request.head.repo.full_name }}"
110+
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
111+
git push $REPO_URL HEAD:$BRANCH_NAME
112+
113+
- name: Comment on the pull request
114+
if: steps.check_changes.outputs.changes == 'true'
115+
uses: actions/github-script@v6
116+
with:
117+
github-token: ${{ secrets.GITHUB_TOKEN }}
118+
script: |
119+
const comment = 'CLI documentation has been generated and pushed to the branch.';
120+
await github.issues.createComment({
121+
...context.repo,
122+
issue_number: context.payload.pull_request.number,
123+
body: comment
124+
});

.github/workflows/check.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)