Skip to content

Commit

Permalink
ci: handle cherry-pick marker label in release automation (determined…
Browse files Browse the repository at this point in the history
…-ai#6911)

Following on from determined-ai#6867, this adds some more steps to the release
automation. The workflows now handle a special label that marks a PR as
a fix to be cherry-picked for the current release. There's also
scaffolding for some future steps for actually handling the
cherry-picks; some of that implementation is left stubbed out for now,
but I believe this should cover the full shape of the Actions lifecycle
we have in mind. Remaining work will lie in filling in that
implementation and updating rph to handle the human side of things.
  • Loading branch information
dzhu authored May 22, 2023
1 parent 8666415 commit 2cdb946
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 103 deletions.
46 changes: 35 additions & 11 deletions .github/workflows/track-prs-for-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,38 @@ on: # yamllint disable-line rule:truthy
pull_request_target:
types:
- closed
- labeled
- unlabeled
branches:
- main

# All jobs require a specifically generated token to run, since we want to
# access org-level projects and the normal GITHUB_TOKEN only has access to this
# repository.

jobs:
add_merged_pr_to_release_project:
if: github.base_ref == 'main' && github.event.pull_request.merged
handle_merged_pr:
if: github.event.action == 'closed' && github.event.pull_request.merged
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.base_ref }}
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1.8.0
with:
app_id: ${{ secrets.RELEASE_APP_ID }}
private_key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Handle merged PR
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
PR_ID: ${{ github.event.pull_request.node_id }}
run: tools/scripts/track-pr pr-merged "$PR_ID"

handle_labeled_pr:
if: github.event.action == 'labeled' || github.event.action == 'unlabeled'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -17,17 +45,13 @@ jobs:
ref: ${{ github.base_ref }}
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92
uses: tibdex/github-app-token@v1.8.0
with:
app_id: ${{ secrets.RELEASE_APP_ID }}
private_key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Add PR to release project
- name: Handle labeled PR
env:
# Since we want to access org-level projects, the normal GITHUB_TOKEN
# won't work -- it only has access to this repository.
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
PR_NUM: ${{ github.event.number }}
PR_REPO: ${{ github.event.repository.name }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: tools/scripts/add-pr-to-release-project.sh
PR_ID: ${{ github.event.pull_request.node_id }}
PR_LABEL: ${{ github.event.label.name }}
run: tools/scripts/track-pr pr-${{ github.event.action }} "$PR_ID" "$PR_LABEL"
92 changes: 0 additions & 92 deletions tools/scripts/add-pr-to-release-project.sh

This file was deleted.

223 changes: 223 additions & 0 deletions tools/scripts/gql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import os
from typing import Any

import requests

GRAPHQL_URL = "https://api.github.com/graphql"

DEBUG = os.environ.get("DET_DEBUG") == "1"


class GraphQLQuery(str):
def __call__(self, **args: Any) -> Any:
if DEBUG:
print("================ GraphQL query")
print(self.strip())
print(args)
r = requests.post(
GRAPHQL_URL,
headers={"Authorization": "bearer " + os.environ["GITHUB_TOKEN"]},
json={"query": self, "variables": args},
)
r.raise_for_status()
j = r.json()
if DEBUG:
print(j)
try:
return j["data"]
except Exception:
print(j)
raise


get_repo_id = GraphQLQuery(
"""
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
id
}
}
"""
)

get_pr_id = GraphQLQuery(
"""
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
id
}
}
}
"""
)


search_projects = GraphQLQuery(
"""
query($owner: String!, $q: String!) {
organization(login: $owner) {
projectsV2(query: $q, first: 100) {
nodes {
id
title
}
}
}
}
"""
)

get_project_status_field = GraphQLQuery(
"""
query($project: ID!) {
node(id: $project) {
... on ProjectV2 {
field(name: "Status") {
... on ProjectV2SingleSelectField {
id
options {
id
name
}
}
}
}
}
}
"""
)

create_issue = GraphQLQuery(
"""
mutation($repo: ID!, $title: String!, $body: String!) {
createIssue(input: {repositoryId: $repo, title: $title, body: $body}) {
issue {
id
}
}
}
"""
)

add_item_to_project = GraphQLQuery(
"""
mutation($project: ID!, $item: ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $item}) {
item {
id
}
}
}
"""
)

get_status_field_info = GraphQLQuery(
"""
query($project: ID!) {
node(id: $project) {
... on ProjectV2 {
field(name: "Status") {
... on ProjectV2SingleSelectField {
id
options {
id
name
}
}
}
}
}
}
"""
)

set_project_item_status = GraphQLQuery(
"""
mutation($project: ID!, $item: ID!, $field: ID!, $value: String) {
updateProjectV2ItemFieldValue(
input: {
projectId: $project, itemId: $item, fieldId: $field, value: {singleSelectOptionId: $value}
}
) {
projectV2Item {
id
}
}
}
"""
)

get_pr_labels = GraphQLQuery(
"""
query($id: ID!) {
node(id: $id) {
... on PullRequest {
labels(first: 100) {
nodes {
name
}
}
}
}
}
"""
)

get_pr_merge_commit = GraphQLQuery(
"""
query($id: ID!) {
node(id: $id) {
... on PullRequest {
mergeCommit {
oid
}
}
}
}
"""
)

get_pr_info = GraphQLQuery(
"""
query($id: ID!) {
node(id: $id) {
... on PullRequest {
number
title
url
repository {
owner {
login
}
name
}
}
}
}
"""
)


get_pr_state = GraphQLQuery(
"""
query($id: ID!) {
node(id: $id) {
... on PullRequest {
state
}
}
}
"""
)


delete_project_item = GraphQLQuery(
"""
mutation($project: ID!, $item: ID!) {
deleteProjectV2Item(input: {projectId: $project, itemId: $item}) {
deletedItemId
}
}
"""
)
Loading

0 comments on commit 2cdb946

Please sign in to comment.