2023-03-13 13:33:31 -04:00
|
|
|
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
|
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:
|
2023-03-13 13:33:31 -04:00
|
|
|
tidycheck:
|
|
|
|
name: tidy and 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
|
2023-03-13 13:33:31 -04:00
|
|
|
run: bazelisk run //:tidy
|
|
|
|
|
2023-03-17 11:20:39 -04:00
|
|
|
- name: Check if untidy
|
|
|
|
id: untidy
|
2023-03-10 08:37:30 -05:00
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
diff=$(git diff)
|
|
|
|
if [[ -z "$diff" ]]; then
|
2023-03-17 11:20:39 -04:00
|
|
|
echo "Everything is tidy."
|
|
|
|
echo "untidy=false" >> "$GITHUB_OUTPUT"
|
2023-03-10 08:37:30 -05:00
|
|
|
exit 0
|
|
|
|
fi
|
2023-03-17 11:20:39 -04:00
|
|
|
echo "Detected changes after tidy"
|
|
|
|
echo "untidy=true" >> "$GITHUB_OUTPUT"
|
|
|
|
|
|
|
|
- name: Run Bazel generate
|
|
|
|
shell: bash
|
|
|
|
run: bazelisk run //:generate
|
|
|
|
|
|
|
|
- name: Check if ungenerated
|
|
|
|
id: ungenerated
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
diff=$(git diff)
|
|
|
|
if [[ -z "$diff" ]]; then
|
|
|
|
echo "Everything is tidy."
|
|
|
|
echo "ungenerated=false" >> "$GITHUB_OUTPUT"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "Detected changes after tidy"
|
|
|
|
echo "ungenerated=true" >> "$GITHUB_OUTPUT"
|
|
|
|
|
|
|
|
- name: Check if tidy or generate made modifications
|
|
|
|
id: modified
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
diff=$(git diff)
|
|
|
|
if [[ -z "$diff" ]]; then
|
|
|
|
echo "Everything is tidy and generated."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-03-10 08:37:30 -05:00
|
|
|
cat << EOF >> "${GITHUB_STEP_SUMMARY}"
|
|
|
|
\`\`\`diff
|
|
|
|
${diff}
|
|
|
|
\`\`\`
|
|
|
|
EOF
|
2023-03-17 11:20:39 -04:00
|
|
|
|
|
|
|
if [[ "${{ steps.untidy.outputs.untidy }}" == "true" ]] &&
|
|
|
|
[[ "${{ steps.ungenerated.outputs.ungenerated }}" == "true" ]]; then
|
|
|
|
suggestCmd="'bazel run //:generate' &&' bazel run //:tidy'"
|
|
|
|
elif [[ "${{ steps.untidy.outputs.untidy }}" == "true" ]]; then
|
|
|
|
suggestCmd="'bazel run //:tidy'"
|
|
|
|
elif [[ "${{ steps.ungenerated.outputs.ungenerated }}" == "true" ]]; then
|
|
|
|
suggestCmd="'bazel run //:generate'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "::error::The repo is not tidy. Please run ${suggestCmd} and commit the changes."
|
2023-03-10 08:37:30 -05:00
|
|
|
exit 1
|
2022-10-18 11:33:21 -04:00
|
|
|
|
2023-03-14 03:23:11 -04:00
|
|
|
- name: Run Bazel check
|
|
|
|
shell: bash
|
|
|
|
run: bazelisk run //:check
|
|
|
|
|
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() &&
|
2023-03-17 11:20:39 -04:00
|
|
|
(steps.modified.conclusion == 'failure') &&
|
2022-12-23 05:16:26 -05:00
|
|
|
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
|