diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..02a981c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,108 @@ +name: Release +on: + push: + tags: + - "v*" + +jobs: + version: + name: Set Version from git ref + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - id: version + run: echo "::set-output name=version::$(sed 's#^refs/tags/\(.*\)#\1#' <<< '${{ github.ref }}')" + + binaries: + name: Binaries + runs-on: ubuntu-latest + needs: version + env: + # VERSION: ${{ needs.version.outputs.version }} + VERSION: v0.0.1 + BUILD_DATE: '$$(date +%Y-%m-%d-%H:%M)' + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Restore Module Cache + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-gomod2-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-gomod2- + - name: Restore Build Cache + uses: actions/cache@v2 + with: + path: ~/.cache/go-build + key: ${{ runner.os }}-gobuild-${{ hashFiles('**/*.go') }} + - name: Setup Go 1.16 + uses: actions/setup-go@v1 + with: + go-version: 1.16 + - name: Build Binaries + run: | + make release-artifacts + - name: Generate Release Notes + run: scripts/release-notes.sh $VERSION > release-notes.md + - name: Create Release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body_path: release-notes.md + prerelease: ${{ contains(env.VERSION, '-alpha.') || contains(env.VERSION, '-beta.') || contains(env.VERSION, '-rc.') || contains(env.VERSION, '-nightly.') }} + - name: Upload macOS .zip + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "_dist/osm-health-${{ env.VERSION }}-darwin-amd64.zip" + asset_name: "osm-health-${{ env.VERSION }}-darwin-amd64.zip" + asset_content_type: application/zip + - name: Upload macOS .tar.gz + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "_dist/osm-health-${{ env.VERSION }}-darwin-amd64.tar.gz" + asset_name: "osm-health-${{ env.VERSION }}-darwin-amd64.tar.gz" + asset_content_type: application/gzip + - name: Upload Linux .zip + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "_dist/osm-health-${{ env.VERSION }}-linux-amd64.zip" + asset_name: "osm-health-${{ env.VERSION }}-linux-amd64.zip" + asset_content_type: application/zip + - name: Upload Linux .tar.gz + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "_dist/osm-health-${{ env.VERSION }}-linux-amd64.tar.gz" + asset_name: "osm-health-${{ env.VERSION }}-linux-amd64.tar.gz" + asset_content_type: application/gzip + - name: Upload Windows .zip + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "_dist/osm-health-${{ env.VERSION }}-windows-amd64.zip" + asset_name: "osm-health-${{ env.VERSION }}-windows-amd64.zip" + asset_content_type: application/zip + - name: Upload Windows .tar.gz + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: "_dist/osm-health-${{ env.VERSION }}-windows-amd64.tar.gz" + asset_name: "osm-health-${{ env.VERSION }}-windows-amd64.tar.gz" + asset_content_type: application/gzip + - name: Upload Checksums + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: _dist/sha256sums.txt + asset_name: sha256sums.txt + asset_content_type: text/plain diff --git a/Makefile b/Makefile index 66cde94..bc46462 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ #!make +TARGETS := darwin/amd64 linux/amd64 windows/amd64 +BINNAME ?= osm-health +DIST_DIRS := find * -type d -exec VERSION ?= dev BUILD_DATE=$$(date +%F) GIT_SHA=$$(git rev-parse HEAD) @@ -7,6 +10,8 @@ BUILD_DATE_VAR := github.com/openservicemesh/osm-health/pkg/version.BuildDate BUILD_VERSION_VAR := github.com/openservicemesh/osm-health/pkg/version.Version BUILD_GITCOMMIT_VAR := github.com/openservicemesh/osm-health/pkg/version.GitCommit +GOX = go run github.com/mitchellh/gox + LDFLAGS ?= "-X $(BUILD_DATE_VAR)=$(BUILD_DATE) -X $(BUILD_VERSION_VAR)=$(VERSION) -X $(BUILD_GITCOMMIT_VAR)=$(GIT_SHA) -s -w" .PHONY: build-ci @@ -61,3 +66,25 @@ run-collection: build-osm-health .PHONY: kind-up kind-up: ./scripts/kind-with-registry.sh + +# ------------------------------------------- +# release targets below +# ------------------------------------------- + +.PHONY: build-cross +build-cross: cmd + GO111MODULE=on CGO_ENABLED=0 $(GOX) -ldflags $(LDFLAGS) -parallel=3 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' ./cmd + +.PHONY: dist +dist: + ( \ + cd _dist && \ + $(DIST_DIRS) cp ../LICENSE {} \; && \ + $(DIST_DIRS) cp ../README.md {} \; && \ + $(DIST_DIRS) tar -zcf osm-${VERSION}-{}.tar.gz {} \; && \ + $(DIST_DIRS) zip -r osm-${VERSION}-{}.zip {} \; && \ + sha256sum osm-* > sha256sums.txt \ + ) + +.PHONY: release-artifacts +release-artifacts: build-cross dist diff --git a/go.mod b/go.mod index 3f2b080..ea80f93 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/matm/gocov-html v0.0.0-20200509184451-71874e2e203b // indirect github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mitchellh/gox v1.0.1 // indirect github.com/openservicemesh/osm v0.8.2-0.20210921094717-3116404ececa github.com/pkg/errors v0.9.1 github.com/rs/zerolog v1.23.0 diff --git a/go.sum b/go.sum index a8b393a..e53a463 100644 --- a/go.sum +++ b/go.sum @@ -721,9 +721,11 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI= github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= github.com/mitchellh/hashstructure/v2 v2.0.1 h1:L60q1+q7cXE4JeEJJKMnh2brFIe3rZxCihYAB61ypAY= github.com/mitchellh/hashstructure/v2 v2.0.1/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= +github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= diff --git a/scripts/release-notes.sh b/scripts/release-notes.sh new file mode 100644 index 0000000..3843058 --- /dev/null +++ b/scripts/release-notes.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Generate release notes using the changes between the given tag and its +# predecessor, calculated by git's version sorting. When a stable tag (i.e. +# without a pre-release tag like alpha, beta, etc.) is provided, then the +# previous tag will be the next latest stable tag, skipping any intermediate +# pre-release tags. + +# This script will break or produce weird output if: +# - Tags are not formatted in a way that can be interpreted by git tag's --sort=version:refname +# - Pre-release tags other than "nightly", "alpha", "beta", and "rc" are used. + +tag=$1 + +# No release notes for nightlies +if [[ "$tag" =~ "nightly" ]]; then + exit 0 +fi + +tags=$(git tag | tr - \~ | sort -V | tr \~ - | sed "/^$tag$/q" ) +! [[ "$tag" =~ -(alpha|beta|rc) ]] && tags=$(grep -Eve '-(alpha|beta|rc)' <<< "$tags") +prev=$(tail -2 <<< "$tags" | head -1) + +changelog=$(git log "$prev".."$tag" --no-merges --format="* %s %H (%aN)") + +cat <