constellation/.github/workflows/test-tidy.yml

74 lines
2.1 KiB
YAML
Raw Normal View History

name: tidy-and-check
2022-09-15 12:48:51 -04:00
on:
2022-10-12 04:50:06 -04:00
workflow_dispatch:
2022-09-15 12:48:51 -04:00
push:
branches:
- main
- "release/**"
2022-09-15 12:48:51 -04:00
paths:
- "**.go"
- "**/go.mod"
- "**/go.sum"
- ".github/workflows/test-tidy.yml"
2022-09-15 12:48:51 -04:00
pull_request:
paths:
- "**.go"
- "**/go.mod"
- "**/go.sum"
- ".github/workflows/test-tidy.yml"
2022-09-15 12:48:51 -04:00
jobs:
tidycheck:
name: tidy and check
runs-on: ubuntu-22.04
2022-09-15 12:48:51 -04:00
steps:
- name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
# No token available for forks, so we can't push changes
token: ${{ !github.event.pull_request.head.repo.fork && secrets.CI_COMMIT_PUSH_PR || '' }}
2022-09-15 12:48:51 -04:00
- name: Run Bazel tidy
shell: bash
run: bazelisk run //:tidy
- name: Run Bazel check
shell: bash
run: bazelisk run //:check
2022-09-15 12:48:51 -04:00
- name: Check if tidy made modifications
id: tidycheck
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
# 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
if: |
failure() &&
(steps.tidycheck.conclusion == 'failure') &&
startsWith(github.head_ref, 'renovate/') &&
!github.event.pull_request.head.repo.fork
shell: bash
run: |
git config --global user.name "edgelessci"
git config --global user.email "edgelessci@users.noreply.github.com"
git commit -am "deps: tidy all modules"
git push