benchmark: PR 5109 (goconst) #92
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Benchmark PR (new linter) | |
on: | |
issues: | |
types: | |
- labeled | |
permissions: | |
issues: write | |
jobs: | |
notify-ack: | |
if: ${{ github.event.label.name == 'bench-new-linter' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Put a reaction | |
run: | | |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" | |
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:CONFUSED}){reaction{content}subject{id}}}" | true | |
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:ROCKET}){reaction{content}subject{id}}}" | true | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NODE_ID: ${{ github.event.issue.node_id }} | |
bench-job: | |
needs: notify-ack | |
if: ${{ github.event.label.name == 'bench-new-linter' }} | |
runs-on: ubuntu-latest | |
env: | |
PR_NUMBER: ${{ fromJson(github.event.issue.body).pr }} | |
LINTER: ${{ fromJson(github.event.issue.body).linter }} | |
TARGET_DIR: /tmp/target | |
HYPERFINE_VERSION: 1.18.0 | |
strategy: | |
matrix: | |
target: | |
- org: golangci | |
repo: golangci-lint | |
- org: goreleaser | |
repo: goreleaser | |
- org: gohugoio | |
repo: hugo | |
- org: go-gitea | |
repo: gitea | |
- org: rclone | |
repo: rclone | |
- org: kubernetes | |
repo: kubernetes | |
- org: hashicorp | |
repo: terraform | |
- org: hashicorp | |
repo: consul | |
- org: etcd-io | |
repo: etcd | |
- org: go-acme | |
repo: lego | |
- org: traefik | |
repo: traefik | |
- org: spf13 | |
repo: cobra | |
- org: google | |
repo: go-github | |
- org: beego | |
repo: beego | |
- org: grpc | |
repo: grpc-go | |
- org: go-delve | |
repo: delve | |
- org: cilium | |
repo: cilium | |
# CGO inside | |
- org: pact-foundation | |
repo: pact-go | |
steps: | |
- name: Hyperfine installation | |
run: | | |
wget https://github.com/sharkdp/hyperfine/releases/download/v${HYPERFINE_VERSION}/hyperfine_${HYPERFINE_VERSION}_amd64.deb | |
sudo dpkg -i hyperfine_${HYPERFINE_VERSION}_amd64.deb | |
- uses: actions/checkout@v4 | |
with: | |
repository: 'golangci/golangci-lint' | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: stable | |
- name: Checkout PR | |
run: gh pr checkout --detach --repo "golangci/golangci-lint" ${PR_NUMBER} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build golangci-lint | |
run: | | |
make build | |
cp ./golangci-lint $(go env GOPATH)/bin/golangci-lint | |
- name: Clone ${{ matrix.target.org }}/${{ matrix.target.repo }} | |
run: | | |
git clone -q --depth 1 --single-branch https://github.com/${{ matrix.target.org }}/${{ matrix.target.repo }}.git ${TARGET_DIR} | |
cd ${TARGET_DIR} | |
go mod tidy | |
- name: Simple run of golangci-lint on ${{ matrix.target.org }}/${{ matrix.target.repo }} (without cache) | |
run: | | |
cd ${TARGET_DIR} | |
golangci-lint cache clean | |
golangci-lint run -v --issues-exit-code=0 --max-issues-per-linter 50 --max-same-issues 10 --timeout=20m --show-stats --out-format colored-line-number,line-number:run.txt --enable-only ${LINTER} | |
# We use: | |
# - goconst as a reference of a fast linter. | |
# - durationcheck as a reference of a medium/slow linter. | |
# It can be changed in the future if needed. | |
- name: Run bench on ${{ matrix.target.org }}/${{ matrix.target.repo }} (without cache) | |
run: | | |
cd ${TARGET_DIR} | |
hyperfine --export-markdown perf.md -L linter "${LINTER},goconst,durationcheck" --warmup 2 \ | |
-n '{linter}' --prepare 'golangci-lint cache clean' "golangci-lint run --issues-exit-code=0 --timeout=20m --print-issued-lines=false --enable-only {linter}" | |
- name: Build report for ${{ matrix.target.org }}/${{ matrix.target.repo }} | |
run: | | |
cd ${TARGET_DIR} | |
mkdir -p /tmp/outputs/${REPO}/ | |
echo "## [${ORG}/${REPO}](${{ github.server_url }}/${ORG}/${REPO})" >> ${REPORT_DEST} | |
echo >> ${REPORT_DEST} | |
if test "$( cat run.txt | wc -c )" -gt 1 | |
then | |
echo '<details>' >> ${REPORT_DEST} | |
echo >> ${REPORT_DEST} | |
echo '```' >> ${REPORT_DEST} | |
cat run.txt | head -n 500 >> ${REPORT_DEST} | |
echo '```' >> ${REPORT_DEST} | |
echo >> ${REPORT_DEST} | |
fi | |
echo '</details>' >> ${REPORT_DEST} | |
echo >> ${REPORT_DEST} | |
cat perf.md >> ${REPORT_DEST} | |
echo >> ${REPORT_DEST} | |
env: | |
ORG: ${{ matrix.target.org }} | |
REPO: ${{ matrix.target.repo }} | |
REPORT_DEST: /tmp/outputs/${{ matrix.target.repo }}/report.md | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: outputs-${{ matrix.target.repo }} | |
path: /tmp/outputs/**/report.md | |
notify-job-result: | |
runs-on: ubuntu-latest | |
needs: bench-job | |
if: ${{ github.event.label.name == 'bench-new-linter' && always() }} | |
steps: | |
- name: Load outputs | |
if: ${{ contains(needs.*.result, 'success') }} | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: outputs-* | |
path: /tmp/outputs/ | |
- name: Notify on Success | |
if: ${{ contains(needs.*.result, 'success') }} | |
run: | | |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:ROCKET}){reaction{content}subject{id}}}" | |
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:CONFUSED}){reaction{content}subject{id}}}" | true | |
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" | true | |
( | |
echo "The benchmark (${{ github.workflow }}) is done!" | |
echo | |
cat /tmp/outputs/**/**/*.md | |
echo | |
echo "You can find the workflow here:" | |
echo "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
) | \ | |
gh issue comment "${ISSUE_NUMBER}" --repo ${{ github.repository }} -F - | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
ISSUE_NUMBER: ${{ github.event.issue.number }} | |
NODE_ID: ${{ github.event.issue.node_id }} | |
- name: Notify on Failure | |
if: ${{ contains(needs.*.result, 'failure') }} | |
run: | | |
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:CONFUSED}){reaction{content}subject{id}}}" | |
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:ROCKET}){reaction{content}subject{id}}}" | true | |
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}" | true | |
( | |
echo "**${{ github.workflow }}**" | |
echo "**Something went wrong!**" | |
echo | |
echo "**Details:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
) | \ | |
gh issue comment "${ISSUE_NUMBER}" --repo ${{ github.repository }} -F - | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
ISSUE_NUMBER: ${{ github.event.issue.number }} | |
NODE_ID: ${{ github.event.issue.node_id }} |