-
Notifications
You must be signed in to change notification settings - Fork 20
203 lines (174 loc) · 6.48 KB
/
release.yaml
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: release
on:
push:
tags:
- "*"
pull_request:
types:
- synchronize
- labeled
permissions:
contents: write
packages: write
jobs:
setup:
runs-on: ubuntu-latest
outputs:
dry-run: ${{ steps.build-context.outputs.dry-run }}
version: ${{ steps.build-context.outputs.version }}
commit: ${{ steps.build-context.outputs.commit }}
build_date: ${{ steps.build-context.outputs.build_date }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set build context
id: build-context
run: |
LABELS="${{ toJson(github.event.pull_request.labels.*.name) }}"
DRY_RUN="false"
if [[ $LABELS == *"build:dry-run"* ]]; then
DRY_RUN="true"
fi
VERSION="${{ github.ref_name }}"
if [[ "${{ github.event_name }}" == 'pull_request' ]]; then
PR_ID=$(echo "${{ github.ref }}" | cut -d '/' -f 3)
VERSION="dev.$PR_ID"
fi
COMMIT=$(git rev-parse --short "$GITHUB_SHA")
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "Dry Run: $DRY_RUN"
echo "Version: $VERSION"
echo "Commit: $COMMIT"
echo "Build Date: $BUILD_DATE"
echo "dry-run=$DRY_RUN" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "commit=$COMMIT" >> $GITHUB_OUTPUT
echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT
# lint:
# uses: ./.github/workflows/lint.yaml
# vuln:
# uses: ./.github/workflows/vuln.yaml
release:
if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'"
needs:
- setup
# - lint
# - vuln
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Snapcraft Setup
run: |
sudo apt-get update
sudo apt-get -yq --no-install-suggests --no-install-recommends install snapcraft
mkdir -p $HOME/.cache/snapcraft/download
mkdir -p $HOME/.cache/snapcraft/stage-packages
- name: Prepare GoReleaser extra args
run: |
ARGS=""
if [[ "${{ needs.setup.outputs.dry-run }}" == "true" ]]; then
ARGS="$ARGS --skip=validate --skip=publish"
fi
echo "GORELEASER_EXTRA_ARGS=$ARGS" >> $GITHUB_ENV
# - name: Run GoReleaser
# uses: goreleaser/goreleaser-action@v5
# with:
# distribution: goreleaser
# version: latest
# args: release --clean ${{ env.GORELEASER_EXTRA_ARGS }}
# env:
# GORELEASER_DRY_RUN: ${{ env.GORELEASER_DRY_RUN }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAP_TOKEN }}
# DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
# DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
# BREW_TAP_PRIVATE_KEY: ${{ secrets.BREW_TAP_PRIVATE_KEY }}
images-linux:
if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'"
strategy:
matrix:
image:
- alpine
- ubuntu
- distroless
- redhat
runs-on: ubuntu-latest
needs:
- setup
- release
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: login into Github Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: login into Docker
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin
- name: build ${{ matrix.image }} image
working-directory: ./images
env:
VERSION: ${{ needs.setup.outputs.version }}
COMMIT: ${{ needs.setup.outputs.commit }}
BUILD_DATE: ${{ needs.setup.outputs.build_date }}
run: VERSION="${{ env.VERSION }}" COMMIT="${{ env.COMMIT }}" BUILD_DATE="${{ env.BUILD_DATE }}" make ${{ matrix.image }}
- name: publish ${{ matrix.image }} image to Github Container Registry
if: "needs.setup.outputs.dry-run != 'true'"
working-directory: ./images
env:
VERSION: ${{ needs.setup.outputs.version }}
run: VERSION="${{ env.VERSION }}" make publish-ghcr-${{ matrix.image }}
- name: publish ${{ matrix.image }} image to DockerHub
if: "needs.setup.outputs.dry-run != 'true'"
working-directory: ./images
env:
VERSION: ${{ needs.setup.outputs.version }}
run: VERSION="${{ env.VERSION }}" make publish-dockerhub-${{ matrix.image }}
images-win:
if: "startsWith(github.ref, 'refs/tags/') || needs.setup.outputs.dry-run == 'true'"
strategy:
matrix:
image:
- nanoserver
- windows-server
needs:
- setup
- release
runs-on: windows-2019
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: login into Github Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: login into Docker
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin
- name: Set up Make
run: choco install make
- name: build ${{ matrix.image }} image
working-directory: ./images
env:
VERSION: ${{ needs.setup.outputs.version }}
COMMIT: ${{ needs.setup.outputs.commit }}
BUILD_DATE: ${{ needs.setup.outputs.build_date }}
run: make VERSION="${{ env.VERSION }}" COMMIT="${{ needs.setup.outputs.commit }}" BUILD_DATE="${{ needs.setup.outputs.build_date }}" ${{ matrix.image }}
- name: publish ${{ matrix.image }} image to Github Container Registry
if: "needs.setup.outputs.dry-run != 'true'"
working-directory: ./images
env:
VERSION: ${{ needs.setup.outputs.version }}
run: make VERSION="${{ env.VERSION }}" publish-ghcr-${{ matrix.image }}
- name: publish ${{ matrix.image }} image to DockerHub
if: "needs.setup.outputs.dry-run != 'true'"
working-directory: ./images
env:
VERSION: ${{ needs.setup.outputs.version }}
run: make VERSION="${{ env.VERSION }}" publish-dockerhub-${{ matrix.image }}