.github/workflows/release.yml #11
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
release: | |
types: [created, edited] | |
permissions: | |
contents: write | |
packages: write | |
env: | |
release_tag: ${{ github.event.release.tag_name }} | |
package_name: swiftwave-stats-ninja | |
homepage: https://swiftwave.org | |
license: Apache-2.0 | |
summary: Analytics and Resouce Stats collector for Swiftwave | |
maintainer: Tanmoy Sarkar <[email protected]>" | |
debian_architectures: "amd64,arm64,i386" | |
rpm_architectures: "x86_64,aarch64,i386" | |
go_archs: "amd64,arm64,386" | |
control_file: | | |
Package: $PACKAGE_NAME | |
Version: $RELEASE_VERSION | |
Architecture: $ARCH | |
Maintainer: $MAINTAINER | |
Description: $SUMMARY | |
Homepage: $HOMEPAGE | |
spec_file: | | |
Name: $PACKAGE_NAME | |
Version: $RELEASE_VERSION | |
Release: $RELEASE_NUMBER | |
Summary: $SUMMARY | |
Packager: $MAINTAINER | |
License: $LICENSE | |
URL: $HOMEPAGE | |
SOURCE0: $PACKAGE_NAME | |
%description | |
$SUMMARY | |
%install | |
mkdir -p %{buildroot}/usr/bin/ | |
install -m 755 %{SOURCE0} %{buildroot}/usr/bin/$PACKAGE_NAME | |
%files | |
/usr/bin/$PACKAGE_NAME | |
%global __strip /bin/true | |
jobs: | |
debian-packager: | |
name: Package and Release Debian Binary (APT) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Environment | |
run: | | |
release_tag="${{ env.release_tag }}" | |
release_version=$(echo "$release_tag" | cut -d'-' -f1) | |
release_number=$(echo "$release_tag" | cut -d'-' -f2) | |
echo "release_version=${release_version}" >> $GITHUB_ENV | |
echo "release_number=${release_number}" >> $GITHUB_ENV | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.22.1 | |
- name: Create Directory to dump .deb | |
run: mkdir -p ~/deb_builds | |
- name: Build for all debian_architectures | |
run: | | |
architectures=(${debian_architectures//,/ }) | |
go_archs=(${go_archs//,/ }) | |
for i in "${!architectures[@]}"; do | |
mkdir -p ~/deb_builds/${package_name}_${release_tag}_${architectures[$i]}/usr/bin | |
mkdir -p ~/deb_builds/${package_name}_${release_tag}_${architectures[$i]}/DEBIAN | |
GOOS=linux GOARCH=${go_archs[$i]} go build -o ${package_name} . | |
mv ${package_name} ~/deb_builds/${package_name}_${release_tag}_${architectures[$i]}/usr/bin | |
control_content="${control_file//\$PACKAGE_NAME/${package_name}}" | |
control_content="${control_content//\$RELEASE_VERSION/${release_version}}" | |
control_content="${control_content//\$ARCH/${architectures[$i]}}" | |
control_content="${control_content//\$LICENSE/${license}}" | |
control_content="${control_content//\$SUMMARY/${summary}}" | |
control_content="${control_content//\$HOMEPAGE/${homepage}}" | |
control_content="${control_content//\$MAINTAINER/${maintainer}}" | |
echo "$control_content" > ~/deb_builds/${package_name}_${release_tag}_${architectures[$i]}/DEBIAN/control | |
dpkg --build ~/deb_builds/${package_name}_${release_tag}_${architectures[$i]} | |
done | |
- name: Print Build Info | |
run: | | |
deb_build_files=($(ls ~/deb_builds/*.deb)) | |
deb_files_list="" | |
for file in "${deb_build_files[@]}"; do | |
deb_files_list+="$(echo -e "$file\n")" | |
done | |
echo "deb_build_files=${deb_files_list}" >> $GITHUB_ENV | |
echo "Built: $deb_files_list" | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: ${{ env.deb_build_files }} | |
tag_name: ${{ env.release_tag }} | |
rpm-packager: | |
name: Package and Release RPM Binary | |
runs-on: ubuntu-latest | |
container: almalinux:latest | |
steps: | |
- name: Setup Environment | |
run: | | |
IFS='-' read -ra version_parts <<< "${{ env.release_tag }}" | |
echo "release_version=${version_parts[0]}" >> $GITHUB_ENV | |
echo "release_number=${version_parts[1]}" >> $GITHUB_ENV | |
dnf install -y tree createrepo rpm-build rpm-sign wget gcc python3 yum-utils nodejs | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.22.1 | |
- name: Build for all architectures | |
run: | | |
architectures=(${rpm_architectures//,/ }) | |
go_archs=(${go_archs//,/ }) | |
for i in "${!architectures[@]}"; do | |
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} | |
GOOS=linux GOARCH=${go_archs[$i]} go build -o ${package_name} . | |
chmod +x ${package_name} | |
mv ${package_name} ~/rpmbuild/SOURCES | |
spec_content="${spec_file//\$PACKAGE_NAME/${package_name}}" | |
spec_content="${spec_content//\$RELEASE_VERSION/${release_version}}" | |
spec_content="${spec_content//\$RELEASE_NUMBER/${release_number}}" | |
spec_content="${spec_content//\$SUMMARY/${summary}}" | |
spec_content="${spec_content//\$LICENSE/${license}}" | |
spec_content="${spec_content//\$HOMEPAGE/${homepage}}" | |
spec_content="${spec_content//\$MAINTAINER/${maintainer}}" | |
echo "$spec_content" > ~/rpmbuild/SPECS/${package_name}.spec | |
rpmbuild -bb ~/rpmbuild/SPECS/${package_name}.spec --target ${architectures[$i]} | |
cp ~/rpmbuild/RPMS/*/*.rpm ~/ | |
rm -rf ~/rpmbuild/* | |
done | |
- name: Print Build Info | |
run: | | |
for i in ~/*.rpm; do | |
echo "Built: $i" | |
rpm -qip $i | |
done | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: ~/*.rpm | |
tag_name: ${{ env.release_tag }} |