Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goreleaser #241

Merged
merged 11 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
kind: pipeline
type: docker
name: default
steps:

steps:
# We use golangci-lint for linting.
# See: https://golangci-lint.run/
- name: lint
Expand All @@ -19,51 +19,72 @@ steps:
path: /root/.cache/go-build
- name: golangci-lint-cache
path: /root/.cache/golangci-lint
- name: go-src
path: /go
commands:
- golangci-lint run --timeout 5m0s --tests=false --verbose
when:
event:
include:
- pull_request
- pull_request

- name: test
image: golang:1.17.1-alpine3.14
volumes:
- name: go-build-cache
path: /root/.cache/go-build
- name: go-src
path: /go
commands:
- CGO_ENABLED=0 GTS_DB_TYPE="sqlite" GTS_DB_ADDRESS=":memory:" go test -count 1 -p 1 ./...
- CGO_ENABLED=0 GTS_DB_TYPE="postgres" GTS_DB_ADDRESS="postgres" go test -count 1 -p 1 ./...
- CGO_ENABLED=0 GTS_DB_TYPE="sqlite" GTS_DB_ADDRESS=":memory:" go test -p 1 ./...
when:
event:
include:
- pull_request
- pull_request

- name: publish
image: plugins/docker
settings:
auto_tag: true
username: gotosocial
password:
- name: snapshot
image: superseriousbusiness/gotosocial-drone-build:latest # https://github.com/superseriousbusiness/gotosocial-drone-build
volumes:
- name: go-build-cache
path: /root/.cache/go-build
- name: docker
path: /var/run/docker.sock
environment:
DOCKER_USERNAME: gotosocial
DOCKER_PASSWORD:
from_secret: gts_docker_password
repo: superseriousbusiness/gotosocial
tags: latest
commands:
- /go/dockerlogin.sh
- goreleaser release --rm-dist --snapshot
- docker push superseriousbusiness/gotosocial:latest
when:
event:
exclude:
- pull_request
include:
- push
branch:
include:
- main

# We need a postgres service running for the test step.
# See: https://docs.drone.io/pipeline/docker/syntax/services/
services:
- name: postgres
image: postgres
- name: release
image: superseriousbusiness/gotosocial-drone-build:latest # https://github.com/superseriousbusiness/gotosocial-drone-build
volumes:
- name: go-build-cache
path: /root/.cache/go-build
- name: docker
path: /var/run/docker.sock
environment:
POSTGRES_PASSWORD: postgres
DOCKER_USERNAME: gotosocial
DOCKER_PASSWORD:
from_secret: gts_docker_password
GITHUB_TOKEN:
from_secret: github_token
commands:
- /go/dockerlogin.sh
- goreleaser release --rm-dist
when:
event:
include:
- pull_request
- tag

# We can speed up builds significantly by caching build artifacts between runs.
# See: https://docs.drone.io/pipeline/docker/syntax/volumes/host/
Expand All @@ -74,6 +95,12 @@ volumes:
- name: golangci-lint-cache
host:
path: /drone/gotosocial/golangci-lint
- name: go-src
host:
path: /drone/gotosocial/go
- name: docker
host:
path: /var/run/docker.sock

trigger:
repo:
Expand All @@ -86,6 +113,6 @@ trigger:

---
kind: signature
hmac: 703dad12a9e92cbd415b23d82620608830a60a70168527118e2e9aab145f1099
hmac: 8c39ebbac5e9cf4abde546a2b6b8b99a863804969474a5c8fc11f394f415e0ac

...
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ cp.out

# exclude compiled mkdocs site
site/

# exclude compiled binaries
dist/

# exclude the copy of swagger.yaml moved into assets during packaging
web/assets/swagger.yaml
85 changes: 85 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# https://goreleaser.com
project_name: gotosocial
before:
# https://goreleaser.com/customization/hooks/
hooks:
# tidy up and lint
- go mod tidy
- go fmt ./...
# generate the swagger.yaml file using go-swagger and bundle it into the assets directory
- swagger generate spec -o docs/api/swagger.yaml --scan-models
- sed -i "s/REPLACE_ME/{{ incpatch .Version }}/" docs/api/swagger.yaml
- cp docs/api/swagger.yaml web/assets/swagger.yaml
# install and bundle the web assets and styling
- yarn install --cwd web/gotosocial-styling
- node web/gotosocial-styling/index.js --build-dir="web/assets"
builds:
# https://goreleaser.com/customization/build/
-
main: ./cmd/gotosocial
binary: gotosocial
ldflags:
- -s
- -w
- -extldflags
- -static
- -X main.Commit={{.Commit}}
- -X main.Version={{.Version}}
tags:
- netgo
- osusergo
- static_build
env:
- CGO_ENABLED=0
goos:
- linux
- freebsd
goarch:
- 386
- amd64
- arm
- arm64
ignore:
# build freebsd only for amd64
- goos: freebsd
goarch: arm64
- goos: freebsd
goarch: arm
- goos: freebsd
goarch: 386
mod_timestamp: "{{ .CommitTimestamp }}"
dockers:
# https://goreleaser.com/customization/docker/
-
goos: linux
goarch: amd64
image_templates:
- "superseriousbusiness/gotosocial:latest"
- "superseriousbusiness/gotosocial:{{ .Version }}"
build_flag_templates:
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
extra_files:
- web
archives:
# https://goreleaser.com/customization/archive/
-
files:
# standard release files
- LICENSE
- README.md
- CHANGELOG*
# web assets and example config
- web
- example/config.yaml
checksum:
# https://goreleaser.com/customization/checksum/
name_template: 'checksums.txt'
snapshot:
# https://goreleaser.com/customization/snapshots/
name_template: "{{ incpatch .Version }}-SNAPSHOT"
source:
# https://goreleaser.com/customization/source/
enabled: true
Loading