From 1b6233617ba37c81d682e5f10e849fb8aa65ae11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bia=C5=82o=C5=84?= Date: Tue, 29 Aug 2023 11:00:24 +0200 Subject: [PATCH] Release workflow (#173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Białoń --- .github/workflows/release.yml | 25 ++++- .gitignore | 3 + .goreleaser.yaml | 173 ++++++++++++++++++++++++++++++++++ Dockerfile | 22 +---- scripts/goimportscheck.sh | 2 +- 5 files changed, 203 insertions(+), 22 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3da8d07723..6500be6a1f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,6 @@ name: release on: workflow_dispatch: push: - branches: - - main tags: - 'v[0-9]+.[0-9]+.[0-9]+*' @@ -22,3 +20,26 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 + + - name: Fetch tags + run: git fetch --force --tags + + - name: Determine Go version + id: go + uses: ./.github/actions/go-version + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ steps.go.outputs.version }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + version: v1.20.0 + args: release --clean --timeout=60m --snapshot=${{ !startsWith(github.ref, 'refs/tags/v') }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index cc34a88b19..daaad4fb13 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ vendor/ # Coverage coverage.txt + +# GoReleaser build directory +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000000..f8efc307d4 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,173 @@ +project_name: opentf + +before: + hooks: + - go mod tidy + - go generate ./... + - make protobuf + +builds: + - env: + - CGO_ENABLED=0 + + flags: + - "-mod=readonly" + - "-trimpath" + + ldflags: + - "-s -w" + - "-X 'github.com/placeholderplaceholderplaceholder/opentf/version.dev=no'" + + goos: + - linux + - windows + - darwin + - freebsd + - openbsd + - solaris + + goarch: + - "386" + - amd64 + - arm + - arm64 + + ignore: + - goos: freebsd + goarch: arm64 + - goos: openbsd + goarch: arm + - goos: openbsd + goarch: arm64 + - goos: solaris + goarch: "386" + - goos: solaris + goarch: arm + - goos: solaris + goarch: arm64 + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + - goos: darwin + goarch: "386" + - goos: darwin + goarch: arm + +archives: + - format: zip + name_template: "{{ .ProjectName }}_{{ .Version }}_{{- .Os }}_{{- .Arch }}" + +dockers: + - use: buildx + goarch: amd64 + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=OpenTF" + - "--label=org.opencontainers.image.description=OpenTF {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.documentation=https://github.com/opentffoundation/opentf/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.licenses=MPL-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.created={{ time \"2006-01-02T15:04:05Z07:00\" }}" + image_templates: + - "ghcr.io/opentffoundation/opentf:{{ .Version }}-amd64" + + - use: buildx + goarch: arm64 + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=OpenTF" + - "--label=org.opencontainers.image.description=OpenTF {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.documentation=https://github.com/opentffoundation/opentf/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.licenses=MPL-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.created={{ time \"2006-01-02T15:04:05Z07:00\" }}" + image_templates: + - "ghcr.io/opentffoundation/opentf:{{ .Version }}-arm64" + + - use: buildx + goarch: arm + build_flag_templates: + - "--pull" + - "--platform=linux/arm" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=OpenTF" + - "--label=org.opencontainers.image.description=OpenTF {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.documentation=https://github.com/opentffoundation/opentf/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.licenses=MPL-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.created={{ time \"2006-01-02T15:04:05Z07:00\" }}" + image_templates: + - "ghcr.io/opentffoundation/opentf:{{ .Version }}-arm" + + - use: buildx + goarch: "386" + build_flag_templates: + - "--pull" + - "--platform=linux/386" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.vendor=OpenTF" + - "--label=org.opencontainers.image.description=OpenTF {{ .Version }}" + - "--label=org.opencontainers.image.url=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.documentation=https://github.com/opentffoundation/opentf/blob/main/README.md" + - "--label=org.opencontainers.image.source=https://github.com/opentffoundation/opentf" + - "--label=org.opencontainers.image.licenses=MPL-2.0" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.created={{ time \"2006-01-02T15:04:05Z07:00\" }}" + image_templates: + - "ghcr.io/opentffoundation/opentf:{{ .Version }}-386" + +docker_manifests: + - name_template: ghcr.io/opentffoundation/opentf:v{{ .Version }} + image_templates: + - ghcr.io/opentffoundation/opentf:{{ .Version }}-amd64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm + - ghcr.io/opentffoundation/opentf:{{ .Version }}-386 + + - name_template: ghcr.io/opentffoundation/opentf:{{ .Major }} + image_templates: + - ghcr.io/opentffoundation/opentf:{{ .Version }}-amd64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm + - ghcr.io/opentffoundation/opentf:{{ .Version }}-386 + + - name_template: ghcr.io/opentffoundation/opentf:{{ .Major }}.{{ .Minor }} + image_templates: + - ghcr.io/opentffoundation/opentf:{{ .Version }}-amd64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm + - ghcr.io/opentffoundation/opentf:{{ .Version }}-386 + + - name_template: ghcr.io/opentffoundation/opentf:latest + image_templates: + - ghcr.io/opentffoundation/opentf:{{ .Version }}-amd64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm64 + - ghcr.io/opentffoundation/opentf:{{ .Version }}-arm + - ghcr.io/opentffoundation/opentf:{{ .Version }}-386 + +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" + +snapshot: + name_template: "{{ .Version }}-next" + +changelog: + use: github-native + +release: + draft: true diff --git a/Dockerfile b/Dockerfile index 56f1ab8b8f..396247ee01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,10 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -# This Dockerfile builds on golang:alpine by building OpenTF from source -# using the current working directory. -# -# This produces a docker image that contains a working OpenTF binary along -# with all of its source code. This is not what produces the official releases -# in the "opentf" namespace on Dockerhub; those images include only -# the officially-released binary from releases.hashicorp.com and are -# built by the (closed-source) official release process. +FROM alpine:3.18 -FROM docker.mirror.hashicorp.services/golang:alpine LABEL maintainer="OpenTF Team " -RUN apk add --no-cache git bash openssh +COPY opentf /usr/local/bin/opentf -ENV TF_DEV=true -ENV TF_RELEASE=1 - -WORKDIR $GOPATH/src/github.com/placeholderplaceholderplaceholder/opentf -COPY . . -RUN /bin/bash ./scripts/build.sh - -WORKDIR $GOPATH -ENTRYPOINT ["opentf"] +ENTRYPOINT ["/usr/local/bin/opentf"] diff --git a/scripts/goimportscheck.sh b/scripts/goimportscheck.sh index 893c662418..c9747af8f6 100755 --- a/scripts/goimportscheck.sh +++ b/scripts/goimportscheck.sh @@ -32,7 +32,7 @@ fi # "IFS" environment variable, but the primary place we want to run this right # now is in our "quick checks" workflow and that _does_ have a reasonably # modern version of Bash. -readarray -t target_files < <(git diff --name-only ${base_branch} --diff-filter=MA | grep "\.go" | grep -v ".pb.go" | grep -v ".go-version") +readarray -t target_files < <(git diff --name-only ${base_branch} --diff-filter=MA | grep "\.go" | grep -v ".pb.go" | grep -v ".go-version" | grep -v ".goreleaser") # NOTE: The above intentionally excludes .pb.go files because those are # generated by a tool (protoc-gen-go) which itself doesn't produce