diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..716fe25 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,96 @@ +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 + shell: bash + run: |+ + task build version=${IMAGE_TAG} GOOS=${{matrix.goos}} GOARCH=${{matrix.arch}} upx=${{ matrix.platform == 'linux' }} binary=fwatcher-${{matrix.goos}}-${{matrix.arch}} + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: fwatcher-${{ matrix.platform }}-${{ matrix.arch }} + 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: + path: ${{ github.workspace }}/binaries + pattern: "fwatcher-*" + + - name: flattening all the artifacts + shell: bash + run: |+ + ls -R ${{ github.workspace }}/binaries + mkdir -p ${{ github.workspace }}/upload/binaries + shopt -s globstar + file ./** | grep 'executable,' | awk '{print $1}' | xargs -I {} cp {} ${{ github.workspace }}/upload/binaries + shopt -u globstar + + - uses: nxtcoder17/actions/generate-image-tag@v1 + id: tag_name + + - name: upload to github release + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: |+ + gh release upload $IMAGE_TAG -R ${{github.repository}} ${{github.workspace}}/upload/binaries/* diff --git a/Taskfile.yml b/Taskfile.yml index 609d9f9..190ab32 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,8 +1,7 @@ version: 3 vars: - Name: "fwatcher" - Bin: "./bin/{{.Name}}" + name: "fwatcher" tasks: dev: @@ -11,12 +10,29 @@ tasks: dev:build: cmds: - - go build -o {{.Bin}} + - go build -ldflags "-s -w -X main.Version={{.version}}" -o ./bin/{{.name}} build: + requires: + vars: + - version + vars: + upx: '{{.upx | default "false"}}' + binary: '{{.binary | default .name }}' + # GOOS: + # sh: go env GOOS + # GOARCH: + # sh: go env GOARCH + env: + GOOS: '{{ .GOOS }}' + GOARCH: '{{ .GOARCH }}' cmds: - - go build -o {{.Bin}} - - upx {{.Bin}} + - echo "building binary for ${GOOS:-$(go env GOOS)} (${GOARCH:-$(go env GOARCH)})" + - go build -ldflags "-s -w -X main.Version={{.version}}" -o ./bin/{{.binary}} + - |+ + if [[ "{{.upx}}" = "true" ]]; then + upx ./bin/{{.binary}} + fi example:http-server: cmds: diff --git a/flake.nix b/flake.nix index 3edc589..6080261 100644 --- a/flake.nix +++ b/flake.nix @@ -21,10 +21,11 @@ go_1_22 upx + go-task ]; shellHook = '' - # ''; + ''; }; } ); diff --git a/main.go b/main.go index 4aa2089..ae1dfb1 100644 --- a/main.go +++ b/main.go @@ -16,13 +16,16 @@ 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", @@ -30,13 +33,6 @@ func main() { 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",