Skip to content

Commit 5a601b9

Browse files
Fontinalisjohejo
andauthored
Support for GitHub Actions and goreleaser (#604)
* goreleaser configuration and automatic release workflow * update and fix goreleaser * remove windows arm ignore * add format override for windows to use zip files * update environment and docker username * the single source of truth * fix depricated api issue ( thanks @dhui ) Co-authored-by: Mitsuo Heijo <[email protected]>
1 parent 5bf05dc commit 5a601b9

File tree

5 files changed

+162
-1
lines changed

5 files changed

+162
-1
lines changed

Diff for: .github/workflows/release.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
jobs:
7+
goreleaser:
8+
name: Release a new version
9+
environment: GoReleaser
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: 2.7
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: "1.16.x"
21+
22+
- uses: docker/setup-qemu-action@v1
23+
- uses: docker/setup-buildx-action@v1
24+
- uses: docker/login-action@v1
25+
with:
26+
username: golangmigrate
27+
password: ${{ secrets.DOCKERHUB_TOKEN }}
28+
29+
- run: echo "SOURCE=$(make echo-source)" >> $GITHUB_ENV
30+
- run: echo "DATABASE=$(make echo-database)" >> $GITHUB_ENV
31+
32+
- uses: goreleaser/goreleaser-action@v2
33+
with:
34+
version: latest
35+
args: release --rm-dist
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- run: gem install package_cloud
40+
- run: package_cloud push golang-migrate/migrate/ubuntu/bionic dist/migrate.linux-amd64.deb
41+
env:
42+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
43+
- run: package_cloud push golang-migrate/migrate/ubuntu/focal dist/migrate.linux-amd64.deb
44+
env:
45+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
46+
- run: package_cloud push golang-migrate/migrate/debian/buster dist/migrate.linux-amd64.deb
47+
env:
48+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ cli/migrate
66
.godoc.pid
77
vendor/
88
.vscode/
9-
.idea/
9+
.idea
10+
dist/

Diff for: .goreleaser.yml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
project_name: migrate
2+
before:
3+
hooks:
4+
- go mod tidy
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
goarch:
13+
- amd64
14+
- arm
15+
- arm64
16+
- 386
17+
goarm:
18+
- 7
19+
main: ./cmd/migrate
20+
ldflags:
21+
- '-w -s -X main.Version={{ .Version }} -extldflags "static"'
22+
flags:
23+
- "-tags={{ .Env.DATABASE }} {{ .Env.SOURCE }}"
24+
- "-trimpath"
25+
nfpms:
26+
- homepage: "https://github.com/golang-migrate/migrate"
27+
maintainer: "[email protected]"
28+
license: MIT
29+
description: "Database migrations"
30+
formats:
31+
- deb
32+
file_name_template: "{{ .ProjectName }}.{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
33+
dockers:
34+
- goos: linux
35+
goarch: amd64
36+
dockerfile: Dockerfile.github-actions
37+
use: buildx
38+
ids:
39+
- migrate
40+
image_templates:
41+
- 'migrate/migrate:{{ .Tag }}-amd64'
42+
build_flag_templates:
43+
- '--label=org.opencontainers.image.created={{ .Date }}'
44+
- '--label=org.opencontainers.image.title={{ .ProjectName }}'
45+
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
46+
- '--label=org.opencontainers.image.version={{ .Version }}'
47+
- "--label=org.opencontainers.image.source={{ .GitURL }}"
48+
- "--platform=linux/amd64"
49+
- goos: linux
50+
goarch: arm64
51+
dockerfile: Dockerfile.github-actions
52+
use: buildx
53+
ids:
54+
- migrate
55+
image_templates:
56+
- 'migrate/migrate:{{ .Tag }}-arm64'
57+
build_flag_templates:
58+
- '--label=org.opencontainers.image.created={{ .Date }}'
59+
- '--label=org.opencontainers.image.title={{ .ProjectName }}'
60+
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
61+
- '--label=org.opencontainers.image.version={{ .Version }}'
62+
- "--label=org.opencontainers.image.source={{ .GitURL }}"
63+
- "--platform=linux/arm64"
64+
65+
docker_manifests:
66+
- name_template: 'migrate/migrate:{{ .Tag }}'
67+
image_templates:
68+
- 'migrate/migrate:{{ .Tag }}-amd64'
69+
- 'migrate/migrate:{{ .Tag }}-arm64'
70+
- name_template: 'migrate/migrate:{{ .Major }}'
71+
image_templates:
72+
- 'migrate/migrate:{{ .Tag }}-amd64'
73+
- 'migrate/migrate:{{ .Tag }}-arm64'
74+
- name_template: 'migrate/migrate:latest'
75+
image_templates:
76+
- 'migrate/migrate:{{ .Tag }}-amd64'
77+
- 'migrate/migrate:{{ .Tag }}-arm64'
78+
archives:
79+
- name_template: "{{ .ProjectName }}.{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
80+
format_overrides:
81+
- goos: windows
82+
format: zip
83+
checksum:
84+
name_template: 'sha256sum.txt'
85+
release:
86+
draft: true
87+
changelog:
88+
skip: false
89+
sort: asc
90+
filters:
91+
exclude:
92+
- '^docs:'
93+
- '^test:'
94+
- Merge pull request
95+
- Merge branch
96+
- go mod tidy
97+
snapshot:
98+
name_template: "{{ .Tag }}-next"

Diff for: Dockerfile.github-actions

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM alpine:3.13
2+
3+
RUN apk add --no-cache ca-certificates
4+
5+
ENTRYPOINT ["/usr/bin/migrate"]
6+
CMD ["--help"]
7+
8+
COPY migrate /usr/bin/migrate

Diff for: Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ TEST_FLAGS ?=
66
REPO_OWNER ?= $(shell cd .. && basename "$$(pwd)")
77
COVERAGE_DIR ?= .coverage
88

9+
echo-source:
10+
@echo "$(SOURCE)"
11+
12+
echo-database:
13+
@echo "$(DATABASE)"
14+
915
build:
1016
CGO_ENABLED=0 go build -ldflags='-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' ./cmd/migrate
1117

0 commit comments

Comments
 (0)