From e7eba669169f79712af2045df6cd9f783c084d94 Mon Sep 17 00:00:00 2001 From: ze0s <43699394+zze0s@users.noreply.github.com> Date: Tue, 10 Dec 2024 02:29:09 +0100 Subject: [PATCH] build: update actions workflows (#3) * build: update workflow and goreleaser * chore: update FUNDING.yml * build: update ignores * build: update Makefile * build: update goreleaser actions * build: update goreleaser config * build: update dep go-set * build: add linkinfo_freebsd.go --- .github/FUNDING.yml | 4 +- .github/workflows/build.yml | 138 +++++++++++---------- .github/workflows/remove_old_artifacts.yml | 17 --- .goreleaser.yml | 90 ++++++++++---- Makefile | 6 +- go.mod | 2 +- go.sum | 4 +- hardlinkfilemap/linkinfo_freebsd.go | 19 +++ 8 files changed, 166 insertions(+), 114 deletions(-) delete mode 100644 .github/workflows/remove_old_artifacts.yml create mode 100644 hardlinkfilemap/linkinfo_freebsd.go diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index e7fac79..585ad14 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,3 @@ -github: l3uddz \ No newline at end of file +github: + - l3uddz + - zze0s diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c35bc3e..c9806b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,88 +3,100 @@ name: Build on: push: branches: - - '*' + - "master" tags: - 'v*' + paths-ignore: + - '.github/ISSUE_TEMPLATE/**' + - '.github/images/**' + - 'config.yaml' + - 'docker-compose.yml' + - 'Makefile' + - '**.md' + pull_request: + paths-ignore: + - '.github/ISSUE_TEMPLATE/**' + - '.github/images/**' + - 'config.yaml' + - 'docker-compose.yml' + - 'Makefile' + - '**.md' + +env: + REGISTRY: ghcr.io + REGISTRY_IMAGE: ghcr.io/${{ github.repository }} + GO_VERSION: '1.23' + +permissions: + contents: write + packages: write jobs: - build: + test: + name: Test runs-on: ubuntu-latest steps: - # dependencies - - name: goreleaser - uses: goreleaser/goreleaser-action@v2 - with: - install-only: true - version: 1.7.0 - - - name: goreleaser version - run: goreleaser -v - - # checkout - - name: checkout - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v4 with: fetch-depth: 0 - # setup go - - name: go - uses: actions/setup-go@v1 + - name: Set up Go + uses: actions/setup-go@v5 with: - go-version: 1.19 + go-version: ${{ env.GO_VERSION }} + cache: true - - name: go info - run: | - go version - go env + - name: Test + run: go run gotest.tools/gotestsum@latest --junitfile unit-tests.xml --format pkgname -- ./... - # cache - - name: cache - uses: actions/cache@v1 + - name: Test Summary + uses: test-summary/action@v2 with: - path: vendor - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - # vendor - - name: vendor - run: | - make vendor + paths: "unit-tests.xml" + if: always() - # git status - - name: git status - run: git status + goreleaser: + name: Build and publish Go binaries + runs-on: ubuntu-latest + needs: [test] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 - # build - - name: build - if: startsWith(github.ref, 'refs/tags/') == false - run: | - make snapshot + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true - # publish - - name: publish - if: startsWith(github.ref, 'refs/tags/') == true + - name: Run GoReleaser build + if: github.event_name == 'pull_request' + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean --skip=validate,publish --parallelism 5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - make publish - # artifacts - - name: artifact_linux - uses: actions/upload-artifact@v2-preview + - name: Run GoReleaser build and publish tags + if: startsWith(github.ref, 'refs/tags/') + uses: goreleaser/goreleaser-action@v6 with: - name: build_linux - path: dist/*linux* - - - name: artifact_darwin - uses: actions/upload-artifact@v2-preview - with: - name: build_darwin - path: dist/*darwin* + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: artifact_windows - uses: actions/upload-artifact@v2-preview + - name: Upload assets + uses: actions/upload-artifact@v4 with: - name: build_windows - path: dist/*windows* \ No newline at end of file + name: tqm + path: | + dist/*.tar.gz + dist/*.json + dist/*.yaml \ No newline at end of file diff --git a/.github/workflows/remove_old_artifacts.yml b/.github/workflows/remove_old_artifacts.yml deleted file mode 100644 index 3741f72..0000000 --- a/.github/workflows/remove_old_artifacts.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Remove old artifacts - -on: - schedule: - - cron: '0 1 * * *' - -jobs: - remove-old-artifacts: - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - name: Remove old artifacts - uses: c-hive/gha-remove-artifacts@v1 - with: - age: '1 hour' - skip-recent: 1 \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index a80babd..870ec2d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,50 +1,86 @@ # https://goreleaser.com +version: 2 project_name: tqm +before: + hooks: + - go mod tidy + # Build builds: - - + - id: tqm env: - CGO_ENABLED=0 + flags: + - -trimpath + ldflags: + - -s -w + - -X "github.com/autobrr/tqm/runtime.Version={{ .Version }}" + - -X "github.com/autobrr/tqm/runtime.GitCommit={{ .ShortCommit }}" + - -X "github.com/autobrr/tqm/runtime.Timestamp={{ .Timestamp }}" goos: - linux - - darwin - windows + - darwin + - freebsd goarch: - amd64 + - arm - arm64 - ldflags: - - -s -w - - -X "github.com/autobrr/tqm/runtime.Version={{ .Version }}" - - -X "github.com/autobrr/tqm/runtime.GitCommit={{ .ShortCommit }}" - - -X "github.com/autobrr/tqm/runtime.Timestamp={{ .Timestamp }}" - flags: - - -trimpath + goarm: + - 6 + ignore: + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + - goos: darwin + goarch: arm + - goos: freebsd + goarch: arm + - goos: freebsd + goarch: arm64 + main: main.go + binary: tqm -# MacOS Universal Binaries -universal_binaries: - - - replace: true - -# Archive archives: - - - name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}" - format: "binary" + - id: tqm + builds: + - tqm + format_overrides: + - goos: windows + format: zip -# Checksum checksum: - name_template: "checksums.txt" - algorithm: sha512 + name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt' -# Snapshot snapshot: - name_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .ShortCommit }}" + version_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .ShortCommit }}" + +release: + prerelease: auto + footer: | + **Full Changelog**: https://github.com/autobrr/tqm/compare/{{ .PreviousTag }}...{{ .Tag }} + + ## What to do next? + + - Read the [documentation](https://autobrr.com) + - Join our [Discord server](https://discord.gg/WQ2eUycxyT) -# Changelog changelog: + sort: asc + use: github filters: exclude: - - "^docs:" - - "^test:" - - "^Merge branch" \ No newline at end of file + - Merge pull request + - Merge remote-tracking branch + - Merge branch + groups: + - title: 'New Features' + regexp: "^.*feat[(\\w)]*:+.*$" + order: 0 + - title: 'Bug fixes' + regexp: "^.*fix[(\\w)]*:+.*$" + order: 10 + - title: Other work + order: 999 diff --git a/Makefile b/Makefile index 55c7197..f1056f0 100644 --- a/Makefile +++ b/Makefile @@ -60,15 +60,15 @@ fetch: ## Fetch vendor files .PHONY: release release: check_goreleaser ## Generate a release, but don't publish - goreleaser --skip-validate --skip-publish --rm-dist + goreleaser --skip=validate --skip=publish --clean .PHONY: publish publish: check_goreleaser ## Generate a release, and publish - goreleaser --rm-dist + goreleaser --clean .PHONY: snapshot snapshot: check_goreleaser ## Generate a snapshot release - goreleaser --snapshot --skip-publish --rm-dist + goreleaser --snapshot --skip=publish --clean .PHONY: help help: diff --git a/go.mod b/go.mod index 4dd774b..612c6e6 100644 --- a/go.mod +++ b/go.mod @@ -54,7 +54,7 @@ require ( github.com/mattn/go-isatty v0.0.14 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect - github.com/scylladb/go-set v1.0.2 + github.com/scylladb/go-set v1.0.3-0.20200225121959-cc7b2070d91e github.com/spf13/pflag v1.0.5 // indirect github.com/tcnksm/go-gitconfig v0.1.2 // indirect golang.org/x/text v0.21.0 // indirect diff --git a/go.sum b/go.sum index 2c256e9..56613db 100644 --- a/go.sum +++ b/go.sum @@ -179,8 +179,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/sanity-io/litter v1.2.0/go.mod h1:JF6pZUFgu2Q0sBZ+HSV35P8TVPI1TTzEwyu9FXAw2W4= -github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE= -github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= +github.com/scylladb/go-set v1.0.3-0.20200225121959-cc7b2070d91e h1:7q6NSFZDeGfvvtIRwBrU/aegEYJYmvev0cHAwo17zZQ= +github.com/scylladb/go-set v1.0.3-0.20200225121959-cc7b2070d91e/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= diff --git a/hardlinkfilemap/linkinfo_freebsd.go b/hardlinkfilemap/linkinfo_freebsd.go new file mode 100644 index 0000000..1de6a47 --- /dev/null +++ b/hardlinkfilemap/linkinfo_freebsd.go @@ -0,0 +1,19 @@ +package hardlinkfilemap + +import ( + "errors" + "os" + "strconv" + "syscall" +) + +func LinkInfo(fi os.FileInfo, _ string) (string, uint64, error) { + sys, ok := fi.Sys().(*syscall.Stat_t) + if !ok { + return "", 0, errors.New("failed to get file identifier") + } + + return strconv.FormatUint(sys.Dev, 10) + "|" + strconv.FormatUint(sys.Ino, 10), + uint64(sys.Nlink), + nil +}