|
| 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 | + if: ${{ contains(github.event.issue.labels.*.name, 'generate_go_docs') }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + repository-projects: read |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout current branch |
| 21 | + uses: actions/checkout@v3 |
| 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 |
| 37 | +
|
| 38 | + - name: Install go doc generator |
| 39 | + shell: bash |
| 40 | + run: | |
| 41 | + go install github.com/smartcontractkit/generate-go-function-docs@latest |
| 42 | +
|
| 43 | + - name: Install gopls |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + go install golang.org/x/tools/gopls@latest |
| 47 | +
|
| 48 | + - name: Create a new branch |
| 49 | + run: | |
| 50 | + git checkout -b ${{ steps.pr-details.outputs.pr_branch }}-docs |
| 51 | +
|
| 52 | + - name: Generate go docs |
| 53 | + shell: bash |
| 54 | + env: |
| 55 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 56 | + run: | |
| 57 | + generate-go-function-docs diff -b ${{ steps.pr-details.outputs.base_commit }} -c ${{ steps.pr-details.outputs.head_commit }} -g fake_slash |
| 58 | +
|
| 59 | + - name: Make sure code still compiles |
| 60 | + run: | |
| 61 | + go mod tidy |
| 62 | + go mod vendor |
| 63 | + go build ./... |
| 64 | +
|
| 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 |
| 70 | +
|
| 71 | + - name: Create a new PR targeting current PR |
| 72 | + uses: peter-evans/create-pull-request@v5 |
| 73 | + 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." |
0 commit comments