chsrc/.github/workflows/pkg-deb.yml
2025-06-15 23:38:04 +08:00

184 lines
5.1 KiB
YAML

# ---------------------------------------------------------------
# Workflow File : pkg-deb.yml
# File Authors : sanchuanhehe <wyihe5520@gmail.com>
# Contributors : Aoran Zeng <ccmywish@qq.com>
# |
# Created On : <2025-06-10>
# Last Modified : <2025-06-15>
#
# This workflow build and publish DEB packages
# ---------------------------------------------------------------
name: Build and Publish DEB package
on:
release:
types: [ released ]
push:
branches: [ "gh-build" ]
workflow_dispatch:
inputs:
version:
description: 'Version to build'
required: true
default: '0.3.0' # 短暂时间内不可达到的最新版本号
jobs:
build-deb:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from tag or input
id: get_version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
version="${{ github.event.release.tag_name }}"
version=${version#v} # Remove 'v' prefix if present
elif [ "${{ github.event_name }}" = "push" ];then
version="9.9.9" # Default version for push events (temporarily)
else
version="${{ github.event.inputs.version }}"
fi
echo "version=$version" >> $GITHUB_OUTPUT
echo "Version: $version"
- name: Validate version tag
run: |
version="${{ steps.get_version.outputs.version }}"
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $version"
exit 1
fi
- name: Update debian/changelog with version
run: |
version="${{ steps.get_version.outputs.version }}"
cd ./pkg/DEB
(cat << EOF; cat ./debian/changelog) > new_changelog
chsrc ($version-1) unstable; urgency=medium
* Release version $version
-- Aoran Zeng <ccmywish@qq.com> $(date -R)
EOF
mv -f new_changelog ./debian/changelog
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y debhelper devscripts build-essential fakeroot
- name: Build package
run: |
make build-deb
- name: Move package into dist
run: |
version="${{ steps.get_version.outputs.version }}"
# Move the generated .deb file to a known location
mkdir -p dist
find ./pkg -name "chsrc_${version}*.deb" -exec mv {} dist/ \;
# Rename to standardized format if needed
cd dist
for file in chsrc_${version}*.deb; do
if [ -f "$file" ]; then
new_name="chsrc_${version}-1_amd64.deb"
if [ "$file" != "$new_name" ]; then
mv "$file" "$new_name"
fi
break
fi
done
- name: Verify package
run: |
version="${{ steps.get_version.outputs.version }}"
ls -la dist/
dpkg-deb --info dist/chsrc_${version}-1_amd64.deb
dpkg-deb --contents dist/chsrc_${version}-1_amd64.deb
- name: Test package installation
run: |
version="${{ steps.get_version.outputs.version }}"
# Install the package
sudo dpkg -i dist/chsrc_${version}-1_amd64.deb || true
sudo apt-get install -f -y || true
# Run DEB installation tests
bash pkg/DEB/deb-installation-test.sh
- name: Upload DEB artifact
uses: actions/upload-artifact@v4
with:
name: chsrc-deb-amd64
path: dist/chsrc_*.deb
retention-days: 30
- name: Upload to Releases (the newest release) if is release event
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.UPLOAD_TO_GITHUB }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: dist/chsrc_${{ steps.get_version.outputs.version }}-1_amd64.deb
asset_name: chsrc_${{ steps.get_version.outputs.version }}-1_amd64.deb
asset_content_type: application/vnd.debian.binary-package
- name: Upload to Releases (the 'pre' release) if is push event
if: github.event_name == 'push'
uses: softprops/action-gh-release@v1
with:
tag_name: pre
files: |
dist/chsrc_*_amd64.deb
token: ${{ secrets.UPLOAD_TO_GITHUB }}
create-repository-metadata:
needs: build-deb
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: chsrc-deb-*
merge-multiple: true
path: ./debs
- name: Install repository tools
run: |
sudo apt-get update
sudo apt-get install -y dpkg-dev
- name: Create Packages file
run: |
cd debs
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
dpkg-scanpackages . /dev/null > Packages
- name: Upload repository metadata
uses: actions/upload-artifact@v4
with:
name: debian-repository-metadata
path: debs/Packages*
retention-days: 30