1+ name : Generate go-docs
2+
3+ on :
4+ pull_request :
5+ types :
6+ - labeled
7+ - reopened
8+ - synchronize
9+
10+ jobs :
11+ generate_docs_new_pr :
12+ name : Generate Go Docs
13+ if : ${{ contains(github.event.pull_request.labels.*.name, 'generate_go_docs') }}
14+ runs-on : ubuntu-latest
15+ environment : integration
16+ permissions :
17+ id-token : write
18+ contents : read
19+
20+ steps :
21+ - name : Setup GitHub Token for reading Generate Go Doc Repo
22+ id : setup-github-token-read
23+ uses :
smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected] 24+ with :
25+ aws-role-arn : ${{ secrets.AWS_ROLE_ARN_READ_GENERATE_GO_DOC_REPO }}
26+ aws-lambda-url : ${{ secrets.GATI_LAMBDA_TT_URL }}
27+ aws-region : ${{ secrets.AWS_REGION }}
28+
29+ - name : Configure git for private repository and install go tools
30+ env :
31+ GOPRIVATE : github.com/smartcontractkit/generate-go-function-docs
32+ run : |
33+ git config --global url."https://x-access-token:${{ steps.setup-github-token-read.outputs.access-token }}@github.com/".insteadOf "https://github.com/"
34+ go install github.com/smartcontractkit/[email protected] 35+ go install github.com/jmank88/[email protected] 36+ go install golang.org/x/tools/gopls@latest
37+
38+ - name : Checkout current branch
39+ uses : actions/checkout@v3
40+ with :
41+ fetch-depth : 0
42+
43+ - name : Detect changes related to current PR
44+ uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
45+ id : changes
46+ with :
47+ filters : |
48+ seth:
49+ - 'seth/**/*.go'
50+ wasp:
51+ - 'wasp/**/*.go'
52+ havoc:
53+ - 'havoc/**/*.go'
54+ lib:
55+ - 'lib/**/*.go'
56+ k8s-test-runner:
57+ - 'k8s-test-runner/**/*.go'
58+ framework:
59+ - 'framework/**/*.go'
60+ tools/asciitable:
61+ - 'tools/asciitable/**/*.go'
62+ tools/breakingchanges:
63+ - 'tools/breakingchanges/**/*.go'
64+ tools/citool:
65+ - 'tools/citool/**/*.go'
66+ tools/ecrimagefetcher:
67+ - 'tools/ecrimagefetcher/**/*.go'
68+ tools/envresolve:
69+ - 'tools/envresolve/**/*.go'
70+ tools/flakeguard:
71+ - 'tools/flakeguard/**/*.go'
72+ tools/ghlatestreleasechecker:
73+ - 'tools/ghlatestreleasechecker/**/*.go'
74+ tools/ghsecrets:
75+ - 'tools/ghsecrets/**/*.go'
76+ tools/gotestloghelper:
77+ - 'tools/gotestloghelper/**/*.go'
78+ tools/testlistgenerator:
79+ - 'tools/testlistgenerator/**/*.go'
80+ tools/workflowresultparser:
81+ - 'tools/workflowresultparser/**/*.go'
82+ # add more projects here
83+
84+ - name : Find all go modules in the repository and filter the ones that changed
85+ shell : bash
86+ id : go-modules
87+ env :
88+ FILTERS : ${{ steps.changes.outputs.changes }}
89+ run : |
90+ PATH=$PATH:$(go env GOPATH)/bin
91+ export PATH
92+
93+ # Find all go projects
94+ gomods_output=$(gomods 2>&1)
95+
96+ # Extract the parent directories of go.mod files
97+ parent_folders=$(echo "$gomods_output" | grep 'go\.mod$' | sed 's/\/go\.mod//' | sed 's/^[ \t]*//;s/[ \t]*$//' | xargs -n 1)
98+
99+ # Convert parent directories into a JSON matrix
100+ echo "$parent_folders" | jq -R -s 'split("\n") | map(select(length > 0)) | map({folder: .})' > all_folders.json
101+
102+ # Filter the directories that did not changeß
103+ jq --argjson filters "$FILTERS" 'map(select(.folder as $folder | $filters | index($folder)))' all_folders.json > filtered_folders.json
104+
105+ echo "Filtered folder List JSON"
106+ cat filtered_folders.json
107+
108+ rm all_folders.json
109+
110+ - name : Generate go docs for changed projects
111+ shell : bash
112+ env :
113+ OPENAI_API_KEY : ${{ secrets.OPENAI_DOC_GEN_API_KEY }}
114+ run : |
115+ # Add go binary to PATH
116+ PATH=$PATH:$(go env GOPATH)/bin
117+ export PATH
118+ cat filtered_folders.json | jq -c '.[]' | while read -r item; do
119+ folder=$(echo "$item" | jq -r '.folder')
120+ echo "Processing folder: $folder"
121+ generate-go-function-docs diff -b ${{ github.event.pull_request.base.sha }} -c ${{ github.event.pull_request.head.sha }} --saveCosts --generator chatgpt --generatorSubType ${{ vars.GO_DOC_GEN_CHATGPT_MODEL }} --folder "$folder"
122+ done
123+ rm filtered_folders.json
124+
125+ - name : Upload costs as artifact
126+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
127+ with :
128+ name : generation-costs
129+ path : ./costs
130+
131+ - name : Remove costs before committing
132+ shell : bash
133+ run : rm -rf costs
134+
135+ - name : Setup GitHub Token for creating a new PR
136+ id : setup-github-token-write
137+ uses :
smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected] 138+ with :
139+ aws-role-arn : ${{ secrets.AWS_ROLE_ARN_CREATE_PR }}
140+ aws-lambda-url : ${{ secrets.GATI_LAMBDA_TT_URL }}
141+ aws-region : ${{ secrets.AWS_REGION }}
142+
143+ - name : Create a new PR targeting current PR
144+ uses : peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
145+ id : create-pr
146+ with :
147+ token : ${{ steps.setup-github-token-write.outputs.access-token }}
148+ branch : ${{ github.head_ref }}-docs
149+ base : ${{ github.head_ref }}
150+ title : " Go docs for PR#${{ github.event.pull_request.number }}"
151+ body : " This PR contains automatically generated go documentation for the PR#${{ github.event.pull_request.number }}. Please review the changes."
152+ commit-message : " [Bot] Add automatically generated go documentation"
153+
154+ - name : Find comment with PR link
155+ uses : peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
156+ id : fc
157+ with :
158+ issue-number : ${{ github.event.pull_request.number }}
159+ body-includes : Go doc generation
160+
161+ - name : Create comment in the original PR with link to the new PR
162+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
163+ if : steps.create-pr.outputs.pull-request-number != ''
164+ with :
165+ token : ${{ steps.setup-github-token-write.outputs.access-token }}
166+ issue-number : ${{ github.event.pull_request.number }}
167+ comment-id : ${{ steps.fc.outputs.comment-id }}
168+ edit-mode : replace
169+ body : |
170+ ## Go doc generation
171+ Hey @${{ github.actor }}, you can check generated Go function documentation [here](${{ steps.create-pr.outputs.pull-request-url }}). Please review them and merge to this PR once you're satisfied with them.
172+
173+ - name : Create comment in the original PR to notify about no new docs
174+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
175+ if : steps.create-pr.outputs.pull-request-number == ''
176+ with :
177+ token : ${{ steps.setup-github-token-write.outputs.access-token }}
178+ issue-number : ${{ github.event.pull_request.number }}
179+ comment-id : ${{ steps.fc.outputs.comment-id }}
180+ edit-mode : replace
181+ body : |
182+ ## Go doc generation
183+ Hey @${{ github.actor }}, no documentation was generated. Are you sure that you made changes to public functions without existing comments in your PR?
184+
185+ - name : Send Slack notification
186+ uses : slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 # v1.25.0
187+ if : failure()
188+ id : slack
189+ env :
190+ SLACK_BOT_TOKEN : ${{ secrets.QA_SLACK_API_KEY }}
191+ with :
192+ channel-id : ' C049X3353K2'
193+ payload : |
194+ {
195+ "attachments": [
196+ {
197+ "color": "#C62828",
198+ "blocks": [
199+ {
200+ "type": "section",
201+ "text": {
202+ "type": "mrkdwn",
203+ "text": "Go doc generation - Failed :x:"
204+ }
205+ },
206+ {
207+ "type": "section",
208+ "text": {
209+ "type": "mrkdwn",
210+ "text": "<@U060CGGPY8H>, please have a look."
211+ }
212+ },
213+ {
214+ "type": "section",
215+ "text": {
216+ "type": "mrkdwn",
217+ "text": "<${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.pull_request.number }}|PR#${{ github.event.pull_request.number }}> | <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run Details>"
218+ }
219+ }
220+ ]
221+ }
222+ ]
223+ }
0 commit comments