-
Notifications
You must be signed in to change notification settings - Fork 138
ROSA-745: per-repo dependency automation config #917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MitaliBhalla
wants to merge
1
commit into
openshift:master
Choose a base branch
from
MitaliBhalla:rosa-745-dependency-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: 'gomod' | ||
| - package-ecosystem: gomod | ||
| directory: '/' | ||
| labels: | ||
| - "area/dependency" | ||
| - "ok-to-test" | ||
| allow: | ||
| - dependency-name: "github.com/openshift/osd-network-verifier" | ||
| - dependency-name: "github.com/openshift/backplane-cli" | ||
| schedule: | ||
| interval: 'daily' | ||
| interval: 'weekly' | ||
| open-pull-requests-limit: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| name: Dependabot Auto-Merge | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| auto-merge: | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| github.event.pull_request.user.login == 'dependabot[bot]' && | ||
| github.event.pull_request.head.repo.full_name == github.repository | ||
| steps: | ||
| - name: Fetch Dependabot Metadata | ||
| id: metadata | ||
| uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2 | ||
|
|
||
| - name: Enable Auto-Merge for Safe Updates | ||
| id: enable-automerge | ||
| if: | | ||
| steps.metadata.outputs.update-type == 'version-update:semver-patch' || | ||
| steps.metadata.outputs.update-type == 'version-update:semver-minor' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| UPDATE_TYPE: ${{ steps.metadata.outputs.update-type }} | ||
| DEPENDENCY_NAMES: ${{ steps.metadata.outputs.dependency-names }} | ||
| PREVIOUS_VERSION: ${{ steps.metadata.outputs.previous-version }} | ||
| NEW_VERSION: ${{ steps.metadata.outputs.new-version }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| REPOSITORY: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| echo "Enabling auto-merge for ${UPDATE_TYPE} update" | ||
| echo "Dependency: ${DEPENDENCY_NAMES}" | ||
|
|
||
| PR_NODE_ID=$(curl -s \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| "https://api.github.com/repos/${REPOSITORY}/pulls/${PR_NUMBER}" \ | ||
| | jq -r '.node_id') | ||
|
|
||
| if [[ -z "${PR_NODE_ID}" || "${PR_NODE_ID}" == "null" ]]; then | ||
| echo "automerge-enabled=false" >> "${GITHUB_OUTPUT}" | ||
| echo "❌ Failed to fetch PR node ID" | ||
| exit 1 | ||
| fi | ||
|
|
||
| response=$(curl -s -w "%{http_code}" -o /tmp/response.json \ | ||
| -X POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| "https://api.github.com/graphql" \ | ||
| -d "{\"query\":\"mutation { enablePullRequestAutoMerge(input: { pullRequestId: \\\"${PR_NODE_ID}\\\", mergeMethod: SQUASH }) { pullRequest { autoMergeRequest { enabledAt } } } }\"}") | ||
|
|
||
| if [[ "${response}" == "200" ]] && \ | ||
| jq -e '.errors == null and .data.enablePullRequestAutoMerge.pullRequest.autoMergeRequest.enabledAt != null' /tmp/response.json >/dev/null; then | ||
| echo "automerge-enabled=true" >> "${GITHUB_OUTPUT}" | ||
| echo "✅ Auto-merge enabled successfully via GraphQL" | ||
| cat /tmp/response.json | ||
| else | ||
| echo "automerge-enabled=false" >> "${GITHUB_OUTPUT}" | ||
| echo "❌ Failed to enable auto-merge. HTTP status: ${response}" | ||
| cat /tmp/response.json | ||
| echo "::warning::Could not enable auto-merge; manual review required." | ||
| jq -n \ | ||
| --arg body "🤖 **Dependabot Auto-Merge Status** | ||
|
|
||
| This PR meets the criteria for auto-merge but could not be automatically merged. | ||
|
|
||
| - Update type: ${UPDATE_TYPE} | ||
| - Dependencies: ${DEPENDENCY_NAMES} | ||
| - Previous version: ${PREVIOUS_VERSION} | ||
| - New version: ${NEW_VERSION}" \ | ||
| '{body: $body}' > /tmp/comment-body.json | ||
| comment_status=$(curl -s -w "%{http_code}" -o /tmp/comment.json \ | ||
| -X POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| "https://api.github.com/repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \ | ||
| -d @/tmp/comment-body.json) | ||
| if [[ "${comment_status}" != "201" ]]; then | ||
| echo "::warning::Failed to post auto-merge status comment (HTTP ${comment_status})" | ||
| cat /tmp/comment.json | ||
| fi | ||
| fi | ||
|
|
||
| - name: Comment on Major Version Updates | ||
| if: | | ||
| github.event.action == 'opened' && | ||
| steps.metadata.outputs.update-type == 'version-update:semver-major' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| DEPENDENCY_NAMES: ${{ steps.metadata.outputs.dependency-names }} | ||
| PREVIOUS_VERSION: ${{ steps.metadata.outputs.previous-version }} | ||
| NEW_VERSION: ${{ steps.metadata.outputs.new-version }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| REPOSITORY: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| jq -n \ | ||
| --arg body "🚨 **Major Version Update Detected** 🚨 | ||
|
|
||
| This PR contains a major version update that requires manual review: | ||
| - **Dependency:** ${DEPENDENCY_NAMES} | ||
| - **Previous version:** ${PREVIOUS_VERSION} | ||
| - **New version:** ${NEW_VERSION} | ||
|
|
||
| Auto-merge has been **disabled** for this PR." \ | ||
| '{body: $body}' > /tmp/major-comment-body.json | ||
| comment_status=$(curl -s -w "%{http_code}" -o /tmp/major-comment.json \ | ||
| -X POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer ${GH_TOKEN}" \ | ||
| "https://api.github.com/repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \ | ||
| -d @/tmp/major-comment-body.json) | ||
| if [[ "${comment_status}" != "201" ]]; then | ||
| echo "::warning::Failed to post major-update comment (HTTP ${comment_status})" | ||
| cat /tmp/major-comment.json | ||
| fi | ||
|
|
||
| - name: Log Auto-Merge Decision | ||
| if: always() | ||
| env: | ||
| UPDATE_TYPE: ${{ steps.metadata.outputs.update-type }} | ||
| DEPENDENCY_NAMES: ${{ steps.metadata.outputs.dependency-names }} | ||
| AUTOMERGE_ENABLED: ${{ steps.enable-automerge.outputs.automerge-enabled }} | ||
| run: | | ||
| echo "Auto-merge decision for PR #${{ github.event.pull_request.number }}:" | ||
| echo "- Update type: ${UPDATE_TYPE}" | ||
| echo "- Dependency: ${DEPENDENCY_NAMES}" | ||
| case "${UPDATE_TYPE}" in | ||
| version-update:semver-patch|version-update:semver-minor) | ||
| if [[ "${AUTOMERGE_ENABLED}" == "true" ]]; then | ||
| echo "✅ Auto-merge ENABLED" | ||
| else | ||
| echo "❌ Auto-merge NOT enabled (mutation failed or step skipped)" | ||
| fi | ||
| ;; | ||
| version-update:semver-major) | ||
| echo "❌ Auto-merge DISABLED: major version update" | ||
| ;; | ||
| *) | ||
| echo "❌ Auto-merge DISABLED: unknown update type" | ||
| ;; | ||
| esac |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub has an example of doing this here, which looks a bit simpler. Should we follow this? https://docs.github.com/en/code-security/tutorials/secure-your-dependencies/automate-dependabot-with-actions#enabling-automerge-on-a-pull-request