Skip to content

Commit 4a6d739

Browse files
committed
Add release script
Add a release script that streamline how we want to do the release. All the documentation should be in the README. This create a VERSION file and push the tag which would then get picked up by gorelease. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 6d40c8e commit 4a6d739

File tree

2 files changed

+157
-41
lines changed

2 files changed

+157
-41
lines changed

tekton/README.md

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,33 @@ them manually.
1515

1616
## Release Pipeline
1717

18-
The release pipeline uses the
19-
[`golang`](https://github.com/tektoncd/catalog/tree/master/golang)
20-
Tasks from the
21-
[`tektoncd/catalog`](https://github.com/tektoncd/catalog). To add them
22-
to your cluster:
18+
You can use the script [`./release.sh`](release.sh) that would do everything
19+
that needs to be done for the release.
2320

24-
```
25-
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/golang/lint.yaml
26-
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/golang/build.yaml
27-
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/golang/tests.yaml
28-
```
21+
The first argument if not provided is the release version you want to do, it
22+
need to respect a format like `v1.2.3` which is basically SEMVER.
2923

30-
It also uses the [`goreleaser`](./goreleaser.yml) Task from this
31-
repository.
24+
If it detects that you are doing a minor release it would ask you for some
25+
commits to be cherry-picked in this release. Alternatively you can provide the
26+
commits separed by a space to the second argument of the script. You do need to
27+
make sure to provide them in order from the oldest to the newest (as listed).
3228

33-
```
34-
kubectl apply -f ./goreleaser.yml
35-
```
29+
If you give the `*` argument for the commits to pick up it would apply all the new
30+
commits.
3631

37-
Next is the actual release pipeline. It is defined in
38-
[`release-pipeline.yml`](./release-pipeline.yml).
32+
It will them use your TektonCD cluster and apply what needs to be done for
33+
running the release.
3934

40-
```
41-
kubectl apply -f ./release-pipeline.yml
42-
```
35+
And finally it will launch the `tkn` cli to show the logs.
4336

44-
Note that the [`goreleaser.yml`](./goreleaser.yml) `Task` needs a
45-
secret for the GitHub token, named `bot-token-github`.
37+
Make sure we have a nice ChangeLog before doign the release, listing `features`
38+
and `bugs` and be thankful to the contributors by listing them.
4639

47-
TODO(vdemeester): It is hardcoded for now as Tekton Pipeline doesn't
48-
support variable interpolation in the environment. This needs to be
49-
fixed upstream.
40+
## Debugging
5041

51-
```
52-
kubectl create secret generic bot-token-github --from-literal=bot-token=${GITHUB_TOKEN}
53-
```
42+
You can define the env variable `PUSH_REMOTE` to push to your own remote (i.e:
43+
which pont to your username on github),
5444

55-
56-
### Running
57-
58-
To run these `Pipelines` and `Tasks`, you must have Tekton Pipelines installed
59-
(in your own kubernetes cluster) either via
60-
[an official release](https://github.com/tektoncd/pipeline/blob/master/docs/install.md)
61-
or
62-
[from `HEAD`](https://github.com/tektoncd/pipeline/blob/master/DEVELOPMENT.md#install-pipeline).
63-
64-
- [`release-pipeline-run.yml`](./release-pipeline-run.yml) — this
65-
runs the `ci-release-pipeline` on `tektoncd/cli` master branch. The
66-
way [`goreleaser`](https://goreleaser.com) works, it will build the
67-
latest tag.
45+
You need to be **careful** if you have write access to the `homebrew` repository, it
46+
would do a release there. Until we can find a proper fix I would generate a
47+
commit which remove the brews data and cherry-pick it in the script.

tekton/release.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/usr/bin/env bash
2+
RELEASE_VERSION="${1}"
3+
COMMITS="${2}"
4+
5+
UPSTREAM_REMOTE=upstream
6+
MASTER_BRANCH="master"
7+
TARGET_NAMESPACE="release"
8+
SECRET_NAME=bot-token-github
9+
PUSH_REMOTE="${PUSH_REMOTE:-${UPSTREAM_REMOTE}}" # export PUSH_REMOTE to your own for testing
10+
11+
CATALOG_TASKS="lint build tests"
12+
13+
set -e
14+
15+
[[ -z ${RELEASE_VERSION} ]] && {
16+
read -e -p "Enter a target release (i.e: v0.1.2): " RELEASE_VERSION
17+
[[ -z ${RELEASE_VERSION} ]] && { echo "no target release"; exit 1 ;}
18+
}
19+
20+
[[ ${RELEASE_VERSION} =~ v[0-9]+\.[0-9]*\.[0-9]+ ]] || { echo "invalid version provided, need to match v\d+\.\d+\.\d+"; exit 1 ;}
21+
lasttag=$(git describe --abbrev=0 --tags)
22+
echo ${lasttag}|sed 's/\.[0-9]*$//'|grep -q ${RELEASE_VERSION%.*} && { echo "Minor version of ${RELEASE_VERSION%.*} detected"; minor_version=true ; }
23+
24+
cd ${GOPATH}/src/github.com/tektoncd/cli
25+
26+
git fetch -a ${UPSTREAM_REMOTE} >/dev/null
27+
git checkout ${MASTER_BRANCH}
28+
git reset --hard ${UPSTREAM_REMOTE}/${MASTER_BRANCH}
29+
git checkout -B release-${RELEASE_VERSION} ${MASTER_BRANCH} >/dev/null
30+
31+
if [[ -n ${minor_version} ]];then
32+
git reset --hard ${lasttag} >/dev/null
33+
34+
if [[ -z ${COMMITS} ]];then
35+
echo "Showing commit between last minor tag '${lasttag} to '${MASTER_BRANCH}'"
36+
echo
37+
git log --reverse --no-merges --pretty=format:"%h | %s | %cd | %ae" ${lasttag}..${MASTER_BRANCH}
38+
echo
39+
read -e -p "Pick a list of ordered commits to cherry-pick space separated (* mean all of them): " COMMITS
40+
fi
41+
[[ -z ${COMMITS} ]] && { echo "no commits picked"; exit 1;}
42+
if [[ ${COMMITS} == "*" ]];then
43+
COMMITS=$(git log --reverse --no-merges --pretty=format:"%h" ${lasttag}..${MASTER_BRANCH})
44+
fi
45+
for commit in ${COMMITS};do
46+
git branch --contains ${commit} >/dev/null || { echo "Invalid commit ${commit}" ; exit 1;}
47+
echo "Cherry-picking commit: ${commit}"
48+
git cherry-pick ${commit} >/dev/null
49+
done
50+
51+
else
52+
echo "Major release ${RELEASE_VERSION%.*} detected: picking up ${UPSTREAM_REMOTE}/${MASTER_BRANCH}"
53+
git reset --hard ${UPSTREAM_REMOTE}/${MASTER_BRANCH}
54+
fi
55+
56+
# TODO: toremove! this is temporary to disable the upload to homebrew
57+
# need to find a way how to do this automatically (push to upstream/revert and
58+
# then being able to cherry-pick if $PUSH_REMOTE != 'upstream/origin'?)
59+
# git cherry-pick 052b0b4ce989fe9aee01027e67e61538b48e1179
60+
61+
# Add our VERSION so Makefile will pick it up when compiling
62+
echo ${RELEASE_VERSION} > VERSION
63+
git add VERSION
64+
git commit -sm "New version ${RELEASE_VERSION}" -m "${COMMITS}" VERSION
65+
git tag --sign -m \
66+
"New version ${RELEASE_VERSION}
67+
COMMITS:
68+
$(git log --reverse --no-merges --pretty=format:"%h | %s | %cd | %ae" ${lasttag}..${MASTER_BRANCH})" \
69+
--force ${RELEASE_VERSION}
70+
71+
git push --force ${PUSH_REMOTE} ${RELEASE_VERSION}
72+
73+
kubectl version 2>/dev/null >/dev/null || {
74+
echo "you need to have access to a kubernetes cluster"
75+
exit 1
76+
}
77+
78+
kubectl get pipelineresource 2>/dev/null >/dev/null || {
79+
echo "you need to have tekton install onto the cluster"
80+
exit 1
81+
}
82+
83+
kubectl create ${TARGET_NAMESPACE} 2>/dev/null || true
84+
85+
for task in ${CATALOG_TASKS};do
86+
kubectl -n ${TARGET_NAMESPACE} apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/golang/${task}.yaml
87+
done
88+
89+
kubectl -n ${TARGET_NAMESPACE} apply -f ./tekton/goreleaser.yml
90+
91+
if ! kubectl get secret ${SECRET_NAME} -o name >/dev/null 2>/dev/null;then
92+
github_token=$(git config --get github.oauth-token || true)
93+
94+
[[ -z ${github_token} ]] && {
95+
read -e -p "Enter your Github Token: " github_token
96+
[[ -z ${github_token} ]] && { echo "no token provided"; exit 1;}
97+
}
98+
99+
kubectl -n ${TARGET_NAMESPACE} create secret generic ${SECRET_NAME} --from-literal=bot-token=${github_token}
100+
fi
101+
102+
kubectl -n ${TARGET_NAMESPACE} apply -f ./tekton/release-pipeline.yml
103+
104+
# Until tkn supports tkn create with parameters we do like this,
105+
cat <<EOF | kubectl -n ${TARGET_NAMESPACE} apply -f-
106+
apiVersion: tekton.dev/v1alpha1
107+
kind: PipelineResource
108+
metadata:
109+
name: tektoncd-cli-git
110+
spec:
111+
type: git
112+
params:
113+
- name: revision
114+
value: ${RELEASE_VERSION}
115+
- name: url
116+
value: $(git remote get-url ${PUSH_REMOTE}|sed 's,git@github.com:,https://github.com/,')
117+
EOF
118+
119+
# Start the pipeline, We can't use tkn start because until #272 and #262 are imp/fixed
120+
cat <<EOF | kubectl -n ${TARGET_NAMESPACE} create -f-
121+
apiVersion: tekton.dev/v1alpha1
122+
kind: PipelineRun
123+
metadata:
124+
generateName: cli-release-pipeline-run
125+
spec:
126+
pipelineRef:
127+
name: cli-release-pipeline
128+
resources:
129+
- name: source-repo
130+
resourceRef:
131+
name: tektoncd-cli-git
132+
EOF
133+
134+
type -p tkn >/dev/null 2>/dev/null || { echo "Could not find the 'tkn' binary, you are on your own buddy"; exit 0 ;}
135+
136+
tkn pipeline logs cli-release-pipeline -f

0 commit comments

Comments
 (0)