-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (80 loc) · 3.67 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
name: Build Debian Package
on:
repository_dispatch:
types: [release-tagged]
workflow_dispatch:
inputs:
tag:
description: 'Version to build'
required: true
default: 'v1.0.0'
project:
description: 'Project to build'
required: true
default: 'renterd'
jobs:
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
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
fi
echo "Building ${{ env.PROJECT}} .deb packages for tag ${{ env.RELEASE_TAG }}"
- name: Checkout packages
uses: actions/checkout@v3
- name: Checkout src code into tmp folder
uses: actions/checkout@v3
with:
repository: SiaFoundation/${{ env.PROJECT }}
ref: ${{ env.RELEASE_TAG }}
path: "tmp"
- name: Build .deb Package
run: |
TAG=${{ env.RELEASE_TAG }}
VERSION=${TAG:1}
# Move into the tmp directory
cd tmp
go generate ./...
for arch in amd64 arm64; do
BUILD_NAME=${{ env.PROJECT }}_$VERSION_$arch
# Create the directory structure for the .deb package
mkdir -p $BUILD_NAME/DEBIAN
mkdir -p $BUILD_NAME/usr/bin
# Build the ${{ env.PROJECT }} binary
GOOS=linux GOARCH=$arch go build -tags='netgo' -o $BUILD_NAME/usr/bin/${{ env.PROJECT }} -a -ldflags='-s -w' ./cmd/${{ 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 "Description: Renterd: The Next-Gen Sia Renter" >> $BUILD_NAME/DEBIAN/control
echo "Homepage: https://github.com/SiaFoundation/${{ env.PROJECT }}" >> $BUILD_NAME/DEBIAN/control
# Build the .deb file
echo "Building $BUILD_NAME.deb"
dpkg-deb --build $BUILD_NAME
# Move the .deb file to debian/pool/main/${{ env.PROJECT }}/
find ../
mv $BUILD_NAME.deb debian/pool/main/${{ env.PROJECT }}/
# Update the Packages file
dpkg-scanpackages debian/pool/main/${{ env.PROJECT }}/ /dev/null | gzip -9c > debian/dists/stable/main/binary-$arch/Packages.gz
# Remove the temporary folders
rm -rf $BUILD_NAME
done
# Move out of tmp and delete it
cd ../
rm -rf src
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: '${{ env.PROJECT }}: ${{ env.RELEASE_TAG }}'
title: '${{ env.PROJECT }}: ${{ env.RELEASE_TAG }}'
body: 'This is an automated PR to update ${{ env.PROJECT }} to ${{ env.RELEASE_TAG }}'
branch: ${{ env.PROJECT }}/update
base: master