@@ -3,74 +3,149 @@ name: CI
33on :
44 push :
55 branches : [main]
6- tags : " v *"
6+ tags : " *"
77 pull_request :
8- branches : [main]
98
109jobs :
1110 build :
12- name : Build
11+ strategy :
12+ fail-fast : false
13+ matrix :
14+ include :
15+ - os : linux
16+ image : ubuntu-latest
17+ arch : amd64
18+ env : {}
19+ - os : linux
20+ image : ubuntu-latest
21+ arch : arm64
22+ setup : sudo apt-get update && sudo apt-get install -qq gcc-aarch64-linux-gnu
23+ env :
24+ CC : aarch64-linux-gnu-gcc
25+ CXX : aarch64-linux-gnu-g++
26+ - os : macos
27+ image : macos-latest
28+ arch : amd64
29+ env : {}
30+ - os : macos
31+ image : macos-latest
32+ arch : arm64
33+ env : {}
34+ - os : windows
35+ image : windows-latest
36+ arch : amd64
37+ env : {}
38+
39+ name : Build (${{ matrix.os }}/${{ matrix.arch }})
40+ runs-on : ${{ matrix.image }}
41+ env : ${{ matrix.env }}
42+
43+ steps :
44+ - uses : actions/checkout@v3
45+
46+ - uses : actions/setup-go@v3
47+ with :
48+ go-version : " 1.17"
49+
50+ - name : Setup environment
51+ run : ${{ matrix.setup }}
52+
53+ - run : go mod download
54+
55+ - run : make build ls
56+ env :
57+ GOARCH : ${{ matrix.arch }}
58+ OUTPUT : dbmate-${{ matrix.os }}-${{ matrix.arch }}
59+
60+ - run : dist/dbmate-${{ matrix.os }}-${{ matrix.arch }} --help
61+ if : ${{ matrix.arch == 'amd64' }}
62+
63+ - name : Publish binaries
64+ uses : softprops/action-gh-release@v1
65+ if : ${{ startsWith(github.ref, 'refs/tags/v') }}
66+ with :
67+ files : dist/dbmate-*
68+ env :
69+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
70+
71+ docker :
72+ name : Docker Test (linux/amd64)
1373 runs-on : ubuntu-latest
1474
1575 steps :
16- - name : Checkout
17- uses : actions/checkout@v2
76+ - uses : actions/checkout@v3
77+
78+ - name : Configure QEMU
79+ uses : docker/setup-qemu-action@v1
1880
19- - name : Environment
81+ - name : Configure Buildx
82+ uses : docker/setup-buildx-action@v1
83+
84+ - name : Check Docker environment
2085 run : |
2186 set -x
2287 docker version
88+ docker buildx version
2389 docker-compose version
2490
25- - name : Cache
26- uses : actions/cache@v2
27- with :
28- key : cache
29- path : .cache
30-
31- - name : Build docker image
91+ - name : Build Docker image
3292 run : |
3393 set -x
3494 docker-compose build
3595 docker-compose run --rm --no-deps dbmate --version
3696
37- - name : Build binaries
38- run : |
39- set -x
40- docker-compose run --rm --no-deps dev make build-all
41- dist/dbmate-linux-amd64 --version
97+ - name : Run make build
98+ run : docker-compose run --rm --no-deps dev make build ls
4299
43- - name : Lint
100+ - name : Run make lint
44101 run : docker-compose run --rm --no-deps dev make lint
45102
46103 - name : Start test dependencies
47104 run : |
48105 set -x
49106 docker-compose pull --quiet
50107 docker-compose up --detach
51-
52- - name : Run tests
53- run : |
54- set -x
55108 docker-compose run --rm dev make wait
56- docker-compose run --rm dev make test
57109
58- - name : Publish docker image
110+ - name : Run make test
111+ run : docker-compose run --rm dev make test
112+
113+ - name : Login to Docker Hub
114+ uses : docker/login-action@v1
59115 if : ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
60- env :
61- SRC_IMAGE : dbmate_release
62- DOCKERHUB_IMAGE : ${{ github.repository }}
63- DOCKERHUB_USERNAME : ${{ secrets.DOCKERHUB_USERNAME }}
64- DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
65- GHCR_IMAGE : ghcr.io/${{ github.repository }}
66- GHCR_USERNAME : ${{ github.actor }}
67- GHCR_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68- run : .github/workflows/publish-docker.sh
69-
70- - name : Publish release binaries
71- uses : softprops/action-gh-release@v1
72- if : ${{ startsWith(github.ref, 'refs/tags/v') }}
73116 with :
74- files : dist/*
75- env :
76- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117+ username : ${{ secrets.DOCKERHUB_USERNAME }}
118+ password : ${{ secrets.DOCKERHUB_TOKEN }}
119+
120+ - name : Login to GitHub Container Registry
121+ uses : docker/login-action@v1
122+ if : ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
123+ with :
124+ registry : ghcr.io
125+ username : ${{ github.actor }}
126+ password : ${{ secrets.GITHUB_TOKEN }}
127+
128+ - name : Generate Docker image tags
129+ id : meta
130+ uses : docker/metadata-action@v3
131+ if : ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
132+ with :
133+ images : |
134+ ${{ github.repository }}
135+ ghcr.io/${{ github.repository }}
136+ tags : |
137+ type=ref,event=branch
138+ type=semver,pattern={{version}}
139+ type=semver,pattern={{major}}.{{minor}}
140+ type=semver,pattern={{major}}
141+
142+ - name : Publish Docker image
143+ uses : docker/build-push-action@v2
144+ if : ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
145+ with :
146+ context : .
147+ target : release
148+ platforms : linux/amd64,linux/arm64
149+ push : true
150+ tags : ${{ steps.meta.outputs.tags }}
151+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments