-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
238 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- edited | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# dependencies | ||
- name: dependencies | ||
run: | | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b /usr/local/bin v1.24.0 | ||
curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sudo sh -s -- -b /usr/local/bin v0.128.0 | ||
# checkout | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
# unshallow (for goreleaser) | ||
- name: unshallow | ||
run: git fetch --prune --unshallow | ||
|
||
# setup go | ||
- name: go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.14 | ||
|
||
# lint | ||
- name: lint | ||
run: | | ||
make lint | ||
# test | ||
- name: test | ||
run: | | ||
make test | ||
# cache | ||
- name: cache | ||
uses: actions/cache@v1 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
# vendor | ||
- name: vendor | ||
run: | | ||
make vendor | ||
# build | ||
- name: build | ||
if: startsWith(github.ref, 'refs/tags/') == false | ||
run: | | ||
make snapshot | ||
# publish | ||
- name: publish | ||
if: startsWith(github.ref, 'refs/tags/') | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
make publish | ||
# artifacts | ||
- name: artifact_linux | ||
uses: actions/upload-artifact@v2-preview | ||
with: | ||
name: build_linux | ||
path: dist/*linux*.tar.gz | ||
|
||
- name: artifact_darwin | ||
uses: actions/upload-artifact@v2-preview | ||
with: | ||
name: build_darwin | ||
path: dist/*darwin*.tar.gz | ||
|
||
# - name: artifact_windows | ||
# uses: actions/upload-artifact@v2-preview | ||
# with: | ||
# name: build_windows | ||
# path: dist/*windows*.zip |
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,45 @@ | ||
# https://goreleaser.com | ||
project_name: crop | ||
|
||
# Build | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
# - windows | ||
goarch: | ||
- amd64 | ||
ldflags: | ||
- -s -w | ||
- -X "github.com/l3uddz/crop/runtime.Version={{ .Version }}" | ||
- -X "github.com/l3uddz/crop/runtime.GitCommit={{ .ShortCommit }}" | ||
- -X "github.com/l3uddz/crop/runtime.Timestamp={{ .Timestamp }}" | ||
flags: | ||
- -trimpath | ||
|
||
# Archive | ||
archives: | ||
- name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
format: "tar.gz" | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
# Checksum | ||
checksum: | ||
name_template: "checksums.txt" | ||
algorithm: sha512 | ||
|
||
# Snapshot | ||
snapshot: | ||
name_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .ShortCommit }}" | ||
|
||
# Changelog | ||
changelog: | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" | ||
- "^Merge branch" |
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,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"bufio" | ||
"github.com/blang/semver" | ||
"github.com/l3uddz/crop/runtime" | ||
"github.com/rhysd/go-github-selfupdate/selfupdate" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var updateCmd = &cobra.Command{ | ||
Use: "update", | ||
Short: "Update to latest version", | ||
Long: `This command can be used to self-update to the latest version.`, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
// init core | ||
initCore(false) | ||
|
||
// parse current version | ||
v, err := semver.Parse(runtime.Version) | ||
if err != nil { | ||
log.WithError(err).Fatal("Failed parsing current build version") | ||
} | ||
|
||
// detect latest version | ||
log.Info("Checking for the latest version...") | ||
latest, found, err := selfupdate.DetectLatest("l3uddz/crop") | ||
if err != nil { | ||
log.WithError(err).Fatal("Failed determining latest available version") | ||
} | ||
|
||
// check version | ||
if !found || latest.Version.LTE(v) { | ||
log.Infof("Already using the latest version: %v", runtime.Version) | ||
return | ||
} | ||
|
||
// ask update | ||
log.Infof("Do you want to update to the latest version: %v? (y/n):", latest.Version) | ||
input, err := bufio.NewReader(os.Stdin).ReadString('\n') | ||
if err != nil || (input != "y\n" && input != "n\n") { | ||
log.Fatal("Failed validating input...") | ||
} else if input == "n\n" { | ||
return | ||
} | ||
|
||
// get existing executable path | ||
exe, err := os.Executable() | ||
if err != nil { | ||
log.WithError(err).Fatal("Failed locating current executable path") | ||
} | ||
|
||
if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil { | ||
log.WithError(err).Fatal("Failed updating existing binary to latest release") | ||
} | ||
|
||
log.Infof("Successfully updated to the latest version: %v", latest.Version) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(updateCmd) | ||
} |
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
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,11 @@ | ||
{ | ||
"extends": [ | ||
"config:base" | ||
], | ||
"baseBranches": [ | ||
"develop" | ||
], | ||
"postUpdateOptions": [ | ||
"gomodTidy" | ||
] | ||
} |