Skip to content

Commit f51715e

Browse files
committed
Several updates
- Use skratchdot/open-golang to open files with their default editor - Update to go 1.20 - Update version logic - Remove distribution scripts - Update GitHub actions - Use GoReleaser to build artifacts - Update README.md
1 parent 2444ead commit f51715e

File tree

15 files changed

+173
-240
lines changed

15 files changed

+173
-240
lines changed

.github/workflows/build-release.yml

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,22 @@ jobs:
99
build:
1010
name: Build and release
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
goos: [windows]
15-
goarch: ["386", amd64]
16-
exclude:
17-
- goos: darwin
18-
goarch: "386"
1912

2013
steps:
21-
2214
- name: Set up Go
23-
uses: actions/setup-go@v2
15+
uses: actions/setup-go@v3
2416
with:
25-
go-version: ^1.19
17+
go-version: ^1.20
2618

2719
- name: Check out code into the Go module directory
28-
uses: actions/checkout@v2
29-
30-
- name: Build executable
31-
run: go build -v -ldflags="-X 'main.versionString=${{ github.event.release.tag_name }}'" .
32-
env:
33-
GOARCH: ${{ matrix.goarch }}
34-
GOOS: ${{ matrix.goos }}
35-
36-
- name: Create distribution archive
37-
run: go run -v ./scripts/dist
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
3823

39-
- name: Upload binary to release
40-
uses: svenstaro/upload-release-action@v2
24+
- name: Run GoReleaser
25+
uses: goreleaser/goreleaser-action@v4
4126
with:
42-
file: dist/dist.zip
43-
asset_name: batch-rename-${{ matrix.goos }}-${{ matrix.goarch }}.zip
44-
overwrite: true
27+
version: latest
28+
args: release --clean
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ jobs:
1010
steps:
1111

1212
- name: Set up Go
13-
uses: actions/setup-go@v2
13+
uses: actions/setup-go@v3
1414
with:
15-
go-version: ^1.19
15+
go-version: ^1.20
1616
id: go
1717

1818
- name: Check out code into the Go module directory
19-
uses: actions/checkout@v2
19+
uses: actions/checkout@v3
2020

2121
- name: Build
22-
run: go build -v .
22+
run: go build -v -ldflags="-X 'main.version=${{ github.event.release.tag_name }}'" .
2323

2424
- name: Test
25-
run: go test -v .
25+
run: go test -v -ldflags="-X 'main.version=${{ github.event.release.tag_name }}'" .

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ $RECYCLE.BIN/
7070

7171
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
7272

73-
/dist/
73+
dist/

.goreleaser.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
before:
2+
hooks:
3+
# You may remove this if you don't use go modules.
4+
- go mod tidy
5+
# you may remove this if you don't need go generate.
6+
#- go generate ./...
7+
builds:
8+
- env:
9+
- CGO_ENABLED=0
10+
goos:
11+
- linux
12+
- windows
13+
- darwin
14+
15+
archives:
16+
- format: tar.gz
17+
# this name template makes the OS and Arch compatible with the results of uname.
18+
name_template: >-
19+
{{ .ProjectName }}_
20+
{{- title .Os }}_
21+
{{- if eq .Arch "amd64" }}x86_64
22+
{{- else if eq .Arch "386" }}i386
23+
{{- else }}{{ .Arch }}{{ end }}
24+
{{- if .Arm }}v{{ .Arm }}{{ end }}
25+
# use zip for windows archives
26+
format_overrides:
27+
- goos: windows
28+
format: zip
29+
files:
30+
- LICENSE
31+
- README.md
32+
- screenshots/*
33+
checksum:
34+
name_template: 'checksums.txt'
35+
snapshot:
36+
name_template: "{{ incpatch .Version }}-dev+{{ .ShortCommit }}"
37+
changelog:
38+
sort: asc
39+
filters:
40+
exclude:
41+
- '^docs:'
42+
- '^test:'

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Package",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}"
13+
}
14+
]
15+
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"Dadido",
44
"GOARCH",
55
"goversion",
6+
"incpatch",
67
"ldflags",
8+
"skratchdot",
79
"svenstaro",
810
"Vogel",
911
"wangyoucao"

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ There are multiple ways to use this tool:
1919
- Download the compiled binary, then move and execute it into the directory you want to rename files in.
2020
- Download the compiled binary, and move it to any directory that is in your `path` environment variable. Afterwards you can run `batch-rename` from inside any directory.
2121
- Use `go install github.com/Dadido3/batch-rename`. Afterwards you can run `batch-rename` from inside any directory.
22+
- Build it yourself from source, see below.
23+
24+
## Building
25+
26+
This software uses GoReleaser to automatically build and upload artifacts to GitHub.
27+
Make sure to [install GoReleaser](https://goreleaser.com/install/).
28+
29+
- To build for your current platform use `goreleaser build --single-target --clean`. Or `goreleaser build --single-target --snapshot --clean` if you have modified the repository.
30+
- To simulate the release process, use `goreleaser --skip-publish --auto-snapshot --clean`.
31+
- To build for your current platform and without GoReleaser, use `go build`. This will not include the version information.

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
module github.com/Dadido3/batch-rename
22

3-
go 1.19
3+
go 1.20
44

5-
require (
6-
github.com/coreos/go-semver v0.3.0
7-
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326
8-
)
5+
require github.com/Masterminds/semver/v3 v3.2.0
96

10-
require gopkg.in/yaml.v2 v2.4.0 // indirect
7+
require github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966

go.sum

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
2-
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
3-
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
4-
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
5-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
7-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
1+
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
2+
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
3+
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
4+
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
"log"
1212
"os"
1313
"path/filepath"
14+
15+
"github.com/skratchdot/open-golang/open"
1416
)
1517

1618
func main() {
17-
log.Printf("Started batch-rename v%v", version)
19+
log.Printf("Started batch-rename %v", Version)
1820

1921
rootDir := "."
2022

@@ -57,7 +59,11 @@ func main() {
5759
log.Panicf("Failed to create temporary text file: %v", err)
5860
}
5961

60-
if err := openWithDefault(filePath); err != nil {
62+
/*if err := openWithDefault(filePath); err != nil {
63+
log.Panicf("Failed to open temporary text file: %v", err)
64+
}*/
65+
66+
if err := open.Run(filePath); err != nil {
6167
log.Panicf("Failed to open temporary text file: %v", err)
6268
}
6369

0 commit comments

Comments
 (0)