Skip to content

Commit cd4692d

Browse files
authored
Merge pull request kubernetes-sigs#474 from DirectXMan12/infra/verify-emoji
🏃 Verify Emoji with GH actions
2 parents aa16141 + 17e0976 commit cd4692d

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

.github/main.workflow

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
workflow "PR Checks" {
2+
on = "pull_request"
3+
resolves = ["verify-emoji"]
4+
}
5+
6+
action "verify-emoji" {
7+
uses = "./hack/release"
8+
secrets = ["GITHUB_TOKEN"]
9+
}

hack/release/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM k8s.gcr.io/debian-base:v1.0.0
2+
3+
LABEL com.github.actions.name="KubeBuilder PR Emoji"
4+
LABEL com.github.actions.name="Verify that KubeBuilder release notes emoji are present on the PR"
5+
LABEL com.github.actions.icon="git-pull-request"
6+
LABEL com.github.actions.color="blue"
7+
8+
RUN apt-get update -y && apt-get install -y bash jq curl
9+
10+
COPY common.sh /common.sh
11+
COPY verify-emoji.sh /verify-emoji.sh
12+
13+
ENTRYPOINT ["/verify-emoji.sh"]

hack/release/common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cr_patch_pattern=":bug:|$(printf "\xf0\x9f\x90\x9b")"
77
cr_docs_pattern=":book:|$(printf "\xf0\x9f\x93\x96")"
88
cr_no_release_note_pattern=":ghost:|$(printf "\xf0\x9f\x91\xbb")"
99
cr_other_pattern=":running:|$(printf "\xf0\x9f\x8f\x83")"
10+
cr_all_pattern="${cr_major_pattern}|${cr_minor_pattern}|${cr_patch_pattern}|${cr_docs_pattern}|${cr_other_pattern}"
1011

1112
# cr::symbol-type-raw turns :xyz: and the corresponding emoji
1213
# into one of "major", "minor", "patch", "docs", "other", or

hack/release/verify-emoji.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
pr_title=$(jq -r '.pull_request.title' < ${GITHUB_EVENT_PATH})
7+
8+
read pr_prefix rest <<<${pr_title}
9+
10+
source "$(dirname ${BASH_SOURCE})/common.sh"
11+
12+
pr_type=$(cr::symbol-type ${pr_prefix})
13+
14+
summary=""
15+
conclusion="success"
16+
if [[ ${pr_type} == "unknown" ]]; then
17+
summary="You must specify an emoji at the beginning of the PR to indicate what kind of change this is.\nValid emoji: ${cr_all_pattern}.\nYou specified '${pr_prefix}'.\nSee VERSIONING.md for more information."
18+
conclusion="failure"
19+
else
20+
summary="PR is a ${pr_type} change (${pr_prefix})."
21+
fi
22+
23+
# get the PR (the PR sent from the event has the base branch head as the head)
24+
base_link=$(jq -r '.pull_request.url' < ${GITHUB_EVENT_PATH})
25+
head_commit=$(curl -H "Authorization: Bearer ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.antiope-preview+json' -q ${base_link} | jq -r '.head.sha')
26+
echo "head commit is ${head_commit}"
27+
28+
curl https://api.github.com/repos/${GITHUB_REPOSITORY}/check-runs -XPOST -H "Authorization: Bearer ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.antiope-preview+json' -H 'Content-Type: application/json' -q --data-raw '{"name": "Verify Emoji", "head_sha": "'${head_commit}'", "conclusion": "'${conclusion}'", "status": "completed", "completed_at": "'$(date -Iseconds)'", "output": {"title": "Verify Emoji", "summary": "'"${summary}"'"}}'
29+

0 commit comments

Comments
 (0)