-
Notifications
You must be signed in to change notification settings - Fork 2
200 lines (180 loc) · 6.43 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
build-binary:
description: 'Build Binary'
required: false
type: boolean
default: true
build-docker:
description: 'Build Docker'
required: false
type: boolean
default: true
draft-release:
description: 'Draft Release'
required: false
type: boolean
default: false
jobs:
extract-version:
name: Extract version
runs-on: warp-ubuntu-latest-x64-16x
outputs:
VERSION: ${{ steps.extract_version.outputs.VERSION }}
steps:
- name: Extract version
id: extract_version
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
SHA_SHORT="$(echo ${GITHUB_SHA} | cut -c1-7)"
BRANCH_NAME_SAFE="${GITHUB_REF_NAME//\//-}" # replaces "/" in branch name with "-"
VERSION="${BRANCH_NAME_SAFE}-${SHA_SHORT}"
fi
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "${VERSION}"
echo "### Version: \`${VERSION}\`" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "| ------------------- | ---------------------- |" >> $GITHUB_STEP_SUMMARY
echo "| \`GITHUB_REF_TYPE\` | \`${GITHUB_REF_TYPE}\` |" >> $GITHUB_STEP_SUMMARY
echo "| \`GITHUB_REF_NAME\` | \`${GITHUB_REF_NAME}\` |" >> $GITHUB_STEP_SUMMARY
echo "| \`GITHUB_REF\` | \`${GITHUB_REF}\` |" >> $GITHUB_STEP_SUMMARY
echo "| \`GITHUB_SHA\` | \`${GITHUB_SHA}\` |" >> $GITHUB_STEP_SUMMARY
echo "| \`VERSION\` | \`${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
build-binary:
name: Build binary
needs: extract-version
if: ${{ github.event.inputs.build-binary == 'true' || github.event_name == 'push'}} # when manually triggered or version tagged
runs-on: ${{ matrix.configs.runner }}
container:
image: ubuntu:22.04
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
permissions:
contents: write
packages: write
strategy:
matrix:
configs:
- target: x86_64-unknown-linux-gnu
runner: warp-ubuntu-latest-x64-16x
steps:
- name: Install dependencies
run: |
apt-get update
apt-get install -y \
build-essential \
curl \
git \
libclang-dev \
libssl-dev \
pkg-config \
protobuf-compiler
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- uses: actions/checkout@v4 # must install git before checkout and set safe.directory after checkout because of container
with:
fetch-depth: 0
- name: Prepare filename
run: echo "OUTPUT_FILENAME=rbuilder-${VERSION}-${{ matrix.configs.target }}" >> $GITHUB_ENV
- name: Build binary
run: |
git config --global --add safe.directory "$(pwd)"
. $HOME/.cargo/env
make build-reproducible TARGET=${{ matrix.configs.target }}
./target/${{ matrix.configs.target }}/release/rbuilder version
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUTPUT_FILENAME }}
path: target/${{ matrix.configs.target }}/release/rbuilder
build-docker:
name: Build and publish Docker image
if: ${{ github.event.inputs.build-docker == 'true' || github.event_name == 'push'}}
needs: extract-version
runs-on: warp-ubuntu-latest-x64-16x
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
permissions:
contents: read
packages: write
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
labels: org.opencontainers.image.source=${{ github.repositoryUrl }}
tags: |
type=sha
type=semver,pattern={{version}},value=${{ env.VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }}
type=semver,pattern={{major}},value=${{ env.VERSION }}
type=raw,value=latest,enable=${{ !contains(env.VERSION, '-') }}
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_PROFILE=release
draft-release:
name: Draft release
if: ${{ github.event.inputs.draft-release == 'true' || github.event_name == 'push'}} # when manually triggered or version tagged
needs: [extract-version, build-binary]
runs-on: warp-ubuntu-latest-x64-16x
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts
- name: Record artifacts checksums
working-directory: artifacts
run: |
find ./ || true
for file in *; do sha256sum "$file" >> sha256sums.txt; done;
cat sha256sums.txt
- name: Create release draft
uses: softprops/[email protected]
id: create-release-draft
with:
draft: true
files: artifacts/*
generate_release_notes: true
name: ${{ env.VERSION }}
tag_name: ${{ env.VERSION }}
- name: Write Github Step Summary
run: |
echo "---"
echo "### Release Draft: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.create-release-draft.outputs.url }}" >> $GITHUB_STEP_SUMMARY