2022-09-15 12:48:51 -04:00
|
|
|
name: Go mod tidy check
|
|
|
|
|
|
|
|
on:
|
2022-10-12 04:50:06 -04:00
|
|
|
workflow_dispatch:
|
2022-09-15 12:48:51 -04:00
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
2022-10-18 10:17:41 -04:00
|
|
|
- "release/**"
|
2022-09-15 12:48:51 -04:00
|
|
|
paths:
|
|
|
|
- "**.go"
|
2022-10-14 04:27:49 -04:00
|
|
|
- "**/go.mod"
|
|
|
|
- "**/go.sum"
|
2023-02-14 14:01:00 -05:00
|
|
|
- ".github/workflows/test-tidy.yml"
|
2022-09-15 12:48:51 -04:00
|
|
|
pull_request:
|
|
|
|
paths:
|
|
|
|
- "**.go"
|
2022-10-14 04:27:49 -04:00
|
|
|
- "**/go.mod"
|
|
|
|
- "**/go.sum"
|
2023-02-14 14:01:00 -05:00
|
|
|
- ".github/workflows/test-tidy.yml"
|
2022-09-15 12:48:51 -04:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
gotidycheck:
|
|
|
|
name: Go mod tidy check
|
2022-11-10 10:55:24 -05:00
|
|
|
runs-on: ubuntu-22.04
|
2022-09-15 12:48:51 -04:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2023-01-05 10:17:51 -05:00
|
|
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
2022-09-19 04:59:46 -04:00
|
|
|
with:
|
2022-12-19 09:21:28 -05:00
|
|
|
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
|
2022-12-23 05:16:26 -05:00
|
|
|
# No token available for forks, so we can't push changes
|
2023-03-02 12:07:29 -05:00
|
|
|
token: ${{ !github.event.pull_request.head.repo.fork && secrets.CI_COMMIT_PUSH_PR || '' }}
|
2022-09-15 12:48:51 -04:00
|
|
|
|
2023-03-10 08:37:30 -05:00
|
|
|
- name: Run Bazel tidy
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
bazelisk run //bazel/ci:tidy
|
|
|
|
bazelisk run //:gazelle-check
|
2022-09-15 12:48:51 -04:00
|
|
|
|
2023-03-10 08:37:30 -05:00
|
|
|
- name: Check if tidy made modifications
|
2022-10-18 11:33:21 -04:00
|
|
|
id: tidycheck
|
2023-03-10 08:37:30 -05:00
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
diff=$(git diff)
|
|
|
|
if [[ -z "$diff" ]]; then
|
|
|
|
echo "Everything is tidy"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
cat << EOF >> "${GITHUB_STEP_SUMMARY}"
|
|
|
|
\`\`\`diff
|
|
|
|
${diff}
|
|
|
|
\`\`\`
|
|
|
|
EOF
|
|
|
|
echo "::error::The repo is not tidy. Please run 'bazel run bazel/ci:tidy' and commit the changes."
|
|
|
|
exit 1
|
2022-10-18 11:33:21 -04:00
|
|
|
|
|
|
|
# The following steps are only executed if the previous tidy check failed
|
|
|
|
# and the action runs on an renovat branche. In this case, we tidy all
|
|
|
|
# modules again and commit the changes, so the user doesn't need to do it.
|
|
|
|
|
|
|
|
- name: Push changes
|
2022-12-23 05:16:26 -05:00
|
|
|
if: |
|
|
|
|
failure() &&
|
|
|
|
(steps.tidycheck.conclusion == 'failure') &&
|
|
|
|
startsWith(github.head_ref, 'renovate/') &&
|
|
|
|
!github.event.pull_request.head.repo.fork
|
2022-10-18 11:33:21 -04:00
|
|
|
shell: bash
|
|
|
|
run: |
|
2023-02-20 09:33:59 -05:00
|
|
|
git config --global user.name "edgelessci"
|
|
|
|
git config --global user.email "edgelessci@users.noreply.github.com"
|
2023-01-12 12:13:25 -05:00
|
|
|
git commit -am "deps: tidy all modules"
|
2022-10-18 11:33:21 -04:00
|
|
|
git push
|