-
Notifications
You must be signed in to change notification settings - Fork 1
168 lines (147 loc) · 5.25 KB
/
build.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Build
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
push:
env:
CONTAINER_REGISTRY: ghcr.io
CONTAINER_IMAGE: ghcr.io/${{ github.repository }}
PLATFORMS: linux/amd64,linux/arm64
jobs:
binaries:
name: Binaries
# pull_request_target: Only "dependabot[bot]" is allowed to access secrets.
# pull_request: All other forks are running without access to secrets.
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') ||
(github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]')
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
- linux/arm
- darwin/amd64
- darwin/arm64
- windows/amd64
steps:
- name: Clone repository
if: ${{ github.event_name != 'pull_request_target' }}
uses: actions/checkout@v4
# Allow "dependabot[bot]" to verify its changes with access to secrets and modified code.
- name: Clone repository for Dependabot
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Go compiler
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true
- name: Fetch version from git history
if: github.ref_protected == true
uses: codfish/semantic-release-action@v2
id: semantic
with:
dry_run: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build binary
if: github.ref_protected == true
run: VERSION=v${{ steps.semantic.outputs.release-version }} UPX=-9 PLATFORM=${{ matrix.platform }} make build
- name: Build binary
if: github.ref_protected == false
run: UPX=-9 PLATFORM=${{ matrix.platform }} make build
- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: binaries
path: bin/*
container:
name: Container
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') ||
(github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]')
steps:
- name: Clone repository
if: ${{ github.event_name != 'pull_request_target' }}
uses: actions/checkout@v4
# Allow "dependabot[bot]" to verify its changes with access to secrets and modified code.
- name: Clone repository for Dependabot
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Fetch version from git history
uses: codfish/semantic-release-action@v2
id: semantic
with:
dry_run: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate container metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.CONTAINER_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=v${{ steps.semantic.outputs.release-version }},enable=${{ steps.semantic.outputs.new-release-published }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.CONTAINER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push container image
uses: docker/build-push-action@v5
with:
file: build/package/Dockerfile
cache-from: type=registry,ref=${{ env.CONTAINER_IMAGE }}:main
cache-to: type=inline
platforms: ${{ env.PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ steps.semantic.outputs.new-release-published }}
build-args: |
VERSION=v${{ steps.semantic.outputs.release-version }}
auto-merge:
name: Auto-merge
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
needs: [binaries, container]
steps:
- uses: ahmadnassri/action-dependabot-auto-merge@v2
with:
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
target: all
release:
name: Release
if: github.ref_protected == true && github.event_name == 'push'
needs: [binaries, container]
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Download release artifacts
uses: actions/download-artifact@v3
with:
name: binaries
path: release
- name: Create release
uses: codfish/semantic-release-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}