/
7-tag-release.yaml
106 lines (102 loc) · 3.19 KB
/
7-tag-release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: ibm-tag-release
annotations:
description: Tags the git repository with the next version release value
app.openshift.io/description: Tags the git repository with the next version release value
app.openshift.io/vcs-uri: https://github.com/IBM/ibm-garage-tekton-tasks
app.openshift.io/vcs-ref: master
labels:
version: 0.0.0
spec:
params:
- name: git-url
- name: git-revision
default: master
- name: source-dir
default: /source
- name: skip-push
default: ""
- name: js-image
default: quay.io/ibmgaragecloud/node:lts-stretch
results:
- name: tag
volumes:
- name: source
emptyDir: {}
stepTemplate:
volumeMounts:
- name: source
mountPath: $(params.source-dir)
steps:
- name: git-clone
image: quay.io/ibmgaragecloud/alpine-git
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: GIT_PASSWORD
valueFrom:
secretKeyRef:
name: git-credentials
key: password
optional: true
- name: GIT_USERNAME
valueFrom:
secretKeyRef:
name: git-credentials
key: username
optional: true
script: |
set +x
if [[ -n "${GIT_USERNAME}" ]] && [[ -n "${GIT_PASSWORD}" ]]; then
git clone "$(echo $(params.git-url) | awk -F '://' '{print $1}')://${GIT_USERNAME}:${GIT_PASSWORD}@$(echo $(params.git-url) | awk -F '://' '{print $2}')" $(params.source-dir)
else
set -x
git clone $(params.git-url) $(params.source-dir)
fi
set -x
cd $(params.source-dir)
git checkout $(params.git-revision)
# Need to create branch to make release-it work
git switch -c local
- name: git-tag
image: $(params.js-image)
workingDir: $(params.source-dir)
script: |
#!/usr/bin/env bash
set -ex
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
git fetch --tags
git config --global user.email "cloud-native-toolkit@example.com"
git config --global user.name "Cloud Native Toolkit Pipeline"
if [[ $(git describe --tag `git rev-parse HEAD`) =~ (^[0-9]+.[0-9]+.[0-9]+$) ]]; then
echo "Latest commit is already tagged"
NEW_TAG="$(git describe --abbrev=0 --tags)"
echo -n "${NEW_TAG}" | tee $(results.tag.path)
exit 0
fi
mkdir -p ~/.npm
npm config set prefix ~/.npm
export PATH=$PATH:~/.npm/bin
npm i -g release-it
release-it patch \
--ci \
--no-npm \
--no-git.push \
--no-git.requireCleanWorkingDir \
--no-git.requireUpstream \
-VV
if [[ -z "$(params.skip-push)" ]]; then
set +x
git push --tags -v
set -x
fi
NEW_TAG="$(git describe --abbrev=0 --tags)"
if [[ -z "${NEW_TAG}" ]]; then
echo "Error: NEW_TAG not defined"
exit 1
fi
echo -n "${NEW_TAG}" | tee $(results.tag.path)