From 20f7a8b88637c18f9eb7196573918a33d83c7075 Mon Sep 17 00:00:00 2001 From: Oleg Lobanov Date: Mon, 1 Mar 2021 16:54:23 +0100 Subject: [PATCH] Add goreleaser --- .github/CODEOWNERS | 5 +++ .github/workflows/ci-test.yaml | 36 ----------------- .github/workflows/main.yaml | 61 +++++++++++++++++++++++++++++ .gitignore | 3 +- Dockerfile | 13 +++++++ goreleaser.yaml | 71 ++++++++++++++++++++++++++++++++++ 6 files changed, 152 insertions(+), 37 deletions(-) create mode 100644 .github/CODEOWNERS delete mode 100644 .github/workflows/ci-test.yaml create mode 100644 .github/workflows/main.yaml create mode 100644 Dockerfile create mode 100644 goreleaser.yaml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..c693722 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# These owners will be the default owners for everything in the repo. +# Unless a later match takes precedence, @o1egl will be requested for +# review when someone opens a pull request. + +* @o1egl \ No newline at end of file diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml deleted file mode 100644 index abd8a3f..0000000 --- a/.github/workflows/ci-test.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: test - -on: - push: - branches: [ master ] - tags: - pull_request: - branches: - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.37.1 - skip-go-installation: true - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - name: Test - run: go test -race -timeout=60s -v -coverprofile=coverage.txt -covermode=atomic ./... - - uses: codecov/codecov-action@v1 - with: - file: ./coverage.txt \ No newline at end of file diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..cb4275d --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,61 @@ +name: main + +on: + push: + branches: [ master ] + tags: v* + pull_request: + branches: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.37.1 + skip-go-installation: true + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: Test + run: go test -race -timeout=60s -v -coverprofile=coverage.txt -covermode=atomic ./... + - uses: codecov/codecov-action@v1 + with: + file: ./coverage.txt + release: + runs-on: ubuntu-latest + needs: [lint, test] + if: startsWith(github.event.ref, 'refs/tags/v') + 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 Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 21d963d..a0dfe02 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build/ .idea vendor -coverage.txt \ No newline at end of file +coverage.txt +dist/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..42327a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:latest as alpine +RUN apk --update add ca-certificates +RUN apk --update add mailcap + +FROM scratch +COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=alpine /etc/mime.types /etc/mime.types + +VOLUME /data + +COPY govatar /govatar + +ENTRYPOINT [ "/govatar" ] \ No newline at end of file diff --git a/goreleaser.yaml b/goreleaser.yaml new file mode 100644 index 0000000..e7b36c6 --- /dev/null +++ b/goreleaser.yaml @@ -0,0 +1,71 @@ +project_name: govatar + +before: + hooks: + - go mod download + +build: + env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X main.version={{ .Version }} + main: govatar/main.go + binary: govatar + goos: + - darwin + - linux + - windows + - freebsd + goarch: + - amd64 + - 386 + - arm + - arm64 + goarm: + - 5 + - 6 + - 7 + ignore: + - goos: darwin + goarch: 386 + - goos: freebsd + goarch: arm + +archives: + - + name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}" + format: tar.gz + format_overrides: + - goos: windows + format: zip + +dockers: + - + dockerfile: Dockerfile + goos: linux + goarch: amd64 + goarm: '' + image_templates: + - "o1egl/govatar:latest" + - "o1egl/govatar:{{ .Tag }}" + - "o1egl/govatar:v{{ .Major }}" + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.authors=Oleg Lobanov" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + +brews: + - name: govatar + tap: + owner: o1egl + name: homebrew-tap + folder: Formula + homepage: https://github.com/o1egl/govatar + commit_author: + name: Oleg Lobanov + email: oleg@lobanov.me + description: GOvatar is an avatar generation library written in GO + license: "MIT" \ No newline at end of file