|
9 | 9 |
|
10 | 10 | jobs: |
11 | 11 | 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') }} |
13 | 13 | runs-on: ubuntu-latest |
14 | 14 | permissions: |
15 | | - contents: read |
16 | | - pull-requests: write |
17 | | - repository-projects: read |
| 15 | + id-token: write |
| 16 | + contents: read |
18 | 17 |
|
19 | 18 | 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] |
22 | 22 | 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 }} |
37 | 26 |
|
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 |
40 | 30 | 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/" |
41 | 33 | go install github.com/smartcontractkit/generate-go-function-docs@latest |
42 | 34 |
|
43 | 35 | - name: Install gopls |
44 | 36 | shell: bash |
45 | 37 | 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" |
47 | 49 |
|
48 | 50 | - name: Create a new branch |
49 | 51 | run: | |
50 | | - git checkout -b ${{ steps.pr-details.outputs.pr_branch }}-docs |
| 52 | + git checkout -b ${{ github.event.pull_request.head.ref }}-docs |
51 | 53 |
|
52 | 54 | - name: Generate go docs |
53 | 55 | shell: bash |
54 | 56 | env: |
55 | 57 | OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
56 | 58 | 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 |
58 | 65 |
|
59 | 66 | - name: Make sure code still compiles |
60 | 67 | run: | |
| 68 | + # TODO we need a way to determine which modules have changes and run this command for all of them |
| 69 | + cd seth |
61 | 70 | go mod tidy |
62 | | - go mod vendor |
63 | 71 | go build ./... |
64 | 72 |
|
65 | | - - name: Commit changes |
| 73 | + - name: Setup branch names |
| 74 | + id: branch-names |
| 75 | + shell: bash |
66 | 76 | run: | |
67 | | - git add . |
68 | | - git commit -m "Add automatically generated go documentation" |
69 | | - git push origin ${{ steps.pr-details.outputs.pr_branch }}-docs |
| 77 | + echo "base_branch=${{ github.head_ref }}" >> $GITHUB_OUTPUT |
| 78 | + echo "new_branch=${{ github.head_ref }}-docs" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + - name: Setup GitHub Token for creating a new PR |
| 81 | + id: setup-github-token-write |
| 82 | + uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected] |
| 83 | + with: |
| 84 | + aws-role-arn: ${{ secrets.AWS_ROLE_ARN_CREATE_PR }} |
| 85 | + aws-lambda-url: ${{ secrets.GATI_LAMBDA_TT_URL }} |
| 86 | + aws-region: ${{ secrets.AWS_REGION }} |
| 87 | + |
| 88 | + - name: Checkout new branch |
| 89 | + uses: peterjgrainger/action-create-branch@10c7d268152480ae859347db45dc69086cef1d9c # v3.0.0 |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ steps.setup-github-token-write.outputs.access-token }} |
| 92 | + with: |
| 93 | + branch: ${{ steps.branch-names.outputs.new_branch }} |
| 94 | + |
| 95 | + - name: Commit changes |
| 96 | + uses: planetscale/ghcommit-action@13a844326508cdefc72235201bb0446d6d10a85f # v0.1.6 |
| 97 | + with: |
| 98 | + commit_message: "[Bot] Add automatically generated go documentation" |
| 99 | + repo: ${{ github.repository }} |
| 100 | + branch: ${{ steps.branch-names.outputs.new_branch }} |
| 101 | + # TODO we need a way to determine which modules have changes and run this command for all of them |
| 102 | + file_pattern: "seth/*" |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ steps.setup-github-token-write.outputs.access-token }} |
| 105 | + |
| 106 | + - name: Fetch repository changes |
| 107 | + uses: actions/checkout@v3 |
| 108 | + with: |
| 109 | + fetch-depth: 0 |
70 | 110 |
|
71 | 111 | - name: Create a new PR targeting current PR |
72 | | - uses: peter-evans/create-pull-request@v5 |
| 112 | + uses: peter-evans/create-pull-request@v7 |
73 | 113 | 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." |
| 114 | + token: ${{ steps.setup-github-token-write.outputs.access-token }} |
| 115 | + base: ${{ steps.branch-names.outputs.base_branch }} |
| 116 | + branch: ${{ steps.branch-names.outputs.new_branch }} |
| 117 | + title: "Go docs for PR#${{ github.event.pull_request.number }}" |
| 118 | + body: "This PR contains automatically generated go documentation for the PR#${{ github.event.pull_request.number }}. Please review the changes." |
0 commit comments