From a96dc6d2746bd318620033f50d809875b41ea6bb Mon Sep 17 00:00:00 2001 From: Kumbirai Tanekha Date: Thu, 1 Apr 2021 12:36:55 +0000 Subject: [PATCH] Automate draft release creation with Goreleaser Go releaser builds the release artefacts and creates a draft release on Github --- .github/workflows/ci.yml | 4 ++-- .goreleaser.yml | 12 +++++++++--- CHANGELOG.md | 4 ++++ CONTRIBUTING.md | 24 ++++++++++++------------ Dockerfile.acceptance | 2 +- Jenkinsfile | 36 +++++++++++++++++++++++++++++------- build | 22 +++++++++++++++------- 7 files changed, 72 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7024d56b..e95684cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,8 @@ jobs: - uses: actions/checkout@v2 with: submodules: recursive - - name: Build Go package (release) - run: ./build + - name: Build Go package (release snapshot) + run: ./build --snapsot if: ${{ startsWith(github.ref, 'refs/tags/v') }} - name: Build Go package (snapshot) run: ./build --snapshot diff --git a/.goreleaser.yml b/.goreleaser.yml index 36188593..f91e02e5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -65,7 +65,7 @@ nfpms: - file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Arch }}" vendor: CyberArk homepage: https://github.com/cyberark/summon - maintainer: Dustin Collins + maintainer: Conjur Maintainers description: CLI that provides on-demand secrets access for common DevOps tools. recommends: @@ -74,8 +74,14 @@ nfpms: formats: - deb - rpm + - apk bindir: /usr/local/bin +dist: ./dist/goreleaser + release: - disable: true - prerelease: auto + disable: false + draft: true + extra_files: + - glob: LICENSE + - glob: CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 1448d0b3..e33f6f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Added +- Adds apk package to the release artefacts. + [cyberark/summon#209](https://github.com/cyberark/summon/issues/209) + ## [0.8.3] - 2020-09-25 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a302dba..6333c5c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ To build versions for Linux, macOS and Windows: ./build ``` -Binaries will be placed in `dist/`. +Binaries will be placed in `dist/goreleaser`. ### Running the project from source @@ -79,9 +79,9 @@ The following checklist should be followed when creating a release: - [ ] Retrieve artifacts generated by jenkins to perform smoke tests - Note: You can manually [`Build`](./build) the release. Output is placed in the `dist` folder - [ ] Binaries for smoke testing are found in the following directories - - Linux: `dist/summon-linux_linux_amd64` - - MacOS: `dist/summon_darwin_amd64` - - Windows: `dist/summon_windows_amd64` + - Linux: `dist/goreleaser/summon-linux_linux_amd64` + - MacOS: `dist/goreleaser/summon_darwin_amd64` + - Windows: `dist/goreleaser/summon_windows_amd64` - [ ] Create a draft release: - [ ] Create an [annotated tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging#_annotated_tags) @@ -91,19 +91,19 @@ The following checklist should be followed when creating a release: - [ ] Name the release the same as the tag. - [ ] Include in the release notes all changes from CHANGELOG that are being released. - [ ] Attach the relevant assets to the release, generated previously by `./build`: - - [ ] Attach `dist/summon-darwin-amd64.tar.gz` to release. - - [ ] Attach `dist/summon-linux-amd64.tar.gz` to release. - - [ ] Attach `dist/summon-windows-amd64.tar.gz` to release. - - [ ] Attach `dist/summon_v*.rpm` to release. - - [ ] Attach `dist/summon_v*.deb` to release. - - [ ] Attach `dist/CHANGELOG.md` to release. - - [ ] Attach `dist/SHA256SUMS.txt` to the release. + - [ ] Attach `dist/goreleaser/summon-darwin-amd64.tar.gz` to release. + - [ ] Attach `dist/goreleaser/summon-linux-amd64.tar.gz` to release. + - [ ] Attach `dist/goreleaser/summon-windows-amd64.tar.gz` to release. + - [ ] Attach `dist/goreleaser/summon_v*.rpm` to release. + - [ ] Attach `dist/goreleaser/summon_v*.deb` to release. + - [ ] Attach `dist/goreleaser/CHANGELOG.md` to release. + - [ ] Attach `dist/goreleaser/SHA256SUMS.txt` to the release. - [ ] Publish the release as a "pre-released". - [ ] Update homebrew tools - [ ] In [`cyberark/homebrew-tools`](https://github.com/cyberark/homebrew-tools) repo, update the [`summon.rb` formula](https://github.com/cyberark/homebrew-tools/blob/master/summon.rb#L4-L6) with a PR - using the file `dist/summon.rb`. + using the file `dist/goreleaser/summon.rb`. - [ ] Publish the release as a regular release. diff --git a/Dockerfile.acceptance b/Dockerfile.acceptance index 161039cd..56bb2361 100644 --- a/Dockerfile.acceptance +++ b/Dockerfile.acceptance @@ -20,7 +20,7 @@ RUN bundle install # Build summon WORKDIR /summon COPY . . -RUN go build -o /bin/summon cmd/main.go +COPY ./dist/goreleaser/summon-linux_linux_amd64/summon /bin/summon # Run tests WORKDIR /summon/acceptance diff --git a/Jenkinsfile b/Jenkinsfile index 52428b9c..6263890e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,13 +24,6 @@ pipeline { steps { sh './bin/parse-changelog' } } - stage('Build Go package') { - steps { - sh './build --skip-validate' - archiveArtifacts artifacts: "dist/*.tar.gz,dist/*.zip,dist/*.rb,dist/*.deb,dist/*.rpm,dist/*.txt", fingerprint: true - } - } - stage('Run unit tests') { steps { sh './test_unit' @@ -45,6 +38,35 @@ pipeline { } } + stage('Build Release Artifacts') { + when { + not { + tag "v*" + } + } + + steps { + sh './build --snapshot' + archiveArtifacts 'dist/goreleaser/' + } + } + + stage('Build Release Artifacts and Create Pre Release') { + // Only run this stage when triggered by a tag + when { tag "v*" } + + steps { + dir('./pristine-checkout') { + // Go releaser requires a pristine checkout + checkout scm + + // Create draft release + sh "summon --yaml 'GITHUB_TOKEN: !var github/users/conjur-jenkins/api-token' ./build" + archiveArtifacts 'dist/goreleaser/' + } + } + } + stage('Run acceptance tests') { steps { sh './test_acceptance' diff --git a/build b/build index cef0e4ca..a6c3cbd8 100755 --- a/build +++ b/build @@ -1,12 +1,20 @@ #!/bin/bash -e -git fetch --tags # jenkins does not do this automatically yet +CURRENT_DIR=$(pwd) + +echo "Current dir: $CURRENT_DIR" + +MOUNT_DIR="/summon" -GORELEASER_IMAGE="goreleaser/goreleaser:latest-cgo" +GORELEASER_IMAGE="goreleaser/goreleaser:latest" + +git fetch --tags # jenkins does not do this automatically yet -docker pull "$GORELEASER_IMAGE" +docker pull "${GORELEASER_IMAGE}" +docker run --rm -t \ + --env GITHUB_TOKEN \ + -v "$CURRENT_DIR:$MOUNT_DIR" \ + -w "$MOUNT_DIR" \ + "${GORELEASER_IMAGE}" --rm-dist "$@" -docker run --rm \ - -v "$PWD:/summon" \ - -w /summon \ - "$GORELEASER_IMAGE" release --rm-dist "$@" +echo "Releases built. Archives can be found in dist/goreleaser"