From efc9d0173e33d28b6faa822efaae882b580e324c Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Tue, 10 Mar 2020 14:34:39 +0100 Subject: [PATCH] Add publishing to GH step without building binaries --- .drone.star | 66 +++++++++++++++++++++- Makefile | 3 + changelog/CHANGELOG.tmpl | 39 ++++++++++--- changelog/unreleased/tracing-middleware.md | 2 +- 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/.drone.star b/.drone.star index bdf2cd0164..fa8ea2d84c 100644 --- a/.drone.star +++ b/.drone.star @@ -5,6 +5,7 @@ def main(ctx): after = [ changelog(ctx), + publish(ctx), ] return stages + after @@ -130,6 +131,7 @@ def testing(ctx): } def changelog(ctx): + repo_slug = ctx.build.source_repo if ctx.build.source_repo else ctx.repo.slug return { 'kind': 'pipeline', 'type': 'docker', @@ -150,8 +152,8 @@ def changelog(ctx): 'actions': [ 'clone', ], - 'remote': 'https://github.com/%s' % (ctx.repo.slug), - 'branch': ctx.build.branch if ctx.build.event == 'pull_request' else 'master', + 'remote': 'https://github.com/%s' % (repo_slug), + 'branch': ctx.build.source if ctx.build.event == 'pull_request' else 'master', 'path': '/drone/src', 'netrc_machine': 'github.com', 'netrc_username': { @@ -170,6 +172,14 @@ def changelog(ctx): 'make changelog', ], }, + { + 'name': 'diff', + 'image': 'owncloud/alpine:latest', + 'pull': 'always', + 'commands': [ + 'git diff', + ], + }, { 'name': 'output', 'image': 'webhippie/golang:1.13', @@ -214,6 +224,58 @@ def changelog(ctx): 'trigger': { 'ref': [ 'refs/heads/master', + 'refs/pull/**', + ], + }, + } + +def publish(ctx): + return { + 'kind': 'pipeline', + 'type': 'docker', + 'name': 'publish', + 'platform': { + 'os': 'linux', + 'arch': 'amd64', + }, + 'steps': [ + { + 'name': 'prepare', + 'image': 'owncloud/alpine:latest', + 'pull': 'always', + 'commands': [ + 'mkdir -p dist', + ], + }, + { + 'name': 'changelog', + 'image': 'toolhippie/calens:latest', + 'pull': 'always', + 'commands': [ + 'calens --version %s -o dist/CHANGELOG.md' % ctx.build.ref.replace("refs/tags/v", "").split("-")[0], + ], + }, + { + 'name': 'release', + 'image': 'plugins/github-release:1', + 'pull': 'always', + 'settings': { + 'api_key': { + 'from_secret': 'github_token', + }, + 'files': [], + 'title': ctx.build.ref.replace("refs/tags/v", ""), + 'note': 'dist/CHANGELOG.md', + 'overwrite': True, + 'prerelease': len(ctx.build.ref.split("-")) > 1, + }, + }, + ], + 'depends_on': [ + 'testing', + ], + 'trigger': { + 'ref': [ 'refs/tags/**', ], }, diff --git a/Makefile b/Makefile index 2932f0c331..7d3e08ef72 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ SHELL := bash NAME := ocis-pkg IMPORT := github.com/owncloud/$(NAME) +BIN := bin +DIST := dist ifeq ($(OS), Windows_NT) UNAME := Windows @@ -33,6 +35,7 @@ sync: .PHONY: clean clean: go clean -i ./... + rm -rf $(BIN) $(DIST) .PHONY: fmt fmt: diff --git a/changelog/CHANGELOG.tmpl b/changelog/CHANGELOG.tmpl index 3fee894812..06388c3cb1 100644 --- a/changelog/CHANGELOG.tmpl +++ b/changelog/CHANGELOG.tmpl @@ -1,18 +1,43 @@ -{{- range $changes := . }}{{ with $changes -}} -# Changelog for {{ .Version }} +{{ $allVersions := . }} +{{- range $index, $changes := . }}{{ with $changes -}} +{{ if gt (len $allVersions) 1 -}} +# Changelog for [{{ .Version }}] ({{ .Date }}) -The following sections list the changes for {{ .Version }}. +The following sections list the changes in ocis-pkg {{ .Version }}. + +{{/* creating version compare links */ -}} +{{ $next := add1 $index -}} +{{ if ne (len $allVersions) $next -}} +{{ $previousVersion := (index $allVersions $next).Version -}} +{{ if eq .Version "unreleased" -}} +[{{ .Version }}]: https://github.com/owncloud/ocis-pkg/compare/v{{ $previousVersion }}...master + +{{ else -}} +[{{ .Version }}]: https://github.com/owncloud/ocis-pkg/compare/v{{ $previousVersion }}...v{{ .Version }} + +{{ end -}} +{{ end -}} + +{{- /* last version managed by calens, end of the loop */ -}} +{{ if eq .Version "1.0.0" -}} +[{{ .Version }}]: https://github.com/owncloud/ocis-pkg/compare/63fa90a673cbc3238a503ea5e6304f1db7fdf47b...v{{ .Version }} + +{{ end -}} +{{ else -}} +# Changes in {{ .Version }} + +{{ end -}} ## Summary {{ range $entry := .Entries }}{{ with $entry }} - * {{ .TypeShort }} #{{ .PrimaryID }}: {{ .Title }} +* {{ .Type }} - {{ .Title }}: [#{{ .PrimaryID }}]({{ .PrimaryURL }}) {{- end }}{{ end }} ## Details {{ range $entry := .Entries }}{{ with $entry }} - * {{ .Type }} #{{ .PrimaryID }}: {{ .Title }} +* {{ .Type }} - {{ .Title }}: [#{{ .PrimaryID }}]({{ .PrimaryURL }}) {{ range $par := .Paragraphs }} - {{ wrap $par 80 3 }} + {{ wrapIndent $par 80 3 }} {{ end -}} {{ range $url := .IssueURLs }} {{ $url -}} @@ -23,6 +48,6 @@ The following sections list the changes for {{ .Version }}. {{ range $url := .OtherURLs }} {{ $url -}} {{ end }} -{{ end }}{{ end }} {{ end }}{{ end -}} +{{ end }}{{ end -}} diff --git a/changelog/unreleased/tracing-middleware.md b/changelog/unreleased/tracing-middleware.md index 5361167592..a7c0a86d0d 100644 --- a/changelog/unreleased/tracing-middleware.md +++ b/changelog/unreleased/tracing-middleware.md @@ -1,4 +1,4 @@ -Feature: Tracing middleware +Enhancement: Tracing middleware A new tracing middleware has been added to unpack context propagation