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
|
2023-11-03 06:59:19 -04:00
|
|
|
runs-on: [arc-runner-set]
|
2023-03-30 03:41:56 -04:00
|
|
|
permissions:
|
|
|
|
id-token: write
|
|
|
|
contents: read
|
2022-09-15 12:48:51 -04:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2023-12-20 10:10:35 -05:00
|
|
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
2022-09-19 04:59:46 -04:00
|
|
|
with:
|
2023-10-24 08:31:13 -04: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
|
2023-10-04 07:55:38 -04:00
|
|
|
uses: ./.github/actions/setup_bazel_nix
|
2023-03-29 08:13:51 -04:00
|
|
|
with:
|
2023-11-03 06:59:19 -04:00
|
|
|
useCache: "rbe"
|
|
|
|
rbePlatform: "ubuntu-22.04"
|
2023-03-29 08:13:51 -04:00
|
|
|
buildBuddyApiKey: ${{ secrets.BUILDBUDDY_ORG_API_KEY }}
|
|
|
|
|
2023-03-30 03:41:56 -04:00
|
|
|
- name: Assume AWS role to upload Bazel dependencies to S3
|
|
|
|
if: startsWith(github.head_ref, 'renovate/')
|
2024-02-21 09:29:06 -05:00
|
|
|
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
2023-03-30 03:41:56 -04:00
|
|
|
with:
|
|
|
|
role-to-assume: arn:aws:iam::795746500882:role/GithubConstellationMirrorWrite
|
|
|
|
aws-region: eu-central-1
|
|
|
|
|
|
|
|
- name: Upload Bazel dependencies to the mirror
|
|
|
|
if: startsWith(github.head_ref, 'renovate/')
|
|
|
|
shell: bash
|
2023-04-05 11:32:51 -04:00
|
|
|
run: |
|
2023-05-19 09:36:54 -04:00
|
|
|
bazel run //bazel/ci:deps_mirror_upgrade
|
|
|
|
bazel run //bazel/ci:deps_mirror_upload
|
2023-03-30 03:41:56 -04:00
|
|
|
|
2023-03-10 08:37:30 -05:00
|
|
|
- name: Run Bazel tidy
|
|
|
|
shell: bash
|
2023-05-19 09:36:54 -04:00
|
|
|
run: bazel run //:tidy
|
2023-03-13 13:33:31 -04:00
|
|
|
|
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-05-02 03:59:55 -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
|
2023-05-19 09:36:54 -04:00
|
|
|
run: bazel run //:generate
|
2023-03-17 11:20:39 -04:00
|
|
|
|
|
|
|
- name: Check if ungenerated
|
|
|
|
id: ungenerated
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
diff=$(git diff)
|
2023-05-02 03:59:55 -04:00
|
|
|
diffsum=$(echo "$diff" | sha256sum| cut -d' ' -f1)
|
2023-03-29 08:49:50 -04:00
|
|
|
if [[ "${{ steps.untidy.outputs.diffsum }}" == "${diffsum}" ]]; then
|
2023-03-17 11:20:39 -04:00
|
|
|
echo "Everything is tidy."
|
2023-04-14 12:25:53 -04:00
|
|
|
echo "ungenerated=false" | tee -a "$GITHUB_OUTPUT"
|
2023-03-17 11:20:39 -04:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "Detected changes after tidy"
|
2023-04-14 12:25:53 -04:00
|
|
|
echo "ungenerated=true" | tee -a "$GITHUB_OUTPUT"
|
2023-03-17 11:20:39 -04:00
|
|
|
|
|
|
|
- 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
|
2023-05-19 09:36:54 -04:00
|
|
|
run: bazel run //:check
|
2023-03-14 03:23:11 -04:00
|
|
|
|
2022-10-18 11:33:21 -04:00
|
|
|
# The following steps are only executed if the previous tidy check failed
|
2023-03-30 03:41:56 -04:00
|
|
|
# and the action runs on an renovate branch. In this case, we tidy all
|
2022-10-18 11:33:21 -04:00
|
|
|
# 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
|