-
-
Notifications
You must be signed in to change notification settings - Fork 61
140 lines (124 loc) · 4.2 KB
/
test-build-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Test, Build, Release
on:
push:
branches: [ 'master', 'pre-release' ]
pull_request:
branches: [ 'master', 'dev', 'pre-release' ]
env:
GH_REGISTRY: ghcr.io
REPOSITORY_NAME: ${{ github.repository }}
jobs:
# Build job runs on every PR into dev and master and pushes to master
test:
name: Test
strategy:
matrix:
go-version: [ 1.16.x ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test ./...
# Build job runs on every PR into dev and master and pushes to master
# Depends on test job
build-docker:
runs-on: ubuntu-latest
name: Build
needs: [ test ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Build Docker Images
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
pull: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Release job runs on every push to master
# Depends on build job
release-docker:
runs-on: ubuntu-latest
name: Release
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/pre-release' }}
needs: [ build-docker ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Create semver tag and changelog
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: master
pre_release_branches: pre-release
# Build Docker Images
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ env.GH_REGISTRY }}/${{ env.REPOSITORY_NAME }}
${{ env.REPOSITORY_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ steps.tag_version.outputs.new_tag }}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.GH_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push version ${{ steps.tag_version.outputs.new_tag }}
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
# Create GitHub release once images have been pushed
- name: Create a GitHub release ${{ steps.tag_version.outputs.new_tag }}
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
prerelease: contains( ${{ steps.tag_version.outputs.release_type }} , 'pre' )
# Build Go Release
- run: git tag ${{ steps.tag_version.outputs.new_tag }}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Run GoReleaser ${{ steps.tag_version.outputs.new_tag }}
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release
workdir: ./cmd/infrared/.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}