Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test doc generation #1448

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 137 additions & 43 deletions .github/workflows/generate-go-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,164 @@

jobs:
generate_docs_new_pr:
if: ${{ contains(github.event.issue.labels.*.name, 'generate_go_docs') }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'generate_go_docs') }}
runs-on: ubuntu-latest
environment: integration
permissions:
contents: read
pull-requests: write
repository-projects: read
id-token: write
contents: read

steps:
- name: Setup GitHub Token for reading Generate Go Doc Repo
id: setup-github-token-read
uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected]
with:
aws-role-arn: ${{ secrets.AWS_ROLE_ARN_READ_GENERATE_GO_DOC_REPO }}
aws-lambda-url: ${{ secrets.GATI_LAMBDA_TT_URL }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Configure git for private repository and install go tools
env:
GOPRIVATE: github.com/smartcontractkit/generate-go-function-docs
run: |
git config --global url."https://x-access-token:${{ steps.setup-github-token-read.outputs.access-token }}@github.com/".insteadOf "https://github.com/"
go install github.com/smartcontractkit/[email protected]
go install github.com/jmank88/[email protected]
go install golang.org/x/tools/gopls@latest

- name: Checkout current branch
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Get PR details
id: pr-details
run: |
echo "pr_number=$(jq -r .pull_request.number <<< "$GITHUB_EVENT_PATH")" >> $GITHUB_OUTPUT
echo "pr_branch=$(jq -r .pull_request.head.ref <<< "$GITHUB_EVENT_PATH")" >> $GITHUB_OUTPUT
echo "base_commit=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT
echo "head_commit=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
- name: Detect changes related to current PR
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
with:
filters: |
seth:
- 'seth/**/*.go'
wasp:
- 'wasp/**/*.go'
havoc:
- 'havoc/**/*.go'
lib:
- 'lib/**/*.go'
k8s-test-runner:
- 'k8s-test-runner/**/*.go'
framework:
- 'framework/**/*.go'
# later add tools here or, if possible, make this filter dynamic so that it's created based on the go modules in the repository

- name: Install go doc generator
- name: Find all go modules in the repository and filter the ones that changed
shell: bash
id: go-modules
env:
FILTERS: ${{ steps.changes.outputs.changes }}
run: |

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:3:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:3:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:3:14: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:3:14: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:4:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:4:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:7:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:7:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:7:17: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:7:17: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:10:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:10:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:10:18: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:10:18: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:13:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:13:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:16:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:16:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:18:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:18:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:19:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:19:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]

Check failure on line 66 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L66

shellcheck reported issue in this script: SC2317:info:21:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:66:9: shellcheck reported issue in this script: SC2317:info:21:1: Command appears to be unreachable. Check usage (or ignore if invoked indirectly) [shellcheck]
go install github.com/smartcontractkit/generate-go-function-docs@latest
# remove after test
exit 1
PATH=$PATH:$(go env GOPATH)/bin
export PATH

- name: Install gopls
shell: bash
run: |
go install golang.org/x/tools/gopls@latest
# Find all go projects
gomods_output=$(gomods 2>&1)

- name: Create a new branch
run: |
git checkout -b ${{ steps.pr-details.outputs.pr_branch }}-docs
# Extract the parent directories of go.mod files
parent_folders=$(echo "$gomods_output" | grep 'go\.mod$' | sed 's/\/go\.mod//' | sed 's/^[ \t]*//;s/[ \t]*$//' | xargs -n 1)

# Convert parent directories into a JSON matrix
echo "$parent_folders" | jq -R -s 'split("\n") | map(select(length > 0)) | map({folder: .})' > all_folders.json

# Filter the directories that did not changeß
jq --argjson filters "$FILTERS" 'map(select(.folder as $folder | $filters | index($folder)))' all_folders.json > filtered_folders.json

echo "Filtered folder List JSON"
cat filtered_folders.json

- name: Generate go docs
rm all_folders.json

- name: Generate go docs for changed projects
shell: bash
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |

Check failure on line 93 in .github/workflows/generate-go-docs.yaml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/generate-go-docs.yaml#L93

shellcheck reported issue in this script: SC2002:style:4:5: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead [shellcheck]
Raw output
.github/workflows/generate-go-docs.yaml:93:9: shellcheck reported issue in this script: SC2002:style:4:5: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead [shellcheck]
generate-go-function-docs diff -b ${{ steps.pr-details.outputs.base_commit }} -c ${{ steps.pr-details.outputs.head_commit }} -g fake_slash
# Add go binary to PATH
PATH=$PATH:$(go env GOPATH)/bin
export PATH
cat filtered_folders.json | jq -c '.[]' | while read -r item; do
folder=$(echo "$item" | jq -r '.folder')
echo "Processing folder: $folder"
generate-go-function-docs diff -b ${{ github.event.pull_request.base.sha }} -c ${{ github.event.pull_request.head.sha }} --saveCosts --generator chatgpt --folder "$folder"
cd "$folder"
cd -
done
rm filtered_folders.json

- name: Make sure code still compiles
run: |
go mod tidy
go mod vendor
go build ./...
- name: Upload costs as artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: generation-costs
path: ./costs

- name: Commit changes
run: |
git add .
git commit -m "Add automatically generated go documentation"
git push origin ${{ steps.pr-details.outputs.pr_branch }}-docs
- name: Remove costs before committing
shell: bash
run: rm -rf costs

- name: Setup GitHub Token for creating a new PR
id: setup-github-token-write
uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected]
with:
aws-role-arn: ${{ secrets.AWS_ROLE_ARN_CREATE_PR }}
aws-lambda-url: ${{ secrets.GATI_LAMBDA_TT_URL }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Create a new PR targeting current PR
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
token: ${{ steps.setup-github-token-write.outputs.access-token }}
branch: ${{ github.head_ref }}-docs
base: ${{ github.head_ref }}
title: "Go docs for PR#${{ github.event.pull_request.number }}"
body: "This PR contains automatically generated go documentation for the PR#${{ github.event.pull_request.number }}. Please review the changes."
commit-message: "[Bot] Add automatically generated go documentation"

- name: Send Slack notification
uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 # v1.25.0
if: failure()
id: slack
env:
SLACK_BOT_TOKEN: ${{ secrets.QA_SLACK_API_KEY }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: ${{ env.pr_branch }}
branch: ${{ steps.pr-details.outputs.pr_branch }}-docs
title: "Go docs for PR#${{ env.pr_number }}"
body: "This PR contains automatically generated go documentation for the PR#${{ env.pr_number }}. Please review the changes."
channel-id: 'C049X3353K2'
payload: |
{
"attachments": [
{
"color": "#C62828",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Go doc generation - Failed :x:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<@U060CGGPY8H>, please have a look."
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"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>"
}
}
]
}
]
}
4 changes: 4 additions & 0 deletions k8s-test-runner/k8s_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func retryK8sCall(operation k8sOperation, retryPolicy wait.Backoff) error {
return nil
}

func IDoNothing() {
//I really do nothing
}

func (m *Client) ListPods(ctx context.Context, namespace, syncLabel string) (*v1.PodList, error) {
var pods *v1.PodList
timeout := int64(30)
Expand Down
4 changes: 4 additions & 0 deletions seth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/pkg/errors"
)

func MyAmazingNewFunction() string {
return "bla bla bla"
}

const (
ErrReadSethConfig = "failed to read TOML config for seth"
ErrUnmarshalSethConfig = "failed to unmarshal TOML config for seth"
Expand Down
2 changes: 2 additions & 0 deletions seth/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func (m *Client) Decode(tx *types.Transaction, txErr error) (*DecodedTransaction
return nil, verr.Join(m.Errors...)
}

_ = MyAmazingNewFunction()

if decodedErr := m.DecodeSendErr(txErr); decodedErr != nil {
return nil, decodedErr
}
Expand Down
Loading
Loading