-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add goreleaser-release command (#78)
* feat: add goreleaser-release command * ci: add test for goreleaser release * ci: add app for testing * docs: add goreleaser release example * fix: lint errors
- Loading branch information
Showing
8 changed files
with
162 additions
and
3 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
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 @@ | ||
description: | | ||
Build Go applications and release them on GitHub. | ||
GoReleaser CLI must be installed and a GitHub Token | ||
with write:packages permissions is also required. | ||
parameters: | ||
github-token: | ||
description: | | ||
A GitHub Token is with write:packages permissions is required. | ||
type: string | ||
default: GITHUB_TOKEN | ||
project-path: | ||
description: | | ||
The path to the directory containing your Go project files: | ||
.goreleaser.yaml, go.mod, main.go. | ||
Defaults to $HOME. | ||
type: string | ||
default: $HOME | ||
validate-yaml: | ||
description: | | ||
Set to true to validate .goreleaser.yaml. | ||
type: boolean | ||
default: false | ||
publish-release: | ||
description: | | ||
Set to true to publish release to GitHub | ||
type: boolean | ||
default: false | ||
steps: | ||
- run: | ||
name: "Build and release Go Binaries to GitHub with GoReleaser" | ||
environment: | ||
GITHUB_TOKEN: << parameters.github-token >> | ||
GO_BOOL_VALIDATE_YAML: << parameters.validate-yaml >> | ||
GO_BOOL_PUBLISH_RELEASE: << parameters.publish-release >> | ||
GO_EVAL_PROJECT_PATH: << parameters.project-path >> | ||
command: << include(scripts/goreleaser-release.sh) >> |
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,25 @@ | ||
description: | | ||
Build Go applications and release them on GitHub. | ||
Install GoReleaser CLI and add a GitHub Token with | ||
write:packages permissions and store as environment variable. | ||
usage: | ||
version: 2.1 | ||
orbs: | ||
go: circleci/[email protected] | ||
jobs: | ||
go-build-release: | ||
executor: | ||
name: go/default | ||
tag: "1.20.8" | ||
steps: | ||
- go/install-goreleaser | ||
- go/goreleaser-release: | ||
# validate .goreleaser.yml | ||
validate-yaml: true | ||
# publish release on GitHub | ||
publish-release: true | ||
project-path: /path/to/Go/project | ||
workflows: | ||
main: | ||
jobs: | ||
- go-build-release |
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,27 @@ | ||
#!/bin/bash | ||
|
||
GITHUB_TOKEN="$(echo "\$$GITHUB_TOKEN" | circleci env subst)" | ||
GO_EVAL_PROJECT_PATH="$(eval echo "${GO_EVAL_PROJECT_PATH}")" | ||
|
||
# Change to directory containing project files | ||
cd "${GO_EVAL_PROJECT_PATH}" || return | ||
|
||
if [ -z "${GITHUB_TOKEN}" ]; then | ||
echo "No GitHub Token provided. Please add token as environment variable in CircleCI." | ||
exit 1 | ||
fi | ||
|
||
if [ "$GO_BOOL_VALIDATE_YAML" -eq 1 ]; then | ||
# Validate .goreleaser.yaml file | ||
goreleaser check | ||
fi | ||
|
||
if [ "$GO_BOOL_PUBLISH_RELEASE" -eq 1 ]; then | ||
# Build binaries and publish release to GitHub | ||
goreleaser release | ||
else | ||
# Build binaries and test release locally | ||
goreleaser release --snapshot --clean | ||
fi | ||
|
||
|
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,44 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
|
||
# The lines bellow are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/need to use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of `uname`. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
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,3 @@ | ||
module main | ||
|
||
go 1.20 |
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,6 @@ | ||
// main.go | ||
package main | ||
|
||
func main() { | ||
println("Hello, World!") | ||
} |