Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit a0cd385

Browse files
domdom82raghunathd8peanball
authored
ci: add semantic releases (#25)
* ci: add semantic releases Signed-off-by: Dominik Froehlich <[email protected]> Co-authored-by: Raghunath Deshpande <[email protected]> * Apply suggestions from code review Co-authored-by: Alexander Lais <[email protected]> * ci: add semantic-release to Dockerfile * ci: use github token in favor of ssh * ci: fix regex for gcs --------- Signed-off-by: Dominik Froehlich <[email protected]> Co-authored-by: Raghunath Deshpande <[email protected]> Co-authored-by: Alexander Lais <[email protected]>
1 parent fbd3458 commit a0cd385

File tree

7 files changed

+214
-10
lines changed

7 files changed

+214
-10
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
# Dependency directories & default folders/files
1515
.bundle
1616
.dev_builds
17+
.final_builds
1718
pcap-release.tgz
1819
config/private.yml
1920
blobs
2021
dev_releases
2122
vendor
23+
node_modules
24+
package-lock.json
25+
package.json
2226

2327
# Releases/tarballs
2428
.final_builds/jobs/**/*.tgz

.releaserc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"ci": false,
3+
"branches": ["main", {"name": "alpha", "prerelease": true}, {"name": "beta", "prerelease": true}],
4+
"plugins": [
5+
["@semantic-release/commit-analyzer", {
6+
"preset": "angular",
7+
"releaseRules": [
8+
{"type": "dep", "release": "patch"}
9+
],
10+
"parserOpts": {
11+
"noteKeywords": ["BREAKING CHANGE", "BREAKING-CHANGE"]
12+
}
13+
}],
14+
"@semantic-release/release-notes-generator",
15+
["@semantic-release/exec", {
16+
"verifyReleaseCmd": "bosh -n create-release --final --version ${nextRelease.version} --tarball /tmp/pcap-${nextRelease.gitTag}.tgz",
17+
"publishCmd": "./ci/scripts/publish.sh ${nextRelease.gitTag}",
18+
"generateNotesCmd": "./ci/scripts/notes.sh ${nextRelease.gitTag} ${nextRelease.version}"
19+
}],
20+
["@semantic-release/github", {
21+
"assets": [
22+
{"path": "/tmp/pcap-*.tgz"}
23+
]
24+
}]
25+
]
26+
}

ci/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ ARG GINKGO_VERSION=latest
55
ARG GOLANGCILINT_VERSION=latest
66
RUN apt-get update && apt-get install -y libpcap-dev && rm -rf /var/lib/apt/lists/*
77

8+
RUN curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash - && \
9+
apt-get install -y nodejs && rm -rf /var/lib/apt/lists/*
10+
11+
RUN npm install -g semantic-release && \
12+
npm install -g @semantic-release/exec
13+
814
RUN rm -rf /usr/local/go
915
COPY --from=golang:1.20 /usr/local/go/ /usr/local/go/
1016
ENV GOPATH=/go PATH=${PATH}:/go/bin

ci/pipeline.yml

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ groups:
44
jobs:
55
- unit-tests
66
- unit-tests-pr
7+
- shipit
8+
- rc
79

810
jobs:
911
- name: unit-tests
@@ -54,7 +56,7 @@ jobs:
5456
args: []
5557
params:
5658
REPO_ROOT: git
57-
on_failure: # TODO channel doesn't exist (yet?)
59+
on_failure:
5860
put: notify
5961
params:
6062
channel: "#pcap-release"
@@ -126,6 +128,84 @@ jobs:
126128
status: failure
127129
context: unit-tests
128130

131+
- name: shipit
132+
public: true
133+
serial: true
134+
plan:
135+
- do:
136+
- in_parallel:
137+
- { get: git, passed: [rc] }
138+
- task: release
139+
config:
140+
platform: linux
141+
image_resource:
142+
type: docker-image
143+
source:
144+
repository: cf-routing.common.repositories.cloud.sap/pcap-release-testflight
145+
tag: latest
146+
username: ((docker.username))
147+
password: ((docker.password))
148+
inputs:
149+
- name: git
150+
outputs:
151+
- name: gh
152+
run:
153+
path: ./git/ci/scripts/shipit
154+
args: []
155+
params:
156+
RELEASE_NAME: pcap-release
157+
REPO_ROOT: git
158+
RELEASE_ROOT: gh
159+
BRANCH: main
160+
GITHUB_OWNER: cloudfoundry
161+
GITHUB_TOKEN: ((github.access_token))
162+
GCP_SERVICE_KEY: ((gcp.service_key))
163+
164+
- put: blobstore
165+
params:
166+
file: "gh/artifacts/pcap-*.tgz"
167+
on_failure:
168+
put: notify
169+
params:
170+
channel: "#pcap-release"
171+
username: ci-bot
172+
icon_url: "((slack.icon))"
173+
text: "((slack.fail_url)) pcap-boshrelease : shipit job failed"
174+
175+
- name: rc
176+
public: true
177+
serial: true
178+
plan:
179+
- do:
180+
- in_parallel:
181+
- { get: git, passed: [unit-tests] }
182+
- task: release-candidate
183+
config:
184+
platform: linux
185+
image_resource:
186+
type: docker-image
187+
source:
188+
repository: cf-routing.common.repositories.cloud.sap/pcap-release-testflight
189+
tag: latest
190+
username: ((docker.username))
191+
password: ((docker.password))
192+
inputs:
193+
- name: git
194+
outputs:
195+
- name: gh
196+
run:
197+
path: ./git/ci/scripts/shipit
198+
args: []
199+
params:
200+
RELEASE_NAME: pcap-release
201+
REPO_ROOT: git
202+
RELEASE_ROOT: gh
203+
BRANCH: main
204+
DRY_RUN: true
205+
GITHUB_OWNER: cloudfoundry
206+
GITHUB_TOKEN: ((github.access_token))
207+
GCP_SERVICE_KEY: ((gcp.service_key))
208+
129209
resource_types:
130210
- name: slack-notification
131211
type: docker-image
@@ -137,22 +217,18 @@ resource_types:
137217
source:
138218
repository: teliaoss/github-pr-resource
139219

140-
# FIXME: Need to use latest version of this resource due to
141-
# https://github.com/concourse/github-release-resource/issues/108
142-
# https://github.com/concourse/github-release-resource/pull/107
143-
# Until Concourse is updated to 7.5.0+
144-
- name: github-release-alt
145-
type: registry-image
220+
- name: gcs
221+
type: docker-image
146222
source:
147-
repository: concourse/github-release-resource
223+
repository: frodenas/gcs-resource
148224

149225
resources:
150226
- name: git
151227
type: git
152228
source:
153-
uri: git@github.com:cloudfoundry/pcap-release.git
229+
uri: https://github.com/cloudfoundry/pcap-release.git
154230
branch: main
155-
private_key: ((github.private_key))
231+
password: ((github.access_token))
156232

157233
- name: git-pull-requests
158234
type: pull-request
@@ -166,3 +242,10 @@ resources:
166242
type: slack-notification
167243
source:
168244
url: ((slack.pcap_release_webhook))
245+
246+
- name: blobstore
247+
type: gcs
248+
source:
249+
bucket: pcap-release
250+
json_key: ((gcp.service_key))
251+
regexp: pcap-v[0-9a-z\.+-]+.tgz

ci/scripts/notes.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
RELEASE_GIT_TAG="${1:?Release Git Tag is mandatory}"
6+
VERSION="${2:?Version defining the target release version is mandatory}"
7+
8+
RELEASE_TGZ="/tmp/pcap-${RELEASE_GIT_TAG}.tgz"
9+
SHA1=$(sha1sum "${RELEASE_TGZ}" | head -n1 | awk '{print $1}')
10+
export SHA1
11+
SHA256=$(sha256sum "${RELEASE_TGZ}" | head -n1 | awk '{print $1}')
12+
export SHA256
13+
14+
cat >> "${CONCOURSE_ROOT}/${RELEASE_ROOT}/notes.md" <<EOF
15+
### Deployment
16+
\`\`\`yaml
17+
releases:
18+
- name: "${RELEASE_NAME}"
19+
version: "${VERSION}"
20+
url: "https://github.com/${GITHUB_OWNER}/${RELEASE_NAME}/releases/download/v${VERSION}/pcap-${RELEASE_GIT_TAG}.tgz"
21+
sha1: "${SHA1}"
22+
23+
# for deployments with sha256, use the following line instead:
24+
# sha1: "sha256:${SHA256}"
25+
\`\`\`
26+
EOF
27+
28+
cat "${CONCOURSE_ROOT}/${RELEASE_ROOT}/notes.md"

ci/scripts/publish.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
RELEASE_GIT_TAG="${1:?Release Git Tag is mandatory}"
6+
mkdir -p "${CONCOURSE_ROOT}/${RELEASE_ROOT}/artifacts"
7+
8+
cp /tmp/pcap-"${RELEASE_GIT_TAG}".tgz "${CONCOURSE_ROOT}/${RELEASE_ROOT}/artifacts/"

ci/scripts/shipit

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
header() {
6+
echo
7+
echo "###############################################"
8+
echo
9+
echo "$*"
10+
echo
11+
}
12+
13+
: "${REPO_ROOT:?required}" # Contains the Git repo
14+
: "${RELEASE_NAME:?required}" # Contains release name
15+
: "${RELEASE_ROOT:?required}" # Contains any information that is passed on to subsequent steps, e.g. GitHub publish
16+
: "${GCP_SERVICE_KEY:?required}" # The GCP service key for accessing the blobstore, written to a temporary private.yml.
17+
: "${GITHUB_TOKEN:?required}" # The github access token
18+
: "${DRY_RUN:=false}" # Whether to do a dry run or a real release
19+
20+
###############################################################
21+
22+
CONCOURSE_ROOT="$(pwd)"
23+
export CONCOURSE_ROOT
24+
25+
DRY_RUN_ARG="--dry-run=$DRY_RUN"
26+
27+
cd "${REPO_ROOT}"
28+
29+
# YAML needs to be indented. The GCP service key is a multiline YAML and needs to be indented uniformly.
30+
# Bash does not allow variables in a sequence literal. $PAD is a 6 spaces indent.
31+
PAD=$(printf ' %.0s' {1..6})
32+
PADDED_GCP_SERVICE_KEY=$(sed -E 's/^(.*)$/'"${PAD}"'\1/g' <<<"${GCP_SERVICE_KEY}")
33+
34+
cat > config/private.yml <<YAML
35+
---
36+
blobstore:
37+
options:
38+
credentials_source: static
39+
json_key: |
40+
${PADDED_GCP_SERVICE_KEY}
41+
YAML
42+
43+
header "Pulling in any git submodules..."
44+
git submodule update --init --recursive --force
45+
cd -
46+
47+
cd "${REPO_ROOT}"
48+
header "Running semantic-release..."
49+
semantic-release "$DRY_RUN_ARG"

0 commit comments

Comments
 (0)