Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test - feat: fill version with git and ldflags #2

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,46 @@ on:
push:
tags:
- "*"
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
if: (!startsWith(github.ref, 'refs/tags/'))
strategy:
matrix:
version: ['1.18']
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.version }}
check-latest: true
cache: true
- name: Build and package with GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
version: ['1.18']
env:
GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ builds:
- linux
- windows
- darwin
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.builtBy=goreleaser'
archives:
- name_template: >-
{{ .ProjectName }}_
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
.EXPORT_ALL_VARIABLES:

VERSION := $(shell git describe --abbrev=0 --tags | tr -d v)
COMMIT := $(shell git rev-parse --short HEAD)
LDFLAGS := -X 'main.version=$(VERSION)' \
-X 'main.commit=$(COMMIT)'

.PHONY: build
build:
go build -o dist/yamlfmt ./cmd/yamlfmt
go build -ldflags "$(LDFLAGS)" -o dist/yamlfmt ./cmd/yamlfmt

.PHONY: test
test:
Expand Down Expand Up @@ -43,7 +48,7 @@ endif

.PHONY: install
install:
go install ./cmd/yamlfmt
go install -ldflags "$(LDFLAGS)" ./cmd/yamlfmt

.PHONY: install_tools
install_tools:
Expand Down
7 changes: 5 additions & 2 deletions cmd/yamlfmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (
"github.com/google/yamlfmt/internal/logger"
)

var version string = "0.12.0"
var (
version = "dev"
commit = "none"
)

func main() {
if err := run(); err != nil {
Expand All @@ -41,7 +44,7 @@ func run() error {
flag.Parse()

if *flagVersion {
fmt.Printf("%s\n", version)
fmt.Printf("yamlfmt %s (%s)\n", version, commit)
return nil
}

Expand Down
Loading