From fc1b2ca1b2699f5e7d5808161156fd9a461a5d8a Mon Sep 17 00:00:00 2001 From: Anbraten Date: Fri, 21 May 2021 21:05:39 +0200 Subject: [PATCH] feat: add release workflow (#2) * feat: add release workflow Co-authored-by: Lukas --- .github/workflows/release.yml | 40 ++++++++++++++++++++++++ .gitignore | 30 ++++++++++++++++++ .goreleaser.yml | 58 +++++++++++++++++++++++++++++++++++ Dockerfile | 10 ++++++ main.go | 5 +-- 5 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..60a0593 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +name: Release + +on: + push: + tags: + - "*" + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload assets + uses: actions/upload-artifact@v2 + with: + name: lassie-bot-dog + path: dist/* diff --git a/.gitignore b/.gitignore index 97aca2e..4153ec6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,32 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof + +lassie-bot-dog +*~ + +dist/ + .env node_modules \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..6c30d34 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,58 @@ +# This is an example goreleaser.yaml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +project_name: lassie-bot-dog + +before: + hooks: + - go mod tidy +builds: + - + flags: + - -trimpath + goos: + - darwin + - linux + - freebsd + goarch: + - amd64 + - arm64 + - ppc64le + - s390x + env: + - CGO_ENABLED=0 +archives: + - + format_overrides: + - goos: windows + format: zip + files: + - README.md + - LICENSE + +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: 'snapshot-{{ time "2006-01-02" }}' +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +nfpms: + - + description: Lassie is a Gitlab bot which helps you with houskeeping + license: MIT License + formats: + - deb + - rpm +dockers: + - + # GOOS of the built binary that should be used. + goos: linux + # GOARCH of the built binary that should be used. + goarch: amd64 + dockerfile: Dockerfile + image_templates: + - "geprog/lassie-bot-dog:{{ .Tag }}" + - "geprog/lassie-bot-dog:latest" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e0e3358 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.16 + +FROM scratch + +# Copy CA certificates to prevent x509: certificate signed by unknown authority errors +COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt + +COPY lassie-bot-dog /lassie-bot-dog + +ENTRYPOINT ["/lassie-bot-dog"] diff --git a/main.go b/main.go index 8fb08f1..f0d1236 100644 --- a/main.go +++ b/main.go @@ -36,10 +36,7 @@ func loop(client *gitlab.Client) { } func main() { - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file") - } + godotenv.Load() GITLAB_URL := os.Getenv("GITLAB_URL") GITLAB_TOKEN := os.Getenv("GITLAB_TOKEN")