From e997466cdfefe8e2b6acae15491ca9ae88e67c06 Mon Sep 17 00:00:00 2001 From: Tulip Blossom Date: Wed, 4 Dec 2024 16:36:11 -0300 Subject: [PATCH] feat: add goreleaser+linting for CI (and fixes) --- .github/workflows/lint.yaml | 24 +++++++++++++++++++++++ .github/workflows/release.yaml | 35 ++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ .goreleaser.yaml | 29 ++++++++++++++++++++++++++++ cmd/update.go | 17 ++++++++++++++--- distrobox.ini | 10 ++++++++++ justfile | 6 ++++++ lib/session.go | 3 ++- 8 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml create mode 100644 distrobox.ini diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..fbbca26 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,24 @@ +name: Lint +on: + push: + pull_request: + +permissions: + contents: read + pull-requests: read + checks: write + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + only-new-issues: true + version: v1.60 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b1e1fcc --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,35 @@ +name: goreleaser + +on: + pull_request: + push: + tags: + - "*" + +permissions: + contents: write + packages: write + issues: write + id-token: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser # goreleaser-pro + version: "latest" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.gitignore b/.gitignore index 6c8ed82..f3920cd 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ output/* *.key *.private *.log + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..98980b0 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,29 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/cmd/update.go b/cmd/update.go index f397f91..92d8a19 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -18,7 +18,12 @@ func Update(cmd *cobra.Command, args []string) { slog.Error(fmt.Sprintf("%v, is uupd already running?", err)) return } - defer lib.ReleaseLock(lock) + defer func() { + err := lib.ReleaseLock(lock) + if err != nil { + slog.Error("Failed releasing lock") + } + }() hwCheck, err := cmd.Flags().GetBool("hw-check") if err != nil { @@ -61,7 +66,10 @@ func Update(cmd *cobra.Command, args []string) { if err != nil { systemUpdater.Config.Enabled = false } else { - systemUpdater.Check() + _, err := systemUpdater.Check() + if err != nil { + slog.Error("Failed checking for system updates") + } } brewUpdater, err := drv.BrewUpdater{}.New(*initConfiguration) @@ -108,7 +116,10 @@ func Update(cmd *cobra.Command, args []string) { if systemUpdater.Outdated { const OUTDATED_WARNING = "There hasn't been an update in over a month. Consider rebooting or running updates manually" - lib.Notify("System Warning", OUTDATED_WARNING) + err := lib.Notify("System Warning", OUTDATED_WARNING) + if err != nil { + slog.Error("Failed showing warning notification") + } slog.Warn(OUTDATED_WARNING) } diff --git a/distrobox.ini b/distrobox.ini new file mode 100644 index 0000000..6332dfd --- /dev/null +++ b/distrobox.ini @@ -0,0 +1,10 @@ +[golang-fedora-uupd] +additional_packages="git go gopls" +image=fedora:rawhide +init=false +nvidia=false +pull=true +root=false +replace=true +start_now=false + diff --git a/justfile b/justfile index 96cb775..1d16408 100644 --- a/justfile +++ b/justfile @@ -70,3 +70,9 @@ container-test: podman rm -f uupd-test clean: rm -rf "$UBLUE_ROOT" + +lint: + golangci-lint run + +release: + goreleaser diff --git a/lib/session.go b/lib/session.go index 0268d2e..6b676f1 100644 --- a/lib/session.go +++ b/lib/session.go @@ -13,6 +13,7 @@ type User struct { func RunUID(uid int, command []string, env map[string]string) ([]byte, error) { // Just fork systemd-run, using the systemd API gave me a massive headache + // FIXME: use the systemd api instead cmdArgs := []string{ "/usr/bin/systemd-run", "--machine", @@ -77,7 +78,7 @@ func Notify(summary string, body string) error { } for _, user := range users { // we don't care if these exit - RunUID(user.UID, []string{"/usr/bin/notify-send", "--app-name", "uupd", summary, body}, nil) + _, _ = RunUID(user.UID, []string{"/usr/bin/notify-send", "--app-name", "uupd", summary, body}, nil) } return nil }