Skip to content

Commit 20f2143

Browse files
committed
run doc generation for all go modules
1 parent ce1b5b6 commit 20f2143

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

.github/workflows/generate-go-docs.yaml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ on:
99

1010
jobs:
1111
generate_docs_new_pr:
12-
if: ${{ contains(github.event.pull_request.labels.*.name, 'generate_go_docs') }}
12+
if: ${{ contains(github.event.pull_request.labels.*.name, 'generate_go_docs') }}
1313
runs-on: ubuntu-latest
1414
permissions:
1515
id-token: write
16-
contents: read
16+
contents: read
1717

1818
steps:
1919
- name: Setup GitHub Token for reading Generate Go Doc Repo
@@ -24,42 +24,55 @@ jobs:
2424
aws-lambda-url: ${{ secrets.GATI_LAMBDA_TT_URL }}
2525
aws-region: ${{ secrets.AWS_REGION }}
2626

27-
- name: Configure git for private repository and install go doc generator
27+
- name: Configure git for private repository and install go tools
2828
env:
2929
GOPRIVATE: github.com/smartcontractkit/generate-go-function-docs
3030
run: |
3131
git config --global \
3232
url."https://x-access-token:${{ steps.setup-github-token-read.outputs.access-token }}@github.com/".insteadOf "https://github.com/"
3333
go install github.com/smartcontractkit/generate-go-function-docs@latest
34-
35-
- name: Install gopls
36-
shell: bash
37-
run: |
38-
go install golang.org/x/tools/gopls@latest
34+
go install github.com/jmank88/[email protected]
35+
go install golang.org/x/tools/gopls@latest
3936
4037
- name: Checkout current branch
4138
uses: actions/checkout@v3
4239
with:
43-
fetch-depth: 0
40+
fetch-depth: 0
41+
42+
- name: Find all go modules
43+
shell: bash
44+
id: go-modules
45+
run: |
46+
PATH=$PATH:$(go env GOPATH)/bin
47+
export PATH
48+
gomods_output=$(gomods 2>&1)
49+
50+
# Extract the parent directories of go.mod files
51+
parent_folders=$(echo "$gomods_output" | grep 'go\.mod$' | sed 's/\/go\.mod//' | sed 's/^[ \t]*//;s/[ \t]*$//' | xargs -n 1)
52+
53+
# Convert parent directories into a JSON matrix
54+
echo "$parent_folders" | jq -R -s 'split("\n") | map(select(length > 0)) | map({folder: .})' > folders.json
4455
45-
- name: Generate go docs
56+
echo "Folder List JSON"
57+
cat folders.json
58+
59+
- name: Generate go docs for all projects
4660
shell: bash
4761
env:
4862
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
4963
run: |
5064
# Add go binary to PATH
5165
PATH=$PATH:$(go env GOPATH)/bin
5266
export PATH
53-
# TODO check why this flag is needed, if it has a default!
54-
# TODO we need a way to determine which modules have changes and run this command for all of them
55-
generate-go-function-docs diff -b ${{ github.event.pull_request.base.sha }} -c ${{ github.event.pull_request.head.sha }} -g chatgpt -f ./seth --goModLocation ./seth/go.mod
56-
57-
- name: Make sure code still compiles
58-
run: |
59-
# TODO we need a way to determine which modules have changes and run this command for all of them
60-
cd seth
61-
go mod tidy
62-
go build ./...
67+
cat folders.json | jq -c '.[]' | while read -r item; do
68+
folder=$(echo "$item" | jq -r '.folder')
69+
echo "Processing folder: $folder"
70+
generate-go-function-docs diff -b ${{ github.event.pull_request.base.sha }} -c ${{ github.event.pull_request.head.sha }} -g chatgpt -f "$folder"
71+
cd "$folder"
72+
echo "Checking if code still compiles"
73+
go build ./...
74+
cd -
75+
done
6376
6477
- name: Setup GitHub Token for creating a new PR
6578
id: setup-github-token-write

0 commit comments

Comments
 (0)