Skip to content

Commit 1bb22e1

Browse files
committed
ci: github actions for release workflow
1 parent 418b593 commit 1bb22e1

File tree

4 files changed

+124
-15
lines changed

4 files changed

+124
-15
lines changed

.github/workflows/release.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build-binary:
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
os: [ubuntu-latest, macos-14, macos-13]
14+
arch: [amd64, arm64]
15+
include:
16+
- os: ubuntu-latest
17+
goos: linux
18+
platform: linux
19+
- os: macos-13
20+
goos: darwin
21+
platform: darwin
22+
- os: macos-14
23+
goos: darwin
24+
platform: darwin
25+
exclude:
26+
- os: macos-14
27+
arch: amd64
28+
- os: macos-13
29+
arch: arm64
30+
name: Building fwatcher-${{ matrix.platform }}-${{ matrix.arch }}
31+
runs-on: ${{ matrix.os }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- uses: nxtcoder17/actions/setup-cache-go@v1
36+
with:
37+
cache_key: "fwatcher"
38+
working_directory: .
39+
40+
# it will set 2 env variables
41+
# IMAGE_TAG - image tag
42+
# OVERRIDE_PUSHED_IMAGE - if true, it will not use pushed image tag
43+
- uses: nxtcoder17/actions/generate-image-tag@v1
44+
id: tag_name
45+
46+
- uses: nxtcoder17/actions/setup-nix-cachix@v1
47+
with:
48+
flake_lock: "./flake.lock"
49+
nix_develop_arguments: ".#default"
50+
cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }}
51+
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}
52+
53+
54+
- name: Build Binary
55+
shell: bash
56+
run: |+
57+
task build version=${IMAGE_TAG} GOOS=${{matrix.goos}} GOARCH=${{matrix.arch}} upx=${{ matrix.platform == 'linux' }} binary=fwatcher-${{matrix.goos}}-${{matrix.arch}}
58+
59+
- name: Upload Artifact
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: fwatcher-${{ matrix.platform }}-${{ matrix.arch }}
63+
path: bin/*
64+
65+
release:
66+
permissions:
67+
contents: write
68+
packages: write
69+
70+
needs: build-binary
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Download all artifacts
74+
uses: actions/download-artifact@v4
75+
with:
76+
path: ${{ github.workspace }}/binaries
77+
pattern: "fwatcher-*"
78+
79+
- name: flattening all the artifacts
80+
shell: bash
81+
run: |+
82+
ls -R ${{ github.workspace }}/binaries
83+
mkdir -p ${{ github.workspace }}/upload/binaries
84+
shopt -s globstar
85+
file ./** | grep 'executable,' | awk -F: '{print $1}' | xargs -I {} cp {} ${{ github.workspace }}/upload/binaries
86+
shopt -u globstar
87+
88+
- uses: nxtcoder17/actions/generate-image-tag@v1
89+
id: tag_name
90+
91+
- name: upload to github release
92+
shell: bash
93+
env:
94+
GH_TOKEN: ${{ github.token }}
95+
run: |+
96+
gh release upload $IMAGE_TAG -R ${{github.repository}} ${{github.workspace}}/upload/binaries/*

Taskfile.yml

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
version: 3
22

33
vars:
4-
Name: "fwatcher"
5-
Bin: "./bin/{{.Name}}"
4+
name: "fwatcher"
65

76
tasks:
87
dev:
@@ -11,12 +10,29 @@ tasks:
1110

1211
dev:build:
1312
cmds:
14-
- go build -o {{.Bin}}
13+
- go build -ldflags "-s -w -X main.Version={{.version}}" -o ./bin/{{.name}}
1514

1615
build:
16+
requires:
17+
vars:
18+
- version
19+
vars:
20+
upx: '{{.upx | default "false"}}'
21+
binary: '{{.binary | default .name }}'
22+
# GOOS:
23+
# sh: go env GOOS
24+
# GOARCH:
25+
# sh: go env GOARCH
26+
env:
27+
GOOS: '{{ .GOOS }}'
28+
GOARCH: '{{ .GOARCH }}'
1729
cmds:
18-
- go build -o {{.Bin}}
19-
- upx {{.Bin}}
30+
- echo "building binary for ${GOOS:-$(go env GOOS)} (${GOARCH:-$(go env GOARCH)})"
31+
- go build -ldflags "-s -w -X main.Version={{.version}}" -o ./bin/{{.binary}}
32+
- |+
33+
if [[ "{{.upx}}" = "true" ]]; then
34+
upx ./bin/{{.binary}}
35+
fi
2036
2137
example:http-server:
2238
cmds:

flake.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
go_1_22
2323
upx
24+
go-task
2425
];
2526

2627
shellHook = ''
27-
# '';
28+
'';
2829
};
2930
}
3031
);

main.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,23 @@ import (
1616
"github.com/urfave/cli/v2"
1717
)
1818

19+
var Version string
20+
1921
func main() {
2022
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
2123
defer stop()
2224

2325
app := &cli.App{
24-
Name: "fwatcher",
25-
Usage: "watches files in directories and operates on their changes",
26+
Name: "fwatcher",
27+
Usage: "watches files in directories and operates on their changes",
28+
Version: Version,
2629
Flags: []cli.Flag{
2730
&cli.BoolFlag{
2831
Name: "debug",
2932
Usage: "toggles showing debug logs",
3033
Required: false,
3134
Value: false,
3235
},
33-
&cli.BoolFlag{
34-
Name: "no-default-ignore",
35-
Usage: "disables ignoring from default ignore list",
36-
Required: false,
37-
Aliases: []string{"I"},
38-
Value: false,
39-
},
4036
&cli.StringFlag{
4137
Name: "command",
4238
Usage: "specifies command to execute on file change",

0 commit comments

Comments
 (0)