From f4a023673f51aefb22fe51497447f23014b197a4 Mon Sep 17 00:00:00 2001 From: Madh93 Date: Sat, 28 Dec 2024 15:59:11 +0000 Subject: [PATCH] ci: setup release workflow --- .air.toml | 4 +- .devcontainer/devcontainer.json | 4 +- .github/workflows/check-pull-request.yml | 31 +++++++ .github/workflows/release-hoarderbot.yml | 44 ++++++++++ .golangci.yml | 17 ++++ .goreleaser.yaml | 105 +++++++++++++++++++++++ .tool-versions | 4 +- main.go | 13 +++ 8 files changed, 217 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/check-pull-request.yml create mode 100644 .github/workflows/release-hoarderbot.yml create mode 100644 .golangci.yml create mode 100644 .goreleaser.yaml create mode 100644 main.go diff --git a/.air.toml b/.air.toml index a26539f..8a112d3 100644 --- a/.air.toml +++ b/.air.toml @@ -6,8 +6,8 @@ tmp_dir = "tmp" [build] cmd = "task build:debug" -bin = "./bin/hoarder-debug server" -full_bin = "dlv exec ./bin/hoarder-debug server --listen=127.0.0.1:2345 --headless=true --api-version=2 --accept-multiclient --continue --log -- " +bin = "./bin/hoarderbot-debug" +full_bin = "dlv exec ./bin/hoarderbot-debug --listen=127.0.0.1:2345 --headless=true --api-version=2 --accept-multiclient --continue --log --" include_ext = ["go"] exclude_dir = [".vscode", ".devcontainer", "bin", "tmp"] exclude_regex = ["_test.go"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5a355d7..948e42c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,7 +14,9 @@ "customizations": { "vscode": { "extensions": [ - "EditorConfig.EditorConfig" + "EditorConfig.EditorConfig", + "tamasfe.even-better-toml", + "redhat.vscode-yaml" ] } } diff --git a/.github/workflows/check-pull-request.yml b/.github/workflows/check-pull-request.yml new file mode 100644 index 0000000..39307e4 --- /dev/null +++ b/.github/workflows/check-pull-request.yml @@ -0,0 +1,31 @@ +name: Check Pull Request + +on: + pull_request: + branches: [main] + +jobs: + check-pr: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Install dependencies + run: go get . + + - name: Build + run: go build -v + + - name: Test + run: go test ./... + + - name: Linter + uses: golangci/golangci-lint-action@v6 + with: + version: v1.62.2 diff --git a/.github/workflows/release-hoarderbot.yml b/.github/workflows/release-hoarderbot.yml new file mode 100644 index 0000000..d288f7a --- /dev/null +++ b/.github/workflows/release-hoarderbot.yml @@ -0,0 +1,44 @@ +name: Release Hoarderbot + +on: + push: + tags: ["v*"] + +permissions: + contents: write + packages: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b6b57be --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,17 @@ +linters: + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + - gofmt + - godot +run: + timeout: 5m + modules: + enable: true +output: + formats: + - format: colored-line-number diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..84fd5d5 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,105 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - id: binary + env: + - CGO_ENABLED=0 + flags: + - -trimpath + ldflags: + - -s -w + - -X github.com/Madh93/hoarderbot/internal/version.appVersion={{ .Version }} + - -X github.com/Madh93/hoarderbot/internal/version.commitHash={{ .FullCommit }} + goos: + - linux + - darwin + - windows + goarch: + - '386' + - amd64 + - arm + - arm64 + ignore: + - goos: darwin + goarch: '386' + - goos: darwin + goarch: arm + - goos: windows + goarch: arm + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + 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 }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +kos: + - build: binary + repositories: + - "ghcr.io/Madh93/{{ .ProjectName }}" + - "madh93/{{ .ProjectName }}" + tags: + - "{{ .Version }}" + - latest + labels: + org.opencontainers.image.authors: Madh93 + org.opencontainers.image.created: "{{ .Date }}" + org.opencontainers.image.description: Telegram Bot for saving bookmarks to Hoarder + org.opencontainers.image.licenses: MIT + org.opencontainers.image.source: "{{ .GitURL }}" + org.opencontainers.image.revision: "{{ .FullCommit }}" + org.opencontainers.image.title: "{{ .ProjectName }}" + org.opencontainers.image.url: "{{ .GitURL }}" + org.opencontainers.image.vendor: Madh93 + org.opencontainers.image.version: "{{ .Version }}" + bare: true + preserve_import_paths: false + platforms: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + +checksum: + name_template: 'checksums.txt' + +snapshot: + version_template: "{{ .Version }}-next" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + draft: true + github: + owner: Madh93 + name: "{{ .ProjectName }}" + footer: >- + + --- + + Released by [GoReleaser](https://github.com/goreleaser/goreleaser). diff --git a/.tool-versions b/.tool-versions index 06179fa..c4c2a44 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -air 1.61.1 -task 3.40.0 +air 1.61.5 +task 3.40.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..b6ba2d1 --- /dev/null +++ b/main.go @@ -0,0 +1,13 @@ +// Package main is the entry point of the application. It initializes the +// configuration, sets up logging, and starts the Hoarderbot. +package main + +import ( + "fmt" +) + +// main initializes the configuration, sets up logging, and starts the +// Hoarderbot. +func main() { + fmt.Println("Hello World!") +}