admin管理员组文章数量:1289382
I have two GitHub workflows working together to automate cluster list updates in my repository:
cluster-list.yaml
workflowThis workflow runs every 3 hours and:
Retrieves a list of all clusters from a tool (ArgoCD).
Compares it with the existing
clusters-list.yaml
file.If there are differences, it:
Creates a new branch.
Updates
clusters-list.yaml
.Creates a pull request (PR) with the changes.
Labels the PR with "automerge".
name: Check for new cluster on: workflow_dispatch: schedule: - cron: '0 */3 * * *' permissions: contents: write pull-requests: write jobs: check-for-new-cluster: runs-on: ubuntu-latest steps: - name: Check for new cluster uses: actions/checkout@v4 with: ref: main - name: Install ArgoCD CLI run: | curl -sSL -o argocd-linux-amd64 sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd sudo rm argocd-linux-amd64 - name: Login to ArgoCD run: argocd login XXXXXX --username ${{ secrets.ARGOCD_USER }} --password ${{ secrets.ARGOCD_PW }} --insecure - name: Get clusters list run: | cd ./helm-charts argocd cluster list -o json | jq 'map({name, labels, annotations, shortName: (.name | gsub("-k8s"; ""))}) | sort_by(.name)' | yq eval '{"argocdClusters": .}' -P > clusters-list-new.yaml - name: Compare cluster list run: | cd ./helm-charts diff -u clusters-list.yaml clusters-list-new.yaml > clusters-list.diff || true if [ -s clusters-list.diff ] then echo "Cluster list has changed" cat clusters-list.diff branchname=$(echo "maint/update-clusters-list-$(date +'%Y%m%d%H%M%S')") cp clusters-list-new.yaml clusters-list.yaml git config user.name github-actions git config user.email [email protected] git checkout -b $branchname git add clusters-list.yaml git commit -m "JOP-000: Update clusters-list.yaml" git push origin $branchname gh pr create -B main -H $branchname -t "JOP-000: Update clusters-list.yaml" -b "JOP-000: Update clusters-list.yaml" --label automerge else echo "Cluster list has not changed" fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
automerge.yaml
workflowThis workflow should automatically merge PRs under specific conditions. It triggers on PR events (labeled, synchronize, opened, ready_for_review, and review_submission) and:
- If only
helm-charts/clusters-list.yaml
is modified, it merges the PR without requiring review. - If other files are modified, it requires an approved review before merging.
name: Automerge on: pull_request_target: types: - labeled - synchronize - opened - ready_for_review pull_request_review: types: - submitted permissions: contents: write pull-requests: write jobs: automerge: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} - name: Check if checks passed and pr is correctly labeled run: | git config user.name github-actions git config user.email [email protected] # check if the PR is labeled automerge if ! gh pr view ${{ github.event.number }} --json labels --jq '.labels[].name' | grep -q automerge; then echo "PR is not labeled automerge, exiting" exit 0 fi echo "PR is labeled automerge" # Get list of modified files MODIFIED_FILES=$(gh pr view ${{ github.event.number }} --json files --jq '.files[].path') # Check if only clusters-list.yaml in helm-charts is modified if [ "$(echo "$MODIFIED_FILES" | wc -l)" -eq 1 ] && [ "$MODIFIED_FILES" = "helm-charts/clusters-list.yaml" ]; then echo "Only helm-charts/clusters-list.yaml is modified, proceeding without review" else # For other files, check for review approval if ! gh pr view ${{ github.event.number }} --json reviews --jq '.reviews[].state' | grep -iq approved; then echo "PR modifies other files and does not have an approved review, exiting" exit 0 fi echo "PR has an approved review" fi #merge gh pr merge ${{ github.event.number }} --auto --squash --delete-branch env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- If only
How the two workflows should work together:
cluster-list.yaml
detects new clusters and creates a PR with updates.This PR is labeled "automerge" by the workflow.
automerge.yaml
should trigger on this PR and automatically merge it (since it only modifiesclusters-list.yaml
).Other PRs (modifying different files) should still require review before merging.
The cluster-list.yaml
workflow successfully creates the PR and applies the "automerge" label. However, the automerge.yaml
workflow never runs for this PR, and the merge does not happen automatically.
I've:
Confirmed that the
automerge.yaml
workflow is correctly configured to trigger on PR events.Manually checked that the PR is labeled "automerge."
Verified that only
helm-charts/clusters-list.yaml
is modified in the PR.
Has anyone encountered a similar issue with GitHub Actions? How can I debug why the automerge.yaml
workflow does not trigger for the PRs created by cluster-list.yaml
?
本文标签: kubernetesAutomerge workflow not triggering on PRsStack Overflow
版权声明:本文标题:kubernetes - Automerge workflow not triggering on PRs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741398510a2376520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论