Skip to content

Commit 8ca52b0

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

File tree

2 files changed

+123
-72
lines changed

2 files changed

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

.github/workflows/check.yml

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

0 commit comments

Comments
 (0)