Skip to content

Commit

Permalink
chore(ci): rework taskfiles. (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zenithar authored Feb 6, 2021
1 parent 78f4360 commit 6d513b6
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ Temporary Items

# Release directory used by mage release target (it could be out of source)
dist
.task
108 changes: 91 additions & 17 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,110 @@ vars:
tasks:
default:
cmds:
- task: build

compile:
desc: Compile artefact
cmds:
- go mod vendor
- mage compile

build:
desc: Build artefact
cmds:
- mage
- task: release

release:
desc: Generate a release
cmds:
- go mod vendor
- mage release
- task: release-clean
- task: release-all
- task: release-checksum
- task: release-formula

release-pack:
desc: Generate final artefact to publish to GH
release-clean:
cmds:
- rm -rf dist && mkdir dist

release-all:
deps:
- release-darwin-amd64
# - release-darwin-arm64
- release-linux-amd64
- release-linux-arm64
- release-linux-arm7
- release-windows-amd64

release-darwin-amd64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-darwin-amd64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-darwin-amd64"
sources:
- bin/{{.ARTIFACT}}-darwin-amd64
generates:
- dist/{{.ARTIFACT}}-darwin-amd64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-darwin-amd64
method: checksum

release-darwin-arm64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-darwin-arm64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-darwin-arm64"
sources:
- bin/{{.ARTIFACT}}-darwin-arm64
generates:
- dist/{{.ARTIFACT}}-darwin-arm64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-darwin-amd64
method: checksum

release-linux-amd64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-linux-amd64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-amd64"
- "tar cfJ dist/{{.ARTIFACT}}-linux-arm7-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-arm7"
sources:
- bin/{{.ARTIFACT}}-linux-amd64
generates:
- dist/{{.ARTIFACT}}-linux-amd64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-linux-amd64
method: checksum

release-linux-arm64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-linux-arm64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-arm64"
sources:
- bin/{{.ARTIFACT}}-linux-arm64
generates:
- dist/{{.ARTIFACT}}-linux-arm64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-linux-arm64
method: checksum

release-linux-arm7:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-linux-arm7-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-arm7"
sources:
- bin/{{.ARTIFACT}}-linux-arm7
generates:
- dist/{{.ARTIFACT}}-linux-arm7-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-linux-arm7
method: checksum

release-windows-amd64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-windows-amd64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-windows-amd64.exe"
sources:
- bin/{{.ARTIFACT}}-windows-amd64.exe
generates:
- dist/{{.ARTIFACT}}-windows-amd64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-windows-amd64.exe
method: checksum

release-checksum:
deps:
- release-all
cmds:
- cd dist && sha256sum {{.ARTIFACT}}-*.tar.xz > {{.ARTIFACT}}-checksum.txt
- cd dist && gpg --detach-sign --armor {{.ARTIFACT}}-checksum.txt
- cat dist/{{.ARTIFACT}}-checksum.txt
generates:
- dist/{{.ARTIFACT}}-checksum.txt
- dist/{{.ARTIFACT}}-checksum.txt.asc

release-formula:
deps:
- release-all
cmds:
- mage homebrew > dist/{{.ARTIFACT}}.rb
generates:
- dist/{{.ARTIFACT}}.rb
4 changes: 1 addition & 3 deletions build/mage/golang/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"time"

"github.com/fatih/color"

"github.com/elastic/harp/pkg/sdk/types"
)

// Keep only last 2 versions
Expand All @@ -38,7 +36,7 @@ func init() {
// Set default timezone to UTC
time.Local = time.UTC

if !types.StringArray(goVersions).Contains(runtime.Version()) {
if !Is(goVersions...) {
color.HiRed("#############################################################################################")
color.HiRed("")
color.HiRed("Your golang compiler (%s) must be updated to %s to successfully compile all tools.", runtime.Version(), goVersions)
Expand Down
29 changes: 29 additions & 0 deletions build/mage/golang/is.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package golang

import (
"runtime"

"github.com/elastic/harp/pkg/sdk/types"
)

// Is return true if current go version is included in given array.
func Is(versions ...string) bool {
return types.StringArray(versions).Contains(runtime.Version())
}
5 changes: 1 addition & 4 deletions build/mage/release/formula.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class {{ .Formula }} < Formula
# Stable build
stable do
if OS.mac? && Hardware::CPU.arm?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-arm64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-darwin-arm64-%s.tar.xz" .Bin .Release) }}"
elsif OS.mac?
if OS.mac?
url "https://{{ .Repository }}/releases/download/cmd%2F{{ .Bin }}%2F{{ .Release }}/{{ .Bin }}-darwin-amd64-{{ .Release }}.tar.xz"
sha256 "{{ sha256file (printf "dist/%s-darwin-amd64-%s.tar.xz" .Bin .Release) }}"
elsif OS.linux?
Expand Down
109 changes: 92 additions & 17 deletions cmd/harp-server/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,110 @@ vars:
tasks:
default:
cmds:
- task: build

build:
desc: Build artefact
cmds:
- mage

test:
desc: Test artefact
cmds:
- mage test
- task: release

release:
desc: Generate a release
cmds:
- go mod vendor
- mage release
- task: release-clean
- task: release-all
- task: release-checksum
- task: release-formula

release-pack:
desc: Generate final artefact to publish to GH
release-clean:
cmds:
- rm -rf dist && mkdir dist

release-all:
deps:
- release-darwin-amd64
# - release-darwin-arm64
- release-linux-amd64
- release-linux-arm64
- release-linux-arm7
- release-windows-amd64

release-darwin-amd64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-darwin-amd64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-darwin-amd64"
sources:
- bin/{{.ARTIFACT}}-darwin-amd64
generates:
- dist/{{.ARTIFACT}}-darwin-amd64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-darwin-amd64
method: checksum

release-darwin-arm64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-darwin-arm64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-darwin-arm64"
sources:
- bin/{{.ARTIFACT}}-darwin-arm64
generates:
- dist/{{.ARTIFACT}}-darwin-arm64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-darwin-amd64
method: checksum

release-linux-amd64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-linux-amd64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-amd64"
- "tar cfJ dist/{{.ARTIFACT}}-linux-arm7-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-arm7"
sources:
- bin/{{.ARTIFACT}}-linux-amd64
generates:
- dist/{{.ARTIFACT}}-linux-amd64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-linux-amd64
method: checksum

release-linux-arm64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-linux-arm64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-arm64"
sources:
- bin/{{.ARTIFACT}}-linux-arm64
generates:
- dist/{{.ARTIFACT}}-linux-arm64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-linux-arm64
method: checksum

release-linux-arm7:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-linux-arm7-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-linux-arm7"
sources:
- bin/{{.ARTIFACT}}-linux-arm7
generates:
- dist/{{.ARTIFACT}}-linux-arm7-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-linux-arm7
method: checksum

release-windows-amd64:
cmds:
- "tar cfJ dist/{{.ARTIFACT}}-windows-amd64-$RELEASE.tar.xz -C bin {{.ARTIFACT}}-windows-amd64.exe"
sources:
- bin/{{.ARTIFACT}}-windows-amd64.exe
generates:
- dist/{{.ARTIFACT}}-windows-amd64-$RELEASE.tar.xz
preconditions:
- test -f bin/{{.ARTIFACT}}-windows-amd64.exe
method: checksum

release-checksum:
deps:
- release-all
cmds:
- cd dist && sha256sum {{.ARTIFACT}}-*.tar.xz > {{.ARTIFACT}}-checksum.txt
- cd dist && gpg --detach-sign --armor {{.ARTIFACT}}-checksum.txt
- cat dist/{{.ARTIFACT}}-checksum.txt
- mage homebrew > dist/harp-server.rb
generates:
- dist/{{.ARTIFACT}}-checksum.txt
- dist/{{.ARTIFACT}}-checksum.txt.asc

release-formula:
deps:
- release-all
cmds:
- mage homebrew > dist/{{.ARTIFACT}}.rb
generates:
- dist/{{.ARTIFACT}}.rb
4 changes: 4 additions & 0 deletions cmd/harp-server/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func Release(ctx context.Context) error {
)()
},
func() error {
if !golang.Is("go1.16rc1", "go1.16") {
// Skip the build
return nil
}
return golang.Release(
"harp-server",
"github.com/elastic/harp/cmd/harp-server",
Expand Down
4 changes: 4 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func Release(ctx context.Context) error {
)()
},
func() error {
if !golang.Is("go1.16rc1", "go1.16") {
// Skip the build
return nil
}
return golang.Release(
"harp",
"github.com/elastic/harp/cmd/harp",
Expand Down

0 comments on commit 6d513b6

Please sign in to comment.