Skip to content

Commit

Permalink
ci: github actions for release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtcoder17 committed Sep 21, 2024
1 parent 418b593 commit bbdb191
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 13 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
build-binary:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-14, macos-13]
arch: [amd64, arm64]
include:
- os: ubuntu-latest
goos: linux
platform: linux
- os: macos-13
goos: darwin
platform: darwin
- os: macos-14
goos: darwin
platform: darwin
exclude:
- os: macos-14
arch: amd64
- os: macos-13
arch: arm64
name: Building fwatcher-${{ matrix.platform }}-${{ matrix.arch }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- uses: nxtcoder17/actions/setup-cache-go@v1
with:
cache_key: "fwatcher"
working_directory: .

# it will set 2 env variables
# IMAGE_TAG - image tag
# OVERRIDE_PUSHED_IMAGE - if true, it will not use pushed image tag
- uses: nxtcoder17/actions/generate-image-tag@v1
id: tag_name

- uses: nxtcoder17/actions/setup-nix-cachix@v1
with:
flake_lock: "./flake.lock"
nix_develop_arguments: ".#default"
cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }}
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}


- name: Build Binary
run: |+
task build version=${IMAGE_TAG} GOOS=${{matrix.goos}} GOARCH=${{matrix.arch}} upx=${{ matrix.platform == 'linux' }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: fwatcher-bin
path: bin/*

release:
permissions:
contents: write
packages: write

needs: build-binary
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
name: fwatcher-bin
path: binaries

- uses: nxtcoder17/actions/generate-image-tag@v1
id: tag_name

- name: upload to github release
shell: bash
run: |+
gh release upload $IMAGE_TAG -R ${{github.repository}} --clobber binaries/*
14 changes: 11 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ tasks:

dev:build:
cmds:
- go build -o {{.Bin}}
- go build -ldflags "-s -w -X main.Version={{.version}}" -o {{.Bin}}

build:
requires:
vars:
- version
vars:
upx: '{{.upx | default "false"}}'
cmds:
- go build -o {{.Bin}}
- upx {{.Bin}}
- go build -ldflags "-s -w -X main.Version={{.version}}" -o ./bin/{{.Name}}-{{.GOOS}}-{{.GOARCH}}
- |+
if [[ "{{.upx}}" = "true" ]]; then
upx ./bin/{{.Name}}-{{.GOOS}}-{{.GOARCH}}
fi
example:http-server:
cmds:
Expand Down
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

go_1_22
upx
go-task
];

shellHook = ''
# '';
'';
};
}
);
Expand Down
14 changes: 5 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@ import (
"github.com/urfave/cli/v2"
)

var Version string

func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
defer stop()

app := &cli.App{
Name: "fwatcher",
Usage: "watches files in directories and operates on their changes",
Name: "fwatcher",
Usage: "watches files in directories and operates on their changes",
Version: Version,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Usage: "toggles showing debug logs",
Required: false,
Value: false,
},
&cli.BoolFlag{
Name: "no-default-ignore",
Usage: "disables ignoring from default ignore list",
Required: false,
Aliases: []string{"I"},
Value: false,
},
&cli.StringFlag{
Name: "command",
Usage: "specifies command to execute on file change",
Expand Down

0 comments on commit bbdb191

Please sign in to comment.