Skip to content

Build .deb Packages #21

Build .deb Packages

Build .deb Packages #21

Workflow file for this run

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'
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
default: ''
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
echo "DESCRIPTION=${{ github.event.inputs.description }}" >> $GITHUB_ENV
echo "WORKFLOW_ID=${{ github.event.inputs.workflow_id }}" >> $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
fi
echo "Building ${{ env.PROJECT}} .deb packages for tag ${{ env.RELEASE_TAG }}"
- name: Checkout repo
uses: actions/checkout@v3
- name: Download release artifacts from workflow
uses: dawidd6/action-download-artifact@v3
with:
name: ${{ env.PROJECT }}_linux_.+
name_is_regex: true
repo: SiaFoundation/${{ env.PROJECT }}
run_id: ${{ env.WORKFLOW_ID }}
workflow_conclusion: success
- name: Build .deb Package
run: |
TAG=${{ env.RELEASE_TAG }}
VERSION=${TAG:1}
# DEBUG: list files
find .
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
# Copy the ${{ env.PROJECT }} binary
cp ${{ env.PROJECT }}/${{ env.PROJECT }}_linux_${arch} ${BUILD_NAME}/usr/bin/${{ env.PROJECT }}
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: ${DESCRIPTION}" >> ${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
mv ${BUILD_NAME}.deb ../debian/pool/main/${{ env.PROJECT }}/
# Remove the temporary folders
rm -rf ${BUILD_NAME}
# Update the Packages file
mkdir -p debian/dists/stable/main/binary-${arch}
dpkg-scanpackages ../debian/pool/main/ | gzip -c > debian/dists/stable/main/binary-${arch}/Packages.gz
done
# Move out of tmp and delete it
cd ../
rm -rf tmp
- 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_TAG }}'
body: 'This is an automated PR to update ${{ env.PROJECT }} to ${{ env.RELEASE_TAG }}'
branch: ${{ env.PROJECT }}/update
base: master