|
| 1 | +name: Go |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: Build |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Check out code into the Go module directory |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up Go 1.x |
| 18 | + uses: actions/setup-go@v5 |
| 19 | + with: |
| 20 | + go-version: "1.x" |
| 21 | + id: go |
| 22 | + |
| 23 | + - name: Build |
| 24 | + run: go build -race -v ./... |
| 25 | + |
| 26 | + - name: Test |
| 27 | + run: go test -race -cover -coverprofile ./coverage.out ./... |
| 28 | + |
| 29 | + - name: Coverage |
| 30 | + id: coverage |
| 31 | + run: | |
| 32 | + go tool cover -func ./coverage.out | tee -a coverage.txt |
| 33 | + echo "COVERAGE_CONTENT<<EOF" >> $GITHUB_ENV |
| 34 | + cat coverage.txt >> $GITHUB_ENV |
| 35 | + echo "EOF" >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - uses: actions/github-script@v4 |
| 38 | + if: github.event_name == 'pull_request' |
| 39 | + continue-on-error: true |
| 40 | + env: |
| 41 | + COVERAGE_CONTENT: "${{ env.COVERAGE_CONTENT }}" |
| 42 | + with: |
| 43 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + script: | |
| 45 | + const output = `Code Coverage\n |
| 46 | + \`\`\`\n |
| 47 | + ${process.env.COVERAGE_CONTENT} |
| 48 | + \`\`\` |
| 49 | +
|
| 50 | + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`; |
| 51 | +
|
| 52 | + const response = await github.issues.listComments({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + issue_number: context.issue.number, |
| 56 | + }); |
| 57 | +
|
| 58 | + var comments = response.data; |
| 59 | +
|
| 60 | + console.log(comments); |
| 61 | +
|
| 62 | + if (comments.length > 0) { |
| 63 | + comments = comments.filter(comment => comment.body.includes('Code Coverage') && comment.user.type === 'Bot'); |
| 64 | + } |
| 65 | +
|
| 66 | + if (comments.length > 0) { |
| 67 | + const comment = comments.shift(); |
| 68 | +
|
| 69 | + github.issues.updateComment({ |
| 70 | + issue_number: context.issue.number, |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + comment_id: comment.id, |
| 74 | + body: output |
| 75 | + }) |
| 76 | + } else { |
| 77 | + github.issues.createComment({ |
| 78 | + issue_number: context.issue.number, |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + body: output |
| 82 | + }) |
| 83 | + } |
| 84 | +
|
| 85 | + - name: Benchmark |
| 86 | + id: benchmark |
| 87 | + run: | |
| 88 | + go test -benchmem -bench . | tee -a benchmark.txt |
| 89 | + echo "BENCHMARK_CONTENT<<EOF" >> $GITHUB_ENV |
| 90 | + cat benchmark.txt >> $GITHUB_ENV |
| 91 | + echo "EOF" >> $GITHUB_ENV |
| 92 | +
|
| 93 | + - uses: actions/github-script@v4 |
| 94 | + if: github.event_name == 'pull_request' |
| 95 | + continue-on-error: true |
| 96 | + env: |
| 97 | + BENCHMARK_CONTENT: "${{ env.BENCHMARK_CONTENT }}" |
| 98 | + with: |
| 99 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + script: | |
| 101 | + const output = `Benchmark\n |
| 102 | + \`\`\`\n |
| 103 | + ${process.env.BENCHMARK_CONTENT} |
| 104 | + \`\`\` |
| 105 | +
|
| 106 | + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`; |
| 107 | +
|
| 108 | + const response = await github.issues.listComments({ |
| 109 | + owner: context.repo.owner, |
| 110 | + repo: context.repo.repo, |
| 111 | + issue_number: context.issue.number, |
| 112 | + }); |
| 113 | +
|
| 114 | + var comments = response.data; |
| 115 | +
|
| 116 | + console.log(comments); |
| 117 | +
|
| 118 | + if (comments.length > 0) { |
| 119 | + comments = comments.filter(comment => comment.body.includes('Benchmark') && comment.user.type === 'Bot'); |
| 120 | + } |
| 121 | +
|
| 122 | + if (comments.length > 0) { |
| 123 | + const comment = comments.shift(); |
| 124 | +
|
| 125 | + github.issues.updateComment({ |
| 126 | + issue_number: context.issue.number, |
| 127 | + owner: context.repo.owner, |
| 128 | + repo: context.repo.repo, |
| 129 | + comment_id: comment.id, |
| 130 | + body: output |
| 131 | + }) |
| 132 | + } else { |
| 133 | + github.issues.createComment({ |
| 134 | + issue_number: context.issue.number, |
| 135 | + owner: context.repo.owner, |
| 136 | + repo: context.repo.repo, |
| 137 | + body: output |
| 138 | + }) |
| 139 | + } |
| 140 | +
|
| 141 | + - name: Run golangci-lint |
| 142 | + |
| 143 | + with: |
| 144 | + version: v1.62.0 |
| 145 | + skip-cache: true |
| 146 | + |
| 147 | + - name: Coveralls |
| 148 | + uses: shogo82148/actions-goveralls@v1 |
| 149 | + with: |
| 150 | + path-to-profile: coverage.out |
0 commit comments