Skip to content

Commit f60c87e

Browse files
authored
Merge pull request #475 from kubernetes-sigs/master
👻 ff release-0.2 branch to master
2 parents 38483b2 + be010e1 commit f60c87e

File tree

22 files changed

+439
-87
lines changed

22 files changed

+439
-87
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+
}

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ Please see https://git.k8s.io/community/CLA.md for more info
1919
1. Setup tools
2020
```bash
2121
$ go get -u github.com/golang/dep/cmd/dep
22-
$ go get -u gopkg.in/alecthomas/gometalinter.v2
23-
$ gometalinter.v2 --install # if can't load package, refer: https://github.com/alecthomas/gometalinter/issues/404
22+
$ curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.15.0
2423
```
2524
1. Test
2625
```bash
27-
TRACE=1 ./hack/check-everything.sh
26+
GO111MODULE=on TRACE=1 ./hack/check-everything.sh
2827
```
2928

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VERSIONING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ a:
9292
- Patch fix: :bug: (`:bug:`)
9393
- Docs: :book: (`:book:`)
9494
- Infra/Tests/Other: :running: (`:running:`)
95+
- No release note: :ghost: (`:ghost:`)
96+
97+
Use :ghost: (no release note) only for the PRs that change or revert unreleased
98+
changes, which don't deserve a release note. Please don't abuse it.
9599

96100
You can also use the equivalent emoji directly, since GitHub doesn't
97101
render the `:xyz:` aliases in PR titles.

examples/builtins/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func main() {
5353
os.Exit(1)
5454
}
5555

56-
// Setup a new controller to Reconciler ReplicaSets
56+
// Setup a new controller to reconcile ReplicaSets
5757
entryLog.Info("Setting up controller")
5858
c, err := controller.New("foo-controller", mgr, controller.Options{
5959
Reconciler: &reconcileReplicaSet{client: mgr.GetClient(), log: log.WithName("reconciler")},

examples/crd/pkg/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type ChaosPodList struct {
6161
Items []ChaosPod `json:"items"`
6262
}
6363

64+
// +kubebuilder:webhook:failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=vchaospod.kb.io,path=/validate-chaosapps-metamagical-io-v1-chaospod,mutating=false
65+
66+
var _ webhook.Validator = &ChaosPod{}
67+
6468
// ValidateCreate implements webhookutil.validator so a webhook will be registered for the type
6569
func (c *ChaosPod) ValidateCreate() error {
6670
log.Info("validate create", "name", c.Name)
@@ -89,6 +93,8 @@ func (c *ChaosPod) ValidateUpdate(old runtime.Object) error {
8993
return nil
9094
}
9195

96+
// +kubebuilder:webhook:failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=mchaospod.kb.io,path=/mutate-chaosapps-metamagical-io-v1-chaospod,mutating=true
97+
9298
var _ webhook.Defaulter = &ChaosPod{}
9399

94100
// Default implements webhookutil.defaulter so a webhook will be registered for the type

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: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ cr_major_pattern=":warning:|$(printf "\xe2\x9a\xa0")"
55
cr_minor_pattern=":sparkles:|$(printf "\xe2\x9c\xa8")"
66
cr_patch_pattern=":bug:|$(printf "\xf0\x9f\x90\x9b")"
77
cr_docs_pattern=":book:|$(printf "\xf0\x9f\x93\x96")"
8+
cr_no_release_note_pattern=":ghost:|$(printf "\xf0\x9f\x91\xbb")"
89
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}"
911

1012
# cr::symbol-type-raw turns :xyz: and the corresponding emoji
1113
# into one of "major", "minor", "patch", "docs", "other", or
@@ -24,6 +26,9 @@ cr::symbol-type-raw() {
2426
@(${cr_docs_pattern})?('!'))
2527
echo "docs"
2628
;;
29+
@(${cr_no_release_note_pattern})?('!'))
30+
echo "no_release_note"
31+
;;
2732
@(${cr_other_pattern})?('!'))
2833
echo "other"
2934
;;
@@ -66,6 +71,52 @@ git::ensure-release-branch() {
6671
fi
6772
}
6873
74+
# git::export-version-from-branch outputs the current version
75+
# for the given branch (as the argument) as exported variables
76+
# (${maj,min,patch}_ver, last_tag).
77+
git::export-version-from-branch() {
78+
local target_branch=${1?must specify a branch}
79+
local current_branch=$(git branch --show-current -q)
80+
81+
local expected_maj_ver
82+
local expected_min_ver
83+
if [[ ${target_branch} =~ release-0.([[:digit:]]+) ]]; then
84+
expected_maj_ver=0
85+
expected_min_ver=${BASH_REMATCH[1]}
86+
elif [[ ${target_branch} =~ release-([[:digit:]]+) ]]; then
87+
expected_maj_ver=${BASH_REMATCH[1]}
88+
else
89+
echo "branch ${target_branch} does not appear to be for a release -- it should be release-X or release-0.Y" >&2
90+
exit 1
91+
fi
92+
93+
local tag_pattern='v([[:digit:]]+).([[:digit:]]+).([[:digit:]]+)'
94+
95+
git checkout -q ${target_branch}
96+
97+
# make sure we've got a tag that matches *some* release
98+
last_tag=$(git describe --tags --abbrev=0) # try to fetch just the "current" tag name
99+
if [[ ! ${last_tag} =~ ${tag_pattern} ]]; then
100+
# it's probably for a previous version
101+
echo "tag ${last_tag} does not appear to be for a release -- it should be vX.Y.Z" >&2
102+
git checkout -q ${current_branch}
103+
exit 1
104+
fi
105+
106+
export min_ver=${BASH_REMATCH[2]}
107+
export patch_ver=${BASH_REMATCH[3]}
108+
export maj_ver=${BASH_REMATCH[1]}
109+
export last_tag=${last_tag}
110+
111+
if ${2:-1} && ([[ ${maj_ver} != ${expected_maj_ver} ]] || [[ ${maj_ver} == 0 && ${min_ver} != ${expected_min_ver} ]]); then
112+
echo "tag ${last_tag} does not appear to be for a the right release (${target_branch})" >&2
113+
git checkout ${current_branch}
114+
exit 1
115+
fi
116+
117+
git checkout -q ${current_branch}
118+
}
119+
69120
# git::export-current-version outputs the current version
70121
# as exported variables (${maj,min,patch}_ver, last_tag) after
71122
# checking that we're on the right release branch.
@@ -75,25 +126,26 @@ git::export-current-version() {
75126
76127
# deal with the release-0.1 branch, or similar
77128
local release_ver=${BASH_REMATCH[1]}
78-
maj_ver=${release_ver}
79-
local tag_pattern='v${maj_ver}.([[:digit:]]+).([[:digit]]+)'
80-
if [[ ${maj_ver} =~ 0\.([[:digit:]]+) ]]; then
81-
maj_ver=0
82-
min_ver=${BASH_REMATCH[1]}
83-
local tag_pattern="v0.(${min_ver}).([[:digit:]]+)"
129+
local expected_maj_ver=${release_ver}
130+
if [[ ${expected_maj_ver} =~ 0\.([[:digit:]]+) ]]; then
131+
expected_maj_ver=0
132+
local expected_min_ver=${BASH_REMATCH[1]}
84133
fi
85134
86-
# make sure we've got a tag that matches our release branch
87-
last_tag=$(git describe --tags --abbrev=0) # try to fetch just the "current" tag name
88-
if [[ ! ${last_tag} =~ ${tag_pattern} ]]; then
89-
echo "tag ${last_tag} does not appear to be a release for this release (${release_ver})-- it should be v${maj_ver}.Y.Z" >&2
90-
exit 1
135+
git::export-version-from-branch "release-${release_ver}" false
136+
137+
local last_tag_branch=""
138+
if [[ ${maj_ver} == "0" && ${min_ver} -eq $((expected_min_ver-1)) ]]; then
139+
echo "most recent tag is a release behind (${last_tag}), checking previous release branch to be safe" >&2
140+
last_tag_branch="release-0.${min_ver}"
141+
elif [[ ${maj_ver} -eq $((expected_maj_ver-1)) ]]; then
142+
echo "most recent tag is a release behind (${last_tag}), checking previous release branch to be safe" >&2
143+
last_tag_branch="release-${maj_ver}"
91144
fi
92145

93-
export min_ver=${BASH_REMATCH[1]}
94-
export patch_ver=${BASH_REMATCH[2]}
95-
export maj_ver=${maj_ver}
96-
export last_tag=${last_tag}
146+
if [[ -n "${last_tag_branch}" ]]; then
147+
git::export-version-from-branch ${last_tag_branch} true
148+
fi
97149
}
98150

99151
# git::next-version figures out the next version to tag

hack/release/release-notes.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ while read commit_word commit; do
5050
patch)
5151
bugfixes="${bugfixes}- ${pr_title} (#${pr_number})${NEWLINE}"
5252
;;
53-
docs|other)
53+
docs|no_release_note|other)
5454
# skip non-code-changes
5555
;;
5656
unknown)
@@ -64,8 +64,8 @@ done <<<$(git rev-list ${last_tag}..HEAD --merges --pretty=format:%B)
6464

6565
# TODO: sort non merge commits with tags
6666

67-
[[ -n "${breaking}" ]] && printf '\e[1;31mbreaking changes this version\e[0m' >&2
68-
[[ -n "${unknown}" ]] && printf '\e[1;35munknown changes in this release -- categorize manually\e[0m' >&2
67+
[[ -n "${breaking}" ]] && printf '\e[1;31mbreaking changes this version\e[0m\n' >&2
68+
[[ -n "${unknown}" ]] && printf '\e[1;35munknown changes in this release -- categorize manually\e[0m\n' >&2
6969

7070
echo "" >&2
7171
echo "" >&2

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)