Skip to content

Commit

Permalink
automerge Helm release PRs after Docker images have been released to …
Browse files Browse the repository at this point in the history
…Docker Hub (#3239)

# What this PR does

See [this](https://drone.grafana.net/grafana/oncall/2896/1/4) Drone job
as an example output of what this build step looks like

Closes #3216
  • Loading branch information
joeyorlando authored Nov 1, 2023
1 parent 341f4fa commit 57e53f5
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ steps:
depends_on:
- set engine version

- name: merge helm release oss pr
image: alpine
environment:
GITHUB_API_KEY:
from_secret: github_api_token
# Allow this step to fail as it's not critical to the build process and we don't want to block
# the build promotion. If this step fails we can always merge the PR manually
failure: ignore
commands:
# yamllint disable rule:line-length
- apk add --no-cache curl jq
# Step 1. Fetch PRs from GitHub's API that're open and have a particular head ref indicative of a helm release PR
# API docs - https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
# NOTE: ${DRONE_TAG:1} will slice off the "v" prefix from the tag
- 'curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $${GITHUB_API_KEY}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/grafana/oncall/pulls?head=grafana:helm-release/$${DRONE_TAG:1}&state=open" > prs.json'
- cat prs.json
# Step 2. Extract the PR number from the first PR in the list to be able to pass that to the next API call
- cat prs.json | jq -r ".[0].number" > pr_number.txt
- cat pr_number.txt
# Step 3. Merge the PR (https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request)
- 'cat pr_number.txt | xargs -r -I{pull_number} curl -L -X PUT -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $${GITHUB_API_KEY}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/grafana/oncall/pulls/{pull_number}/merge"'
# yamllint enable rule:line-length
depends_on:
- build and push docker image

trigger:
event:
- promote
Expand Down Expand Up @@ -327,8 +352,14 @@ get:
path: infra/data/ci/drone
kind: secret
name: drone_token

---
# GitHub API token (only scoped to grafana/oncall + PR access)
get:
name: github-api-token
path: ci/data/repo/grafana/oncall/drone
kind: secret
name: github_api_token
---
kind: signature
hmac: 8b387638ef35f86ed9f8c8c964726e0ae703beb7d0f18e053b5041ab8ee9bed2

...
hmac: 9cc2cc2db01455d34768577047f8069d19c0573b6a05dd26c88b9deb3af3a0c9

0 comments on commit 57e53f5

Please sign in to comment.