Skip to content

Commit

Permalink
Verify Emoji with GH actions
Browse files Browse the repository at this point in the history
This introduces a GitHub action that verifies emoji.  We could move this
to prow, but in the mean time, it can live here.
  • Loading branch information
DirectXMan12 committed Jun 6, 2019
1 parent b88347b commit 17e0976
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
workflow "PR Checks" {
on = "pull_request"
resolves = ["verify-emoji"]
}

action "verify-emoji" {
uses = "./hack/release"
secrets = ["GITHUB_TOKEN"]
}
13 changes: 13 additions & 0 deletions hack/release/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM k8s.gcr.io/debian-base:v1.0.0

LABEL com.github.actions.name="KubeBuilder PR Emoji"
LABEL com.github.actions.name="Verify that KubeBuilder release notes emoji are present on the PR"
LABEL com.github.actions.icon="git-pull-request"
LABEL com.github.actions.color="blue"

RUN apt-get update -y && apt-get install -y bash jq curl

COPY common.sh /common.sh
COPY verify-emoji.sh /verify-emoji.sh

ENTRYPOINT ["/verify-emoji.sh"]
1 change: 1 addition & 0 deletions hack/release/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cr_minor_pattern=":sparkles:|$(printf "\xe2\x9c\xa8")"
cr_patch_pattern=":bug:|$(printf "\xf0\x9f\x90\x9b")"
cr_docs_pattern=":book:|$(printf "\xf0\x9f\x93\x96")"
cr_other_pattern=":running:|$(printf "\xf0\x9f\x8f\x83")"
cr_all_pattern="${cr_major_pattern}|${cr_minor_pattern}|${cr_patch_pattern}|${cr_docs_pattern}|${cr_other_pattern}"

# cr::symbol-type-raw turns :xyz: and the corresponding emoji
# into one of "major", "minor", "patch", "docs", "other", or
Expand Down
29 changes: 29 additions & 0 deletions hack/release/verify-emoji.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

pr_title=$(jq -r '.pull_request.title' < ${GITHUB_EVENT_PATH})

read pr_prefix rest <<<${pr_title}

source "$(dirname ${BASH_SOURCE})/common.sh"

pr_type=$(cr::symbol-type ${pr_prefix})

summary=""
conclusion="success"
if [[ ${pr_type} == "unknown" ]]; then
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."
conclusion="failure"
else
summary="PR is a ${pr_type} change (${pr_prefix})."
fi

# get the PR (the PR sent from the event has the base branch head as the head)
base_link=$(jq -r '.pull_request.url' < ${GITHUB_EVENT_PATH})
head_commit=$(curl -H "Authorization: Bearer ${GITHUB_TOKEN}" -H 'Accept: application/vnd.github.antiope-preview+json' -q ${base_link} | jq -r '.head.sha')
echo "head commit is ${head_commit}"

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}"'"}}'

0 comments on commit 17e0976

Please sign in to comment.