Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

feat(ci): create GitHub release workflow #121

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

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
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!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)
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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/osm/version/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestEnvoyConfigParser(t *testing.T) {
assert := tassert.New(t)
actual := getReleases()

assert.Equal([]string{"v0.10", "v0.11", "v0.6", "v0.7", "v0.8", "v0.9"}, actual)
assert.Equal([]string{"v0.10", "v0.11", "v0.7", "v0.8", "v0.9"}, actual)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to pass unit tests as v0.6 is not supported anymore.


for _, release := range actual {
controllerVersion := ControllerVersion(release)
Expand Down
36 changes: 36 additions & 0 deletions scripts/release-notes.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
## Notable Changes

## Deprecation Notes

## Changelog

$changelog
EOF