mirror of
https://github.com/wahyd4/charts.git
synced 2026-08-09 05:06:29 +10:00
[bitnami/*] Reduce CI complexity and improve UX for automated PRs (#12242)
* [bitnami/*] Reduce CI complexity and simplify logic Signed-off-by: FraPazGal <fdepaz@vmware.com> * Enable auto-merge before approval Signed-off-by: FraPazGal <fdepaz@vmware.com> * Check for failing condition before skipping CI launched by readme-gen Signed-off-by: FraPazGal <fdepaz@vmware.com> Signed-off-by: FraPazGal <fdepaz@vmware.com>
This commit is contained in:
@@ -22,45 +22,29 @@ jobs:
|
||||
github.event.action == 'opened' &&
|
||||
github.actor == 'bitnami-bot'
|
||||
steps:
|
||||
# Enables auto-merge and adds necessary labels for automated releases' PRs
|
||||
- id: labeling
|
||||
name: Label PR
|
||||
# Adds 'verify' label to indicate the VIB Verify job can be executed
|
||||
- name: Label PR to be verified
|
||||
uses: andymckay/labeler@1.0.4
|
||||
with:
|
||||
# We can't use GITHUB_TOKEN because the labeling needs to trigger a new CI pipeline
|
||||
repo-token: "${{ secrets.BITNAMI_BOT_TOKEN }}"
|
||||
add-labels: "verify, auto-merge"
|
||||
- id: auto-merge
|
||||
name: Enable auto-merge
|
||||
run: |
|
||||
curl --request POST \
|
||||
--url https://api.github.com/graphql \
|
||||
--header 'authorization: Bearer ${{ secrets.BITNAMI_BOT_TOKEN }}' \
|
||||
--data '{
|
||||
"query": "mutation { enablePullRequestAutoMerge(input: {pullRequestId: \"${{ github.event.pull_request.node_id }}\", mergeMethod: SQUASH}) { clientMutationId }}"
|
||||
}' \
|
||||
--fail
|
||||
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
add-labels: 'verify'
|
||||
get-chart:
|
||||
runs-on: ubuntu-latest
|
||||
name: 'Get modified charts'
|
||||
name: Get modified charts
|
||||
if: ${{ github.event.pull_request.state != 'closed' }}
|
||||
outputs:
|
||||
chart: ${{ steps.get-chart.outputs.chart }}
|
||||
result: ${{ steps.get-chart.outputs.result }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
name: 'Checkout Repository'
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
fetch-depth: 0
|
||||
- id: get-chart
|
||||
name: 'Get modified charts'
|
||||
name: Get modified charts
|
||||
run: |
|
||||
# Check latest commit to skip pipeline if it contains changes from 'update-readme-metadata' action
|
||||
# TODO: remove logic and related conditional once the readme generator logic is included in the CI
|
||||
COMMIT_URL="https://api.github.com/repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.ref }}"
|
||||
latest_commit_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$COMMIT_URL")
|
||||
latest_commit_message=$(echo $latest_commit_data | jq -r '.commit | .message')
|
||||
|
||||
# Using the Github API to detect the files changed as git merge-base stops working when the branch is behind
|
||||
# and jitterbit/get-changed-files does not support pull_request_target
|
||||
PR_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files"
|
||||
@@ -73,15 +57,16 @@ jobs:
|
||||
num_version_bumps="$(echo "$files_changed_data" | jq -r '[.[] | select(.filename|endswith("Chart.yaml")) | select(.patch|contains("+version")) ] | length' )"
|
||||
non_readme_files=$(echo "$files_changed" | grep -vc "\.md" || true)
|
||||
|
||||
if [[ ${{ github.event.action }} == "synchronize" && ${{ github.actor }} == "bitnami-bot" && "$latest_commit_message" == *"readme-generator-for-helm"* ]]; then
|
||||
echo "::set-output name=result::skip"
|
||||
elif [[ "$non_readme_files" -le "0" ]]; then
|
||||
if [[ "$non_readme_files" -le "0" ]]; then
|
||||
# The only changes are .md files -> SKIP
|
||||
echo "::set-output name=result::skip"
|
||||
elif [[ "$num_charts_changed" -ne "$num_version_bumps" ]]; then
|
||||
# Changes done in charts but version not bumped -> ERROR
|
||||
echo "::set-output name=error::Detected changes in charts without version bump in Chart.yaml.\nCharts changed: ${num_charts_changed}\n${charts_dirs_changed}\nVersion bumps detected: ${num_version_bumps}"
|
||||
echo "::set-output name=result::fail"
|
||||
elif [[ ${{ github.actor }} == "bitnami-bot" && "$latest_commit_message" == *"readme-generator-for-helm"* ]]; then
|
||||
# The CI was launched by the readme generator workflow
|
||||
echo "::set-output name=result::skip"
|
||||
elif [[ "$num_charts_changed" -eq "1" ]]; then
|
||||
# Changes done in only one chart -> OK
|
||||
chart_name=$(echo "$charts_dirs_changed" | sed "s|bitnami/||g")
|
||||
@@ -105,31 +90,31 @@ jobs:
|
||||
# Using actions/github-scripts because using exit 1 in the script above would not provide any output
|
||||
# Source: https://github.community/t/no-output-on-process-completed-with-exit-code-1/123821/3
|
||||
- id: show-error
|
||||
name: 'Show error'
|
||||
name: Show error
|
||||
if: ${{ steps.get-chart.outputs.result == 'fail' }}
|
||||
uses: actions/github-script@v3
|
||||
with:
|
||||
script: |
|
||||
core.setFailed('${{ steps.get-chart.outputs.error }}')
|
||||
core.setFailed('${{ steps.get-chart.outputs.error }}')
|
||||
vib-verify:
|
||||
runs-on: ubuntu-latest
|
||||
needs: get-chart
|
||||
# Given performance issues of the action feature on GH's side, we need to be very restrictive in the job's triggers:
|
||||
# -> The 'Get modified charts' job suceededs AND
|
||||
# -> The event is not opened (avoids running twice on consecutive opened and labeled events) AND
|
||||
# ( ---> The pipeline was triggered due to a label addition and said label was the 'verify' one OR
|
||||
# ---> The pipeline was NOT triggered due to a label addition but the PR already contains the 'verify' one )
|
||||
# ---> The pipeline was NOT triggered due to a label addition but the PR already contains the 'verify' one OR
|
||||
# ---> The pipeline was triggered for a new automated PR )
|
||||
if: |
|
||||
needs.get-chart.outputs.result == 'ok' &&
|
||||
github.event.action != 'opened' &&
|
||||
(
|
||||
(github.event.action == 'labeled' && github.event.label.name == 'verify') ||
|
||||
(github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'verify'))
|
||||
)
|
||||
needs.get-chart.outputs.result == 'ok' &&
|
||||
(
|
||||
(github.event.action == 'labeled' && github.event.label.name == 'verify') ||
|
||||
(github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'verify')) ||
|
||||
(contains(github.event.pull_request.title, 'Release') && github.event.action == 'opened' && github.actor == 'bitnami-bot')
|
||||
)
|
||||
name: VIB Verify
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
name: 'Checkout Repository'
|
||||
name: Checkout Repository
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
@@ -144,58 +129,57 @@ jobs:
|
||||
VIB_ENV_ALTERNATIVE_TARGET_PLATFORM: ${{ secrets.VIB_ENV_ALTERNATIVE_TARGET_PLATFORM }}
|
||||
auto-pr-review:
|
||||
runs-on: ubuntu-latest
|
||||
needs: vib-verify
|
||||
needs: [auto-pr-triage, vib-verify]
|
||||
name: Reviewal for automated PRs
|
||||
# Job to be run only when the triage for automated PRs did as well,
|
||||
# not taking into account whether 'VIB Verify' succeeded
|
||||
if: |
|
||||
always() &&
|
||||
github.actor == 'bitnami-bot' &&
|
||||
contains(github.event.pull_request.labels.*.name, 'auto-merge')
|
||||
needs.auto-pr-triage.result == 'success'
|
||||
steps:
|
||||
# Approves the CI's PR if the 'VIB Verify' job succeeded
|
||||
# Approved by the 'github-actions' user. A PR can't be approved by its author
|
||||
- name: Approval
|
||||
- name: Enable auto-merge feature
|
||||
if: ${{ needs.vib-verify.result == 'success' }}
|
||||
uses: reitermarkus/automerge@v2.1.2
|
||||
with:
|
||||
token: ${{ secrets.BITNAMI_BOT_TOKEN }}
|
||||
merge-method: squash
|
||||
pull-request: ${{ github.event.number }}
|
||||
- name: Label PR as auto-merge
|
||||
if: ${{ needs.vib-verify.result == 'success' }}
|
||||
run: |
|
||||
curl --request POST \
|
||||
--url https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews \
|
||||
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
|
||||
--header 'content-type: application/json' \
|
||||
--data '{
|
||||
"event": "APPROVE"
|
||||
}' \
|
||||
--fail
|
||||
- name: Remove auto-merge label
|
||||
if: ${{ needs.vib-verify.result == 'failure' }}
|
||||
uses: andymckay/labeler@1.0.4
|
||||
with:
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
remove-labels: "auto-merge"
|
||||
- name: Disable auto-merge
|
||||
if: ${{ needs.vib-verify.result == 'failure' }}
|
||||
run: |
|
||||
curl --request POST \
|
||||
--url https://api.github.com/graphql \
|
||||
--header 'authorization: Bearer ${{ secrets.BITNAMI_BOT_TOKEN }}' \
|
||||
--data '{
|
||||
"query": "mutation { disablePullRequestAutoMerge(input: {pullRequestId: \"${{ github.event.pull_request.node_id }}\"}) { clientMutationId }}"
|
||||
}' \
|
||||
--fail
|
||||
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
add-labels: 'auto-merge'
|
||||
# Approve the CI's PR if the 'VIB Verify' job succeeded
|
||||
# Approved by the 'github-actions' user; a PR can't be approved by its author
|
||||
- name: PR approval
|
||||
if: ${{ needs.vib-verify.result == 'success' }}
|
||||
uses: hmarr/auto-approve-action@v2.4.0
|
||||
with:
|
||||
pull-request-number: ${{ github.event.number }}
|
||||
|
||||
# If the CI did not succeed ('VIB Verify' failed or skipped),
|
||||
# post a comment on the PR and assign a maintainer agent to review it
|
||||
- name: Manual review required
|
||||
if: ${{ needs.vib-verify.result == 'failure' }}
|
||||
run: |
|
||||
curl --request POST \
|
||||
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
|
||||
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
|
||||
--header 'content-type: application/json' \
|
||||
--data '{
|
||||
"body": "There has been an error during the automated release process. Manual revision is now required."
|
||||
}' \
|
||||
--fail
|
||||
curl --request POST \
|
||||
--url https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
|
||||
--header 'authorization: Bearer ${{ secrets.BITNAMI_BOT_TOKEN }}' \
|
||||
--header 'content-type: application/json' \
|
||||
--data '{
|
||||
"team_reviewers": ["build-maintainers"]
|
||||
}' \
|
||||
--fail
|
||||
if: ${{ needs.vib-verify.result != 'success' }}
|
||||
uses: peter-evans/create-or-update-comment@v2.0.0
|
||||
with:
|
||||
issue-number: ${{ github.event.number }}
|
||||
body: |
|
||||
There has been an error during the automated release process. Manual revision is now required.
|
||||
Please check the related [action_run#${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more information.
|
||||
- name: Assign PR to a maintaner agent
|
||||
if: ${{ needs.vib-verify.result != 'success' }}
|
||||
uses: pozil/auto-assign-issue@v1.9.0
|
||||
with:
|
||||
numOfAssignee: 1
|
||||
teams: build-maintainers
|
||||
repo-token: '${{ secrets.BITNAMI_BOT_TOKEN }}'
|
||||
- name: Move into From Bitnami
|
||||
uses: peter-evans/create-or-update-project-card@v2.0.0
|
||||
if: ${{ needs.vib-verify.result != 'success' }}
|
||||
with:
|
||||
project-name: Support
|
||||
column-name: From Bitnami
|
||||
token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
issue-number: ${{ github.event.number }}
|
||||
|
||||
Reference in New Issue
Block a user