-
Notifications
You must be signed in to change notification settings - Fork 1
204 lines (180 loc) · 8.73 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
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
204
name: Build .deb Packages
on:
repository_dispatch:
types: [release-tagged]
workflow_dispatch:
inputs:
tag:
description: 'Version to build'
required: true
default: 'v1.0.2'
project:
description: 'Project to build'
required: true
component:
description: 'The release component (main, beta, or nightly)'
required: true
default: 'main'
description:
description: 'Description of the project'
required: true
default: 'Renterd: The Next-Gen Sia Renter'
workflow_id:
description: 'Workflow ID from which to download the artifact'
required: true
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# Use oldest supported versions of each distro
include:
# Debian 10
- distro: 'debian'
release: 'buster'
# Ubuntu 20.04
- distro: 'ubuntu'
release: 'focal'
container:
image: ${{ matrix.distro }}:${{ matrix.release }}
steps:
- name: Store input in env
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "RELEASE_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
echo "PROJECT=${{ github.event.inputs.project }}" >> $GITHUB_ENV
echo "DESCRIPTION=${{ github.event.inputs.description }}" >> $GITHUB_ENV
echo "WORKFLOW_ID=${{ github.event.inputs.workflow_id }}" >> $GITHUB_ENV
echo "RELEASE_COMPONENT=${{ github.event.inputs.component }}" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "RELEASE_TAG=${{ github.event.client_payload.tag }}" >> $GITHUB_ENV
echo "PROJECT=${{ github.event.client_payload.project }}" >> $GITHUB_ENV
echo "DESCRIPTION=${{ github.event.client_payload.description }}" >> $GITHUB_ENV
echo "WORKFLOW_ID=${{ github.event.client_payload.workflow_id }}" >> $GITHUB_ENV
echo "RELEASE_COMPONENT=${{ github.event.client_payload.component }}" >> $GITHUB_ENV
fi
echo "Building ${{ env.PROJECT}} .deb packages for tag ${{ env.RELEASE_TAG }}"
- name: Install dependencies
run: |
apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install unzip dpkg-dev git
- name: Download release artifacts from workflow
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.PAT_ARTIFACT_DOWNLOAD }}
pattern: ${{ env.PROJECT }}_linux_*
path: artifacts
merge-multiple: true
repository: SiaFoundation/${{ env.PROJECT }}
run-id: ${{ env.WORKFLOW_ID }}
- name: Build .deb packages
shell: bash
run: |
TAG=${{ env.RELEASE_TAG }}
if [ "${{env.RELEASE_COMPONENT}}" = "nightly" ]; then
VERSION=$(date +%Y%m%d)-${{ env.RELEASE_TAG }}
else
VERSION=${TAG:1}
fi
for arch in amd64 arm64; do
BUILD_NAME=${{ matrix.distro }}_${{ env.PROJECT }}_${VERSION}_${arch}
# Create the directory structure for the .deb package
mkdir -p ${BUILD_NAME}/DEBIAN
mkdir -p ${BUILD_NAME}/usr/bin
mkdir -p ${BUILD_NAME}/var/lib/${{ env.PROJECT }}
mkdir -p ${BUILD_NAME}/etc/systemd/system
# Copy the ${{ env.PROJECT }} binary
unzip ./artifacts/${{ env.PROJECT }}_linux_${arch}.zip -d ./artifacts/${arch}/
cp ./artifacts/${arch}/${{ env.PROJECT }} ${BUILD_NAME}/usr/bin/${{ env.PROJECT }}
# Create the control file
echo "Package: ${{ env.PROJECT }}" > ${BUILD_NAME}/DEBIAN/control
echo "Version: $VERSION" >> ${BUILD_NAME}/DEBIAN/control
echo "Architecture: ${arch}" >> ${BUILD_NAME}/DEBIAN/control
echo "Maintainer: The Sia Foundation <[email protected]>" >> ${BUILD_NAME}/DEBIAN/control
echo "Priority: optional" >> ${BUILD_NAME}/DEBIAN/control
echo "Section: net" >> ${BUILD_NAME}/DEBIAN/control
echo "Description: ${DESCRIPTION}" >> ${BUILD_NAME}/DEBIAN/control
echo "Homepage: https://github.com/SiaFoundation/${{ env.PROJECT }}" >> ${BUILD_NAME}/DEBIAN/control
# Create systemd service file
echo "[Unit]" > ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "Description=${DESCRIPTION}" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "After=network.target" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "[Service]" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "ExecStart=/usr/bin/${{ env.PROJECT }}" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "WorkingDirectory=/var/lib/${{ env.PROJECT }}" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "Restart=always" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "RestartSec=15" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "TimeoutStopSec=120" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "[Install]" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "WantedBy=multi-user.target" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
echo "Alias=${{ env.PROJECT }}.service" >> ${BUILD_NAME}/etc/systemd/system/${{ env.PROJECT }}.service
# Create the prerem script
echo "#!/bin/sh" > ${BUILD_NAME}/DEBIAN/prerm
echo "systemctl stop ${{ env.PROJECT }}.service" >> ${BUILD_NAME}/DEBIAN/prerm
echo "systemctl disable ${{ env.PROJECT }}.service" >> ${BUILD_NAME}/DEBIAN/prerm
chmod +x ${BUILD_NAME}/DEBIAN/prerm
# Build the .deb file
echo "Building ${BUILD_NAME}.deb"
dpkg-deb --build ${BUILD_NAME}
done
- name: upload deb packages
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.distro }}
path: '*.deb'
create-pull-request:
needs: build
runs-on: ubuntu-latest
steps:
- name: Store input in env
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "RELEASE_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
echo "PROJECT=${{ github.event.inputs.project }}" >> $GITHUB_ENV
echo "RELEASE_COMPONENT=${{ github.event.inputs.component }}" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "RELEASE_TAG=${{ github.event.client_payload.tag }}" >> $GITHUB_ENV
echo "PROJECT=${{ github.event.client_payload.project }}" >> $GITHUB_ENV
echo "RELEASE_COMPONENT=${{ github.event.client_payload.component }}" >> $GITHUB_ENV
fi
- name: install dependencies
run: |
sudo apt-get update && sudo apt-get -y install reprepro
- name: Checkout repo
uses: actions/checkout@v3
- name: Download deb packages
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Import GPG Key
run: |
echo "${{ secrets.GPG_SIGNING_KEY }}" | base64 --decode | gpg --import
- name: Add packages to repository
shell: bash
run: |
# loop over all supported debian releases
for release in 'bookworm' 'bullseye' 'buster'; do
for deb in ./debian_*.deb; do
reprepro -Vb ./debian -C ${{ env.RELEASE_COMPONENT }} includedeb ${release} $deb
done
done
# loop over all supported ubuntu releases
for release in 'focal' 'jammy' 'mantic' 'noble'; do
for deb in ./ubuntu_*.deb; do
reprepro -Vb ./ubuntu -C ${{ env.RELEASE_COMPONENT }} includedeb ${release} $deb
done
done
rm -rf *.deb
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: '${{ env.PROJECT }}: ${{ env.RELEASE_TAG }}'
title: '${{ env.PROJECT }} (${{ env.RELEASE_COMPONENT }}): ${{ env.RELEASE_TAG }}'
body: 'This is an automated PR to update ${{ env.PROJECT }} to ${{ env.RELEASE_TAG }}'
branch: ${{ env.PROJECT }}/update/${{env.RELEASE_COMPONENT }}/${{ env.RELEASE_TAG }}
base: master