1+ # This workflow will build and publish DEB packages for chsrc
2+ # when there is a new release event.
3+ name : Build and Publish DEB Package
4+
5+ on :
6+ release :
7+ types : [ released ]
8+ workflow_dispatch :
9+ inputs :
10+ version :
11+ description : ' Version to build'
12+ required : true
13+ default : ' 1.0.0'
14+
15+ jobs :
16+ build-deb :
17+ runs-on : ubuntu-latest
18+
19+ steps :
20+ - name : Checkout repository
21+ uses : actions/checkout@v4
22+
23+ - name : Get version from tag or input
24+ id : get_version
25+ run : |
26+ if [ "${{ github.event_name }}" = "release" ]; then
27+ version="${{ github.event.release.tag_name }}"
28+ version=${version#v} # Remove 'v' prefix if present
29+ else
30+ version="${{ github.event.inputs.version }}"
31+ fi
32+ echo "version=$version" >> $GITHUB_OUTPUT
33+ echo "Version: $version"
34+
35+ - name : Validate version tag
36+ run : |
37+ version="${{ steps.get_version.outputs.version }}"
38+ if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
39+ echo "Invalid version format: $version"
40+ exit 1
41+ fi
42+
43+ - name : Update debian/changelog with version
44+ run : |
45+ version="${{ steps.get_version.outputs.version }}"
46+ # Update changelog with new version
47+ cat > debian/changelog << EOF
48+ chsrc ($version-1) unstable; urgency=medium
49+
50+ * Release version $version
51+
52+ -- Aoran Zeng <ccmywish@qq.com> $(date -R)
53+
54+ EOF
55+
56+ - name : Set up build environment
57+ run : |
58+ sudo apt-get update
59+ sudo apt-get install -y debhelper devscripts build-essential fakeroot
60+
61+ - name : Build DEB package
62+ run : |
63+ version="${{ steps.get_version.outputs.version }}"
64+
65+ # Build the package
66+ debuild -us -uc -b
67+
68+ # Move the generated .deb file to a known location
69+ mkdir -p dist
70+ find .. -name "chsrc_${version}*.deb" -exec mv {} dist/ \;
71+
72+ # Rename to standardized format if needed
73+ cd dist
74+ for file in chsrc_${version}*.deb; do
75+ if [ -f "$file" ]; then
76+ new_name="chsrc_${version}-1_amd64.deb"
77+ if [ "$file" != "$new_name" ]; then
78+ mv "$file" "$new_name"
79+ fi
80+ break
81+ fi
82+ done
83+
84+ - name : Verify package
85+ run : |
86+ version="${{ steps.get_version.outputs.version }}"
87+ ls -la dist/
88+ dpkg-deb --info dist/chsrc_${version}-1_amd64.deb
89+ dpkg-deb --contents dist/chsrc_${version}-1_amd64.deb
90+
91+ - name : Test package installation
92+ run : |
93+ version="${{ steps.get_version.outputs.version }}"
94+ # Install the package
95+ sudo dpkg -i dist/chsrc_${version}-1_amd64.deb || true
96+ sudo apt-get install -f -y || true
97+
98+ # Run basic tests
99+ if [ -f "test/deb-test.sh" ]; then
100+ sudo bash test/deb-test.sh
101+ else
102+ # Basic manual test
103+ chsrc help
104+ echo "Package installation test passed!"
105+ fi
106+
107+ - name : Upload DEB artifact
108+ uses : actions/upload-artifact@v4
109+ with :
110+ name : chsrc-deb-amd64
111+ path : dist/chsrc_*.deb
112+ retention-days : 30
113+
114+ - name : Upload to release
115+ if : github.event_name == 'release'
116+ uses : actions/upload-release-asset@v1
117+ env :
118+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
119+ with :
120+ upload_url : ${{ github.event.release.upload_url }}
121+ asset_path : dist/chsrc_${{ steps.get_version.outputs.version }}-1_amd64.deb
122+ asset_name : chsrc_${{ steps.get_version.outputs.version }}-1_amd64.deb
123+ asset_content_type : application/vnd.debian.binary-package
124+
125+ create-repository-metadata :
126+ needs : build-deb
127+ runs-on : ubuntu-latest
128+ if : github.event_name == 'release'
129+
130+ steps :
131+ - name : Download all artifacts
132+ uses : actions/download-artifact@v4
133+ with :
134+ pattern : chsrc-deb-*
135+ merge-multiple : true
136+ path : ./debs
137+
138+ - name : Install repository tools
139+ run : |
140+ sudo apt-get update
141+ sudo apt-get install -y dpkg-dev
142+
143+ - name : Create Packages file
144+ run : |
145+ cd debs
146+ dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
147+ dpkg-scanpackages . /dev/null > Packages
148+
149+ - name : Upload repository metadata
150+ uses : actions/upload-artifact@v4
151+ with :
152+ name : debian-repository-metadata
153+ path : debs/Packages*
154+ retention-days : 30
0 commit comments