Skip to content

Commit

Permalink
Add goreleaser support and -V flag for printing the version
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Mar 8, 2021
1 parent eb3cc62 commit ad7f9c1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
22 changes: 21 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
name: build
on: [push, pull_request]

on:
push:
branches:
- master
- main
tags:
- 'v*'
pull_request:


jobs:

test-build:
Expand All @@ -23,3 +33,13 @@ jobs:
- name: Build
run: go build ./...

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
# only release on tags
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: v0.156.1
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.FAILLINT_ACTIONS_BOT_TOKEN }}
37 changes: 37 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
project_name: faillint
release:
prerelease: auto # don't publish release with -rc1,-pre, etc suffixes
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
ldflags:
- -s -w -X main.version={{.Version}} -X main.date={{.Date}}
binary: "faillint"
nfpms:
- maintainer: Fatih Arslan
description: Report unwanted Go import path and declaration usages
homepage: https://github.com/fatih/faillint
license: BSD 3-Clause
formats:
- deb
- rpm
replacements:
darwin: macOS
archives:
- replacements:
darwin: macOS
format_overrides:
- goos: windows
format: zip
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/fatih/faillint/faillint"
"golang.org/x/tools/go/analysis/singlechecker"
)

var (
version string
date string
)

func main() {
// this is a small hack to implement the -V flag that is part of
// go/analysis framework. It'll allow us to print the version with -V, but
// the --help message will print the flags of the analyzer
ff := flag.NewFlagSet("faillint", flag.ContinueOnError)
v := ff.Bool("V", false, "print version and exit")
ff.Usage = func() {}
ff.Parse(os.Args[1:])
if *v {
fmt.Printf("faillint version %s (%s)\n", version, date)
os.Exit(0)
}

singlechecker.Main(faillint.NewAnalyzer())
}

0 comments on commit ad7f9c1

Please sign in to comment.