2023-03-17 12:02:27 -04:00
|
|
|
name: tidy-check-generate
|
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
|
|
|
pull_request:
|
|
|
|
|
|
|
|
jobs:
|
2023-03-13 13:33:31 -04:00
|
|
|
tidycheck:
|
2023-03-17 12:02:27 -04:00
|
|
|
name: tidy, check and generate
|
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-03-22 12:57:47 -04:00
|
|
|
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.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-23 12:27:09 -04:00
|
|
|
- name: Install Dependencies
|
|
|
|
run: |
|
|
|
|
echo "::group::Install Dependencies"
|
|
|
|
sudo apt-get update && sudo apt-get -y install libcryptsetup-dev libvirt-dev
|
|
|
|
echo "::endgroup::"
|
|
|
|
|
2023-03-29 08:13:51 -04:00
|
|
|
- name: Setup Bazel
|
|
|
|
uses: ./.github/actions/setup_bazel
|
|
|
|
with:
|
|
|
|
useCache: "true"
|
|
|
|
buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }}
|
|
|
|
|
2023-03-23 12:27:09 -04:00
|
|
|
- name: Setup Go environment
|
|
|
|
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
|
|
|
with:
|
|
|
|
go-version: "1.20.2"
|
|
|
|
|
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."
|
2023-03-23 12:27:09 -04:00
|
|
|
echo "untidy=false" | tee -a "$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"
|
2023-03-23 12:27:09 -04:00
|
|
|
echo "untidy=true" | tee -a "$GITHUB_OUTPUT"
|
2023-03-29 08:49:50 -04:00
|
|
|
diffsum=$(echo "$diff" | sha256sum | cut -d' ' -f1)
|
2023-03-23 12:27:09 -04:00
|
|
|
echo "diffsum=${diffsum}" | tee -a "$GITHUB_OUTPUT"
|
2023-03-17 11:20:39 -04:00
|
|
|
|
|
|
|
- name: Run Bazel generate
|
|
|
|
shell: bash
|
|
|
|
run: bazelisk run //:generate
|
|
|
|
|
|
|
|
- name: Check if ungenerated
|
|
|
|
id: ungenerated
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
diff=$(git diff)
|
2023-03-29 08:49:50 -04:00
|
|
|
diffsum=$(echo "$diff" | sha256sum| cut -d' ' -f1)
|
|
|
|
if [[ "${{ steps.untidy.outputs.diffsum }}" == "${diffsum}" ]]; then
|
2023-03-17 11:20:39 -04:00
|
|
|
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
|