From 1cd0150afdf827a9ee1d3db374579276884872e8 Mon Sep 17 00:00:00 2001 From: claire labry Date: Thu, 19 Jan 2023 13:02:09 -0600 Subject: [PATCH] Introduce action-set-product-version for Packer (#12135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change introduces the new actions-set-product-version, a tiny, but mighty, GitHub action that acts as a bridge between the product repo and our new CRT feature: automated version bumping. tl;dr automated version bumping has a new command (bob update version) in the bob CLI that automatically bumps the version to a new patch. This automation has been introduced to crt-workflows-common as a new workflow (with the new bob command) and handles version bumping at the end of the release pipeline (after being released to production); for example, 1.0.0→1.0.1 and 1.0.0-dev→1.0.0. Bumping the minor version (ie 1.0.x→1.1.0) is only supported manually via bob update version -bump minor, but not supported in CRT (this work is upcoming). This is made possible by adding the new event “bump-version” in the ci.hcl file in this PR. What this small action does: Allows for the static version string from the version/VERSION file to be read by the new CRT workflow and automagically be bumped to the next version (whether it be a minor, or patch, or major version bump). Outputs an error if there’s no VERSION file in the version dir Outputs an error if there’s no version string in the VERSION file Is able to parse product_version if it is 1.3.0-alpha1 as 1.3.0 (example: when product_version = 1.3.0-alpha1, base_version = 1.3.0) Is able to parse prerelease product versions such as alpha1 (example prerelease_product_version = alpha1) in the statement above. --- .github/workflows/build.yml | 170 +++++++++++++++++------------------- .release/ci.hcl | 159 +++++---------------------------- Makefile | 3 - scripts/version.sh | 12 --- version/VERSION | 1 + version/version.go | 10 ++- 6 files changed, 108 insertions(+), 247 deletions(-) delete mode 100755 scripts/version.sh create mode 100644 version/VERSION diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab949cc76..f37a0436c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,6 @@ on: [ workflow_dispatch, push, workflow_call ] env: REPO_NAME: "packer" - GO_TAGS: "" permissions: contents: read @@ -21,7 +20,7 @@ jobs: outputs: go-version: ${{ steps.get-go-version.outputs.go-version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: 'Determine Go version' id: get-go-version # We use .go-version as our source of truth for current Go @@ -30,58 +29,55 @@ jobs: echo "Building with Go $(cat .go-version)" echo "::set-output name=go-version::$(cat .go-version)" - get-product-version: + set-product-version: runs-on: ubuntu-latest outputs: - product-version: ${{ steps.get-product-version.outputs.product-version }} + product-version: ${{ steps.set-product-version.outputs.product-version }} + base-product-version: ${{ steps.set-product-version.outputs.base-product-version }} + product-date: ${{ steps.get-product-version.outputs.product-date }} + product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }} + set-ld-flags: ${{ steps.set-ld-flags.outputs.set-ld-flags }} steps: - - uses: actions/checkout@v2 - - name: get product version - id: get-product-version + - uses: actions/checkout@v3 + - name: set product version + id: set-product-version + uses: hashicorp/actions-set-product-version@v1 + - name: set-ld-flags + id: set-ld-flags run: | - make version - echo "::set-output name=product-version::$(make version)" + T="github.com/hashicorp/packer/version" + echo "::set-output name=set-ld-flags::-X ${T}.GitCommit=${GITHUB_SHA::8} -X ${T}.GitDescribe=${{ steps.set-product-version.outputs.product-version }} -X ${T}.Version=${{ steps.set-product-version.outputs.base-product-version }} -X ${T}.VersionPrerelease=${{ steps.set-product-version.outputs.prerelease-product-version }} -X ${T}.VersionMetadata=" + - name: validate outputs + run: | + echo "Product Version: ${{ steps.set-product-version.outputs.product-version }}" + echo "Base Product Version: ${{ steps.set-product-version.outputs.base-product-version }}" + echo "Prerelease Version: ${{ steps.set-product-version.outputs.prerelease-product-version }}" + echo "ldflags: ${{ steps.set-ld-flags.outputs.set-ld-flags }}" generate-metadata-file: - needs: - - get-product-version + needs: set-product-version runs-on: ubuntu-latest outputs: filepath: ${{ steps.generate-metadata-file.outputs.filepath }} steps: - name: 'Checkout directory' - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Generate metadata file id: generate-metadata-file uses: hashicorp/actions-generate-metadata@main with: - version: ${{ needs.get-product-version.outputs.product-version }} + version: ${{ needs.set-product-version.outputs.product-version }} product: ${{ env.REPO_NAME }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: metadata.json path: ${{ steps.generate-metadata-file.outputs.filepath }} - - set-ld-flags: - needs: get-product-version - runs-on: ubuntu-latest - outputs: - ldflags: ${{ steps.generate-ld-flags.outputs.ldflags }} - steps: - - uses: actions/checkout@v2 - - name: 'Generate ld flags' - id: generate-ld-flags - run: | - project="$(go list -m)" - sha="$(git rev-parse HEAD)" - echo "::set-output name=ldflags::"-s -w -X \'$project/version.GitCommit=$sha\'"" - + build-other: needs: - - get-product-version + - set-product-version - get-go-version - - set-ld-flags runs-on: ubuntu-latest strategy: matrix: @@ -98,36 +94,33 @@ jobs: fail-fast: true name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build + env: GOPRIVATE: "github.com/hashicorp" GO111MODULE: on - LD_FLAGS: ${{ needs.set-ld-flags.outputs.ldflags }} steps: - - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} + - uses: actions/checkout@v3 - name: Go Build env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - CGO_ENABLED: 0 - run: | - mkdir -p dist out - unset GOPATH; - go build -v -tags "${{ env.GO_TAGS }}" -ldflags "${{ env.LD_FLAGS }}" -o dist/ . - zip -r -j out/${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ - - uses: actions/upload-artifact@v2 + PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} + PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} + LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" + CGO_ENABLED: "0" + uses: hashicorp/actions-go-build@v0.1.7 with: - name: ${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip - path: out/${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip + product_name: ${{ env.REPO_NAME }} + product_version: ${{ needs.set-product-version.outputs.product-version }} + go_version: ${{ matrix.go }} + os: ${{ matrix.goos }} + arch: ${{ matrix.goarch }} + reproducible: report + instructions: |- + go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false build-linux: needs: - - get-product-version + - set-product-version - get-go-version - - set-ld-flags runs-on: ubuntu-latest strategy: matrix: @@ -141,28 +134,25 @@ jobs: env: GOPRIVATE: "github.com/hashicorp" GO111MODULE: on - LD_FLAGS: ${{ needs.set-ld-flags.outputs.ldflags }} steps: - - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} + - uses: actions/checkout@v3 - name: Go Build env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - CGO_ENABLED: 0 - run: | - mkdir -p dist out - unset GOPATH; - go build -v -tags "${{ env.GO_TAGS }}" -ldflags "${{ env.LD_FLAGS }}" -o dist/ . - zip -r -j out/${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ - - uses: actions/upload-artifact@v2 + PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} + PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} + LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" + CGO_ENABLED: "0" + uses: hashicorp/actions-go-build@v0.1.7 with: - name: ${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip - path: out/${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip + product_name: ${{ env.REPO_NAME }} + product_version: ${{ needs.set-product-version.outputs.product-version }} + go_version: ${{ matrix.go }} + os: ${{ matrix.goos }} + arch: ${{ matrix.goarch }} + reproducible: report + instructions: |- + go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false - name: Linux Packaging uses: hashicorp/actions-packaging-linux@v1 @@ -170,7 +160,7 @@ jobs: name: ${{ env.REPO_NAME }} description: "HashiCorp Packer - A tool for creating identical machine images for multiple platforms from a single source configuration" arch: ${{ matrix.goarch }} - version: ${{ needs.get-product-version.outputs.product-version }} + version: ${{ needs.set-product-version.outputs.product-version }} maintainer: "HashiCorp" homepage: "https://www.packer.io/docs" license: "MPL-2.0" @@ -181,20 +171,19 @@ jobs: run: | echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: ${{ env.RPM_PACKAGE }} path: out/${{ env.RPM_PACKAGE }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: ${{ env.DEB_PACKAGE }} path: out/${{ env.DEB_PACKAGE }} build-darwin: needs: - - get-product-version + - set-product-version - get-go-version - - set-ld-flags runs-on: macos-latest strategy: matrix: @@ -207,42 +196,39 @@ jobs: env: GOPRIVATE: "github.com/hashicorp" GO111MODULE: on - LD_FLAGS: ${{ needs.set-ld-flags.outputs.ldflags }} steps: - - uses: actions/checkout@v2 - - name: Setup go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} + - uses: actions/checkout@v3 - name: Go Build env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - CGO_ENABLED: 0 - run: | - mkdir -p dist out - unset GOPATH; - go build -v -tags "${{ env.GO_TAGS }} netcgo" -ldflags "${{ env.LD_FLAGS }}" -o dist/ . - zip -r -j out/${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip dist/ - - uses: actions/upload-artifact@v2 + PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} + PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} + LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" + CGO_ENABLED: "0" + uses: hashicorp/actions-go-build@v0.1.7 with: - name: ${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip - path: out/${{ env.REPO_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip + product_name: ${{ env.REPO_NAME }} + product_version: ${{ needs.set-product-version.outputs.product-version }} + go_version: ${{ matrix.go }} + os: ${{ matrix.goos }} + arch: ${{ matrix.goarch }} + reproducible: report + instructions: |- + go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -tags netcgo -trimpath -buildvcs=false build-docker: name: Docker light ${{ matrix.arch }} build needs: - - get-product-version + - set-product-version - build-linux runs-on: ubuntu-latest strategy: matrix: arch: [ "arm", "arm64", "386", "amd64" ] env: - version: ${{ needs.get-product-version.outputs.product-version }} + version: ${{ needs.set-product-version.outputs.product-version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Docker Build (Action) uses: hashicorp/actions-docker-build@v1 with: diff --git a/.release/ci.hcl b/.release/ci.hcl index 258c48590..b1f995952 100644 --- a/.release/ci.hcl +++ b/.release/ci.hcl @@ -9,7 +9,7 @@ project "packer" { organization = "hashicorp" repository = "packer" release_branches = [ - "main" + "main", ] } } @@ -28,146 +28,14 @@ event "build" { } } -event "upload-dev" { +event "prepare" { depends = ["build"] - action "upload-dev" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "upload-dev" - depends = ["build"] - } - - notification { - on = "fail" - } -} - -event "quality-tests" { - depends = ["upload-dev"] - action "quality-tests" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "quality-tests" - } - - notification { - on = "fail" - } -} -event "security-scan-binaries" { - depends = ["upload-dev"] - action "security-scan-binaries" { + action "prepare" { organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "security-scan-binaries" - config = "security-scan.hcl" - } - - notification { - on = "fail" - } -} - -event "security-scan-containers" { - depends = ["security-scan-binaries"] - action "security-scan-containers" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "security-scan-containers" - config = "security-scan.hcl" - } - - notification { - on = "fail" - } -} - -event "notarize-darwin-amd64" { - depends = ["security-scan-containers"] - action "notarize-darwin-amd64" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "notarize-darwin-amd64" - } - - notification { - on = "fail" - } -} - -event "notarize-windows-386" { - depends = ["notarize-darwin-amd64"] - action "notarize-windows-386" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "notarize-windows-386" - } - - notification { - on = "fail" - } -} - -event "notarize-windows-amd64" { - depends = ["notarize-windows-386"] - action "notarize-windows-amd64" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "notarize-windows-amd64" - } - - notification { - on = "fail" - } -} - -event "sign" { - depends = ["notarize-windows-amd64"] - action "sign" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "sign" - } - - notification { - on = "fail" - } -} - -event "sign-linux-rpms" { - depends = ["sign"] - action "sign-linux-rpms" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "sign-linux-rpms" - } - - notification { - on = "fail" - } -} - -event "verify" { - depends = ["sign-linux-rpms"] - action "verify" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "verify" - } - - notification { - on = "fail" - } -} - -event "promote-dev-docker" { - depends = ["verify"] - action "promote-dev-docker" { - organization = "hashicorp" - repository = "crt-workflows-common" - workflow = "promote-dev-docker" - depends = ["verify"] + repository = "crt-workflows-common" + workflow = "prepare" + depends = ["build"] } notification { @@ -267,8 +135,21 @@ event "post-publish-website" { } } -event "update-ironbank" { +event "bump-version" { depends = ["post-publish-website"] + action "bump-version" { + organization = "hashicorp" + repository = "crt-workflows-common" + workflow = "bump-version" + } + + notification { + on = "fail" + } +} + +event "update-ironbank" { + depends = ["bump-version"] action "update-ironbank" { organization = "hashicorp" repository = "crt-workflows-common" diff --git a/Makefile b/Makefile index c6f145f3c..13102b044 100644 --- a/Makefile +++ b/Makefile @@ -196,6 +196,3 @@ vet: ## Vet Go code help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -# This is used for release builds by .github/workflows/build.yml -version: - @$(CURDIR)/scripts/version.sh version/version.go diff --git a/scripts/version.sh b/scripts/version.sh deleted file mode 100755 index c854cab30..000000000 --- a/scripts/version.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -version_file=$1 -version=$(awk '$1 == "Version" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < "${version_file}") -prerelease=$(awk '$1 == "VersionPrerelease" && $2 == "=" { gsub(/"/, "", $3); print $3 }' < "${version_file}") - -if [ -n "$prerelease" ]; then - echo "${version}-${prerelease}" -else - echo "${version}" -fi \ No newline at end of file diff --git a/version/VERSION b/version/VERSION new file mode 100644 index 000000000..9eadd6baa --- /dev/null +++ b/version/VERSION @@ -0,0 +1 @@ +1.8.6 \ No newline at end of file diff --git a/version/version.go b/version/version.go index 192d87d6f..5e6f85b8f 100644 --- a/version/version.go +++ b/version/version.go @@ -13,13 +13,21 @@ var ( // Whether cgo is enabled or not; set at build time CgoEnabled bool + // The next version number that will be released. This will be updated after every release + // Version must conform to the format expected by github.com/hashicorp/go-version + // for tests to work. + // A pre-release marker for the version can also be specified (e.g -dev). If this is omitted // The main version number that is being run at the moment. + Version = "1.8.6" + // A pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release // such as "dev" (in development), "beta", "rc1", etc. + VersionPrerelease = "dev" - VersionMetadata = "" + + VersionMetadata = "" ) var PackerVersion *pluginVersion.PluginVersion