-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github Actions CI and v1.0.0 release prep (#1)
- Loading branch information
1 parent
77ea885
commit 00fe1a6
Showing
6 changed files
with
310 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Tests | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
go: | ||
- "1.14.x" | ||
- "1.15.x" | ||
- "1.16.x" | ||
- "1.17.x" | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
- windows-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Check version | ||
run: go version | ||
|
||
- name: Run tests with coverage | ||
if: matrix.os != 'windows-latest' | ||
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... | ||
|
||
- name: Run tests without coverage (windows) | ||
if: matrix.os == 'windows-latest' | ||
run: go test -race ./... | ||
|
||
- name: Upload coverage | ||
if: matrix.os != 'windows-latest' | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: release | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-ruby@v1 | ||
with: | ||
ruby-version: '2.5' | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.14 | ||
|
||
- name: Run tests | ||
run: go test -race ./... | ||
|
||
- name: Build and publish | ||
run: rake build | ||
|
||
# - name: Archive action artifacts | ||
# uses: actions/upload-artifact@v2 | ||
# with: | ||
# name: artifacts | ||
# path: build/artifacts/* | ||
|
||
- name: Upload artifacts to release | ||
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
artifacts: "build/artifacts/*" | ||
bodyFile: "build/release_notes" | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# v1.0.0 | ||
|
||
Initial stable release | ||
|
||
## Main Features | ||
|
||
- Drop-in replacement for built-in `errors` package | ||
- Sentinel error type | ||
- Error composition, directly or through Sentinel errors interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
# ============================================================================= | ||
# | ||
# MODULE : rakefile.rb | ||
# PROJECT : go-errors | ||
# DESCRIPTION : | ||
# | ||
# Copyright (c) 2016-2021, Marc-Antoine Argenton. All rights reserved. | ||
# ============================================================================= | ||
|
||
require 'fileutils' | ||
|
||
task default: [:build] | ||
|
||
desc 'Display version and information that will be incldued in build' | ||
task :info do | ||
puts "Version: #{BuildInfo.default.version}" | ||
puts "Remote: #{BuildInfo.default.remote}" | ||
puts "Commit: #{BuildInfo.default.commit}" | ||
puts "Dir: #{BuildInfo.default.dir}" | ||
end | ||
|
||
desc 'Build and publish both release archive and associated container image' | ||
task :build do | ||
FileUtils.makedirs( ['./build/artifacts'] ) | ||
version = BuildInfo.default.version | ||
puts "Version: #{version}" | ||
File.write( 'build/release_notes', generate_release_notes(version, | ||
# prefix: "go-errors", | ||
input:'RELEASES.md', | ||
)) | ||
end | ||
|
||
desc 'Remove build artifacts' | ||
task :clean do | ||
FileUtils.rm_rf('./build') | ||
end | ||
|
||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
# BuildInfo : Helper to extract version inforrmation for git repo | ||
# ---------------------------------------------------------------------------- | ||
|
||
class BuildInfo | ||
class << self | ||
def default() return @default ||= new end | ||
end | ||
|
||
def initialize() | ||
if _git('rev-parse --is-shallow-repository') == 'true' | ||
puts "Fetching missing information from remote ..." | ||
system(' git fetch --prune --tags --unshallow') | ||
end | ||
end | ||
|
||
def version() return @version ||= _version() end | ||
def remote() return @remote ||= _remote() end | ||
def commit() return @commit ||= _commit() end | ||
def dir() return @dir ||= _dir() end | ||
|
||
private | ||
def _git( cmd ) return `git #{cmd} 2>/dev/null`.strip() end | ||
def _commit() return _git('rev-parse HEAD') end | ||
def _dir() return _git('rev-parse --show-toplevel') end | ||
|
||
def _version() | ||
v, b, n, g = _info() | ||
m = _mtag() | ||
v, b, n, g, m = _fix_up_patch(v, b, n, g, m) | ||
return v if _is_default_branch(b, v) && n == 0 && m.nil? | ||
return "#{v}-" + [b, n, g, m].compact().join('.') | ||
end | ||
|
||
def _info() | ||
# Note: Due to glob(7) limitations, the following pattern enforces | ||
# 3-part dot-separated sequences starting with a digit, | ||
# rather than 3 dot-separated numbers. | ||
d = _git("describe --always --tags --long --match 'v[0-9]*.[0-9]*.[0-9]*'").strip.split('-') | ||
if d.count != 0 | ||
b = _git("rev-parse --abbrev-ref HEAD").strip.gsub(/[^A-Za-z0-9\._-]+/, '-') | ||
return ['v0.0.0', b, _git("rev-list --count HEAD").strip.to_i, "g#{d[0]}"] if d.count == 1 | ||
return [d[0], b, d[1].to_i, d[2]] if d.count == 3 | ||
end | ||
return ['v0.0.0', "none", 0, 'g0000000'] | ||
end | ||
|
||
def _is_default_branch(b, v = nil) | ||
# Check branch name against common main branch names, and branch name | ||
# that matches the beginning of the version strings e.g. 'v1' is | ||
# considered a default branch for version 'v1.x.y'. | ||
return ["main", "master", "HEAD"].include?(b) || | ||
(!v.nil? && v.start_with?(b)) | ||
end | ||
|
||
def _fix_up_patch(v, b, n, g, m) | ||
# If the number of commits since the latest tag is greater than zero, | ||
# increment the patch number by 1, so that the generated version string | ||
# sorts between the last tag and the next tag according to semver. | ||
# v0.6.1 | ||
# v0.6.1-maa-cleanup.1.g6ede8cd <-- with _fix_up_patch() | ||
# v0.6.0 | ||
# v0.6.0-maa-cleanup.1.g6ede8cd <-- without _fix_up_patch() | ||
# v0.5.99 | ||
if n > 0 || !_is_default_branch(b, v) | ||
vv = v[1..-1].split('.').map { |v| v.to_i } | ||
vv[-1] += 1 | ||
v = "v" + vv.join(".") | ||
end | ||
return v, b, n, g, m | ||
end | ||
|
||
def _mtag() | ||
status = _git("status --porcelain=2 --untracked-files=no") | ||
files = status.lines.map {|l| l.strip.split(/ +/).last }.map { |n| n.split(/\t/).first } | ||
t = files.map { |f| File.mtime(f).to_i rescue nil }.compact.max | ||
return t.nil? ? nil : "m%08x" % t | ||
end | ||
|
||
GIT_SSH_REPO = /git@(?<host>[^:]+):(?<path>.+).git/ | ||
def _remote() | ||
remote = _git('remote get-url origin') | ||
m = GIT_SSH_REPO.match(remote) | ||
return remote if m.nil? | ||
|
||
host = m[:host] | ||
host = "github.com" if host.end_with? ("github.com") | ||
return "https://#{host}/#{m[:path]}/" | ||
end | ||
end | ||
|
||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
# Release notes generator | ||
# ---------------------------------------------------------------------------- | ||
|
||
def generate_release_notes(version, prefix:nil, input:nil, checksums:nil) | ||
rn = "" | ||
rn += "#{prefix} #{version}\n\n" if prefix | ||
rn += load_release_notes(input, version) if input | ||
rn += "\n## Checksums\n\n```\n" + File.read(checksums) + "```\n" if checksums | ||
rn | ||
end | ||
|
||
def load_release_notes(filename, version) | ||
notes, capture = [], false | ||
File.readlines(filename).each do |l| | ||
if l.start_with?( "# ") | ||
break if capture | ||
capture = true if version.start_with?(l[2..-1].strip()) | ||
elsif capture | ||
notes << l | ||
end | ||
end | ||
notes.shift while (notes.first || "-").strip == "" | ||
return notes.join() | ||
end | ||
|
||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
# Definitions to help formating 'rake watch' results | ||
# ---------------------------------------------------------------------------- | ||
|
||
TERM_WIDTH = `tput cols`.to_i || 80 | ||
|
||
def tty_red(str); "\e[31m#{str}\e[0m" end | ||
def tty_green(str); "\e[32m#{str}\e[0m" end | ||
def tty_blink(str); "\e[5m#{str}\e[25m" end | ||
def tty_reverse_color(str); "\e[7m#{str}\e[27m" end | ||
|
||
def print_separator( success = true ) | ||
if success | ||
puts tty_green( "-" * TERM_WIDTH ) | ||
else | ||
puts tty_reverse_color(tty_red( "-" * TERM_WIDTH )) | ||
end | ||
end | ||
|
||
|
||
|
||
# ---------------------------------------------------------------------------- | ||
# Definition of watch task, that monitors the project folder for any relevant | ||
# file change and runs the unit test of the project. | ||
# ---------------------------------------------------------------------------- | ||
|
||
def watch( *glob ) | ||
yield unless block_given? | ||
files = [] | ||
loop do | ||
new_files = Dir[*glob].map {|file| File.mtime(file) } | ||
yield if new_files != files | ||
files = new_files | ||
sleep 0.5 | ||
end | ||
end | ||
|
||
# task :watch do | ||
# watch( '**/*.{c,cc,cpp,h,hh,hpp,ld}', 'Makefile' ) do | ||
# success = system "clear && rake" | ||
# print_separator( success ) | ||
# end | ||
# end |