Skip to content

Commit 018f62b

Browse files
authored
Merge 232edcb into f03577d
2 parents f03577d + 232edcb commit 018f62b

File tree

2 files changed

+70
-37
lines changed

2 files changed

+70
-37
lines changed

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

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,70 +9,99 @@ on:
99

1010
jobs:
1111
generate_docs_new_pr:
12-
if: ${{ contains(github.event.issue.labels.*.name, 'generate_go_docs') }}
12+
if: ${{ contains(github.event.pull_request.labels.*.name, 'generate_go_docs') }}
1313
runs-on: ubuntu-latest
1414
permissions:
15-
contents: read
16-
pull-requests: write
17-
repository-projects: read
15+
id-token: write
16+
contents: read
1817

1918
steps:
20-
- name: Checkout current branch
21-
uses: actions/checkout@v3
19+
- name: Setup GitHub Token for reading Generate Go Doc Repo
20+
id: setup-github-token-read
21+
uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected]
2222
with:
23-
fetch-depth: 0
24-
25-
- name: Setup Git
26-
run: |
27-
git config user.name "github-actions[bot]"
28-
git config user.email "github-actions[bot]@users.noreply.github.com"
29-
30-
- name: Get PR details
31-
id: pr-details
32-
run: |
33-
echo "pr_number=$(jq -r .pull_request.number <<< "$GITHUB_EVENT_PATH")" >> $GITHUB_OUTPUT
34-
echo "pr_branch=$(jq -r .pull_request.head.ref <<< "$GITHUB_EVENT_PATH")" >> $GITHUB_OUTPUT
35-
echo "base_commit=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT
36-
echo "head_commit=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
23+
aws-role-arn: ${{ secrets.AWS_ROLE_ARN_READ_GENERATE_GO_DOC_REPO }}
24+
aws-lambda-url: ${{ secrets.GATI_LAMBDA_TT_URL }}
25+
aws-region: ${{ secrets.AWS_REGION }}
3726

38-
- name: Install go doc generator
39-
shell: bash
27+
- name: Configure git for private repository and install go doc generator
28+
env:
29+
GOPRIVATE: github.com/smartcontractkit/generate-go-function-docs
4030
run: |
31+
git config --global \
32+
url."https://x-access-token:${{ steps.setup-github-token-read.outputs.access-token }}@github.com/".insteadOf "https://github.com/"
4133
go install github.com/smartcontractkit/generate-go-function-docs@latest
4234
4335
- name: Install gopls
4436
shell: bash
4537
run: |
46-
go install golang.org/x/tools/gopls@latest
38+
go install golang.org/x/tools/gopls@latest
39+
40+
- name: Checkout current branch
41+
uses: actions/checkout@v3
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Setup Git to use GitHub Actions bot
46+
run: |
47+
git config user.name "github-actions[bot]"
48+
git config user.email "github-actions[bot]@users.noreply.github.com"
4749
4850
- name: Create a new branch
4951
run: |
50-
git checkout -b ${{ steps.pr-details.outputs.pr_branch }}-docs
52+
git checkout -b ${{ github.event.pull_request.head.ref }}-docs
5153
5254
- name: Generate go docs
5355
shell: bash
5456
env:
5557
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
5658
run: |
57-
generate-go-function-docs diff -b ${{ steps.pr-details.outputs.base_commit }} -c ${{ steps.pr-details.outputs.head_commit }} -g fake_slash
59+
# Add go binary to PATH
60+
PATH=$PATH:$(go env GOPATH)/bin
61+
export PATH
62+
# TODO check why this flag is needed, if it has a default!
63+
# TODO we need a way to determine which modules have changes and run this command for all of them
64+
generate-go-function-docs diff -b ${{ github.event.pull_request.base.sha }} -c ${{ github.event.pull_request.head.sha }} -g fake_slash -f ./seth --goModLocation ./seth/go.mod
5865
5966
- name: Make sure code still compiles
6067
run: |
68+
# TODO we need a way to determine which modules have changes and run this command for all of them
69+
cd seth
6170
go mod tidy
62-
go mod vendor
6371
go build ./...
6472
65-
- name: Commit changes
66-
run: |
67-
git add .
68-
git commit -m "Add automatically generated go documentation"
69-
git push origin ${{ steps.pr-details.outputs.pr_branch }}-docs
73+
- name: Setup GitHub Token for creating a new PR
74+
id: setup-github-token-write
75+
uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected]
76+
with:
77+
aws-role-arn: ${{ secrets.AWS_ROLE_ARN_CREATE_PR }}
78+
aws-lambda-url: ${{ secrets.GATI_LAMBDA_TT_URL }}
79+
aws-region: ${{ secrets.AWS_REGION }}
80+
81+
82+
- name: Checkout new branch
83+
uses: peterjgrainger/action-create-branch@10c7d268152480ae859347db45dc69086cef1d9c # v3.0.0
84+
env:
85+
GITHUB_TOKEN: ${{ steps.setup-github-token-write.outputs.access-token }}
86+
with:
87+
branch: ${{ github.event.pull_request.head.ref }}-docs
88+
89+
- name: Commit changes
90+
uses: planetscale/ghcommit-action@13a844326508cdefc72235201bb0446d6d10a85f # v0.1.6
91+
with:
92+
commit_message: "[Bot] Add automatically generated go documentation"
93+
repo: ${{ github.repository }}
94+
branch: ${{ github.head_ref }}-docs
95+
# TODO we need a way to determine which modules have changes and run this command for all of them
96+
file_pattern: "seth/*"
97+
env:
98+
GITHUB_TOKEN: ${{ steps.setup-github-token-write.outputs.access-token }}
7099

71100
- name: Create a new PR targeting current PR
72-
uses: peter-evans/create-pull-request@v5
101+
uses: peter-evans/create-pull-request@v7
73102
with:
74-
token: ${{ secrets.GITHUB_TOKEN }}
75-
base: ${{ env.pr_branch }}
76-
branch: ${{ steps.pr-details.outputs.pr_branch }}-docs
77-
title: "Go docs for PR#${{ env.pr_number }}"
78-
body: "This PR contains automatically generated go documentation for the PR#${{ env.pr_number }}. Please review the changes."
103+
token: ${{ steps.setup-github-token-write.outputs.access-token }}
104+
base: ${{ github.head_ref }}
105+
branch: ${{ github.head_ref }}-docs
106+
title: "Go docs for PR#${{ github.event.pull_request.number }}"
107+
body: "This PR contains automatically generated go documentation for the PR#${{ github.event.pull_request.number }}. Please review the changes."

seth/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"github.com/pkg/errors"
1616
)
1717

18+
func MyAmazingNewFunction() string {
19+
return "bla bla bla"
20+
}
21+
1822
const (
1923
ErrReadSethConfig = "failed to read TOML config for seth"
2024
ErrUnmarshalSethConfig = "failed to unmarshal TOML config for seth"

0 commit comments

Comments
 (0)