Skip to content

Commit 4b90d9d

Browse files
authored
Merge pull request #16 from conjurinc/automated-release
Automated releases for Conjur preflight CLI
2 parents 597eb79 + 583aa2f commit 4b90d9d

File tree

17 files changed

+183
-61
lines changed

17 files changed

+183
-61
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ build_ca_certificate
1414
conjur-preflight
1515
# Exclude binary entrypoint
1616
!cmd/conjur-preflight
17+
VERSION
18+
!pkg/version

.goreleaser.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ before:
77
- go mod tidy
88
# you may remove this if you don't need go generate
99
- go generate ./...
10+
1011
builds:
1112
- main: ./cmd/conjur-preflight
1213
binary: conjur-preflight
@@ -28,6 +29,8 @@ builds:
2829
ldflags:
2930
- -w
3031
- -X "github.com/cyberark/conjur-preflight/pkg/version.Tag={{ .ShortCommit }}"
32+
- -X "github.com/cyberark/conjur-preflight/pkg/version.Version={{ .Env.VERSION }}"
33+
- -X "github.com/cyberark/conjur-preflight/pkg/version.BuildNumber={{ .Env.BUILD_NUMBER }}"
3134
hooks:
3235
post:
3336
# Copy the binary out into the <dist> path, and give the copy the name we
@@ -41,16 +44,16 @@ archives:
4144
- CHANGELOG.md
4245
- LICENSE
4346
- README.md
44-
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}_{{.Arch}}"
47+
name_template: "{{.ProjectName}}_{{.Env.VERSION}}_{{.Os}}_{{.Arch}}"
4548
wrap_in_directory: true
4649

4750
checksum:
4851
name_template: "SHA256SUMS.txt"
4952

5053
nfpms:
5154
- bindir: /usr/bin
52-
description: CyberArk Conjur Enteprise Preflight Qualification Tool
53-
file_name_template: "{{.ProjectName}}_{{.Version}}_{{.Arch}}"
55+
description: CyberArk Conjur Enterprise Preflight Qualification Tool
56+
file_name_template: "{{.ProjectName}}_{{.Env.VERSION}}_{{.Arch}}"
5457
formats:
5558
- deb
5659
- rpm
@@ -66,7 +69,12 @@ release:
6669
disable: true
6770
draft: true
6871
extra_files:
72+
- glob: NOTICES.txt
6973
- glob: CHANGELOG.md
7074
- glob: LICENSE
71-
- glob: README.md
7275
- glob: dist/binaries
76+
77+
# Changelog management and publishing is handled by Jenkins-based release
78+
# automation
79+
changelog:
80+
skip: true

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
- Nothing should go in this section, please add to the latest unreleased version
1010
(and update the corresponding date), or add a new version.
1111

12-
## [0.1.0] - 2022-12-09
12+
## [0.1.0] - 2022-12-12
13+
14+
### Added
15+
- Initial reports for CPU, memory, disk space, and OS version.
16+
[conjurinc/conjur-preflight#14](https://github.com/conjurinc/conjur-preflight/pull/14)
1317

1418
[Unreleased]: https://github.com/cyberark/conjur/compare/v0.0.0...HEAD

Dockerfile.junit

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.17-alpine
1+
FROM golang:1.19-alpine
22
LABEL MAINTAINER CyberArk Software Ltd.
33
LABEL id="conjur-preflight-junit-processor"
44

@@ -13,6 +13,6 @@ RUN apk add -u curl \
1313

1414
# gocov converts native coverage output to gocov's JSON interchange format
1515
# gocov-xml converts gocov format to XML for use with Jenkins/Cobertura
16-
RUN go get -u github.com/jstemmer/go-junit-report && \
17-
go get github.com/axw/gocov/gocov && \
18-
go get github.com/AlekSi/gocov-xml
16+
RUN go install github.com/jstemmer/go-junit-report@latest && \
17+
go install github.com/axw/gocov/gocov@latest && \
18+
go install github.com/AlekSi/gocov-xml@latest

Jenkinsfile

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#!/usr/bin/env groovy
22

3+
// Automated release, promotion and dependencies
4+
properties([
5+
// Include the automated release parameters for the build
6+
release.addParams(),
7+
])
8+
9+
// Performs release promotion. No other stages will be run
10+
if (params.MODE == "PROMOTE") {
11+
release.promote(params.VERSION_TO_PROMOTE) { sourceVersion, targetVersion, assetDirectory ->
12+
// Any assets from sourceVersion Github release are available in assetDirectory
13+
// Any version number updates from sourceVersion to targetVersion occur here
14+
// Any publishing of targetVersion artifacts occur here
15+
// Anything added to assetDirectory will be attached to the Github Release
16+
}
17+
return
18+
}
19+
320
pipeline {
421
agent { label 'executor-v2' }
522

@@ -9,20 +26,46 @@ pipeline {
926
timeout(time: 2, unit: 'HOURS')
1027
}
1128

29+
triggers {
30+
cron(getDailyCronString())
31+
}
32+
1233
environment {
1334
// Sets the MODE to the specified or autocalculated value as appropriate
1435
MODE = release.canonicalizeMode()
1536
}
1637

1738
stages {
18-
stage('Validate') {
19-
parallel {
20-
stage('Changelog') {
21-
steps { sh './bin/parse_changelog' }
39+
// Aborts any builds triggered by another project that wouldn't include any changes
40+
stage ("Skip build if triggering job didn't create a release") {
41+
when {
42+
expression {
43+
MODE == "SKIP"
44+
}
45+
}
46+
steps {
47+
script {
48+
currentBuild.result = 'ABORTED'
49+
error("Aborting build because this build was triggered from upstream, but no release was built")
2250
}
2351
}
2452
}
2553

54+
// Generates a VERSION file based on the current build number and latest version in CHANGELOG.md
55+
stage('Validate Changelog and set version') {
56+
steps {
57+
sh './bin/parse_changelog'
58+
updateVersion("CHANGELOG.md", "${BUILD_NUMBER}")
59+
}
60+
}
61+
62+
stage('Get latest upstream dependencies') {
63+
steps {
64+
updateGoDependencies('${WORKSPACE}/go.mod')
65+
}
66+
}
67+
68+
2669
stage('Run Unit Tests') {
2770
steps {
2871
sh './bin/test_unit'
@@ -44,5 +87,34 @@ pipeline {
4487
ccCoverage("gocov", "--prefix github.com/conjurinc/conjur-preflight")
4588
}
4689
}
90+
91+
stage('Release') {
92+
when {
93+
expression {
94+
MODE == "RELEASE"
95+
}
96+
}
97+
98+
steps {
99+
// Build release artifacts
100+
sh "bin/build_release"
101+
102+
release { billOfMaterialsDirectory, assetDirectory, toolsDirectory ->
103+
// Publish release artifacts to all the appropriate locations
104+
// Copy any artifacts to assetDirectory to attach them to the Github release
105+
106+
// Create Go application SBOM using the go.mod version for the golang container image
107+
sh """go-bom --tools "${toolsDirectory}" --go-mod ./go.mod --image "golang" --main "cmd/conjur-preflight/" --output "${billOfMaterialsDirectory}/go-app-bom.json" """
108+
// Create Go module SBOM
109+
sh """go-bom --tools "${toolsDirectory}" --go-mod ./go.mod --image "golang" --output "${billOfMaterialsDirectory}/go-mod-bom.json" """
110+
111+
// Add goreleaser artifacts to release
112+
sh """cp dist/*.tar.gz "${assetDirectory}" """
113+
sh """cp dist/*.rpm "${assetDirectory}" """
114+
sh """cp dist/*.deb "${assetDirectory}" """
115+
sh """cp "dist/SHA256SUMS.txt" "${assetDirectory}" """
116+
}
117+
}
118+
}
47119
}
48120
}

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ build:
22
go build -o ./dev/tmp/ ./cmd/conjur-preflight
33

44
test:
5-
go test -count=1 -coverprofile=c.out -v ./...
5+
go test -count=1 -coverpkg=./... -coverprofile=c.out -v ./...
6+
go tool cover -func c.out
67

78
install:
89
go install ./cmd/conjur-preflight

NOTICES.txt

Whitespace-only changes.

bin/build_release

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
REPO_ROOT="$(git rev-parse --show-toplevel)"
6+
7+
VERSION=$(<"${REPO_ROOT}/VERSION")
8+
9+
# Remove Jenkins build number from VERSION
10+
VERSION="${VERSION/-*/}"
11+
12+
13+
GORELEASER_IMAGE="goreleaser/goreleaser:latest"
14+
15+
main() {
16+
build_release
17+
}
18+
19+
build_release() {
20+
echo "Building release ${VERSION} (${BUILD_NUMBER})..."
21+
docker run \
22+
--rm \
23+
--env VERSION="${VERSION}" \
24+
--env BUILD_NUMBER="${BUILD_NUMBER}" \
25+
--volume "${PWD}/:/conjur-preflight/" \
26+
--workdir "/conjur-preflight" \
27+
"${GORELEASER_IMAGE}" \
28+
--skip-validate \
29+
--snapshot \
30+
--rm-dist
31+
echo "Release built. Artifacts can be found in dist/"
32+
}
33+
34+
main "$@"

bin/test_unit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function run_unit_tests() {
2424
docker run --rm -t \
2525
--volume "$PWD"/:/conjur-preflight/test/ \
2626
conjur-preflight-test-runner:latest \
27+
-count=1 \
28+
-coverpkg=./... \
2729
-coverprofile="./test/c.out" \
2830
./... \
2931
| tee -a "$junit_output_file"

0 commit comments

Comments
 (0)