Skip to content

Commit

Permalink
Add go releaser
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Boissiere <victor.boissiere@qonto.com>
  • Loading branch information
victorboissiere committed Sep 2, 2024
1 parent 1462914 commit 4453a7d
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: release
run-name: building and publishing new release
on: # yamllint disable-line rule:truthy
push:
# run only against tags
tags:
- "*"
permissions:
contents: write # allows the action to create a Github release
id-token: write # This is required for requesting the AWS JWT

jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- run: git fetch --force --tags

- uses: actions/setup-go@v5
with:
go-version: stable

- name: Set up QEMU for ARM64 build
uses: docker/setup-qemu-action@v3

- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: unittest
on: # yamllint disable-line rule:truthy
push:
branches:
- "*"

permissions:
contents: read

jobs:
go:
name: go
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Install dependencies
run: |
go get .
- name: Build
run: go build
- name: Run Go tests
run: go test -v ./...

68 changes: 68 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
---
env:
- BUILD_INFO_PACKAGE_PATH=github.com/qonto/terraform-plan-linter/cmd

builds:
- env:
- CGO_ENABLED=0
ldflags:
- '-s'
- '-w'
- '-X "{{ .Env.BUILD_INFO_PACKAGE_PATH }}.Version={{.Version}}"'
- '-X "{{ .Env.BUILD_INFO_PACKAGE_PATH }}.CommitSHA={{.Commit}}"'
- '-X "{{ .Env.BUILD_INFO_PACKAGE_PATH }}.Date={{.Date}}"'
goos:
- linux
- darwin
goarch:
- amd64
- arm64

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc
use: github
filters:
exclude:
- "^test:"
- "^chore"
- "merge conflict"
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 300
- title: "New Features"
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: "Security updates"
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
order: 150
- title: "Bug fixes"
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: "Documentation updates"
regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$
order: 400
- title: "Build process updates"
regexp: ^.*?build(\([[:word:]]+\))??!?:.+$
order: 400
- title: Other work
order: 9999

release:
github:
owner: qonto
name: terraform-plan-linter
name_template: "v{{.Version}}"
footer: |
**Full Changelog**: https://github.com/qonto/terraform-plan-linter/compare/{{ .PreviousTag }}...{{ .Tag }}
7 changes: 7 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cmd

var (
Version = "unknown"
CommitSHA = "unknown"
Date = "unknown"
)
9 changes: 9 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ var rootCmd = &cobra.Command{
}

func Execute() {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\nCommit: %s\nDate: %s\n", Version, CommitSHA, Date)
},
}
rootCmd.AddCommand(versionCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down

0 comments on commit 4453a7d

Please sign in to comment.