Skip to content

Commit c41bcf7

Browse files
authored
Merge pull request #206 from sanchuanhehe/main
2 parents 19b9e54 + cac040e commit c41bcf7

File tree

13 files changed

+542
-3
lines changed

13 files changed

+542
-3
lines changed

.github/workflows/pkg-deb.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@ chsrc.log
3333
chsrc.toc
3434
*.info
3535
*.pdf
36+
37+
# DEB package build artifacts
38+
debian/chsrc/
39+
debian/.debhelper/
40+
debian/debhelper-build-stamp
41+
debian/files
42+
debian/chsrc.debhelper.log
43+
debian/chsrc.substvars
44+
*.deb
45+
*.changes
46+
*.buildinfo

Makefile

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,25 @@ debug: CFLAGS += -g
7676
debug: all
7777
@$(DEBUGGER) ./chsrc
7878

79-
test: test-xy test-fw
79+
test: test-env test-xy test-fw
80+
81+
test-env:
82+
@echo "On-Linux: $(On-Linux)"
83+
@echo "On-Windows: $(On-Windows)"
84+
@echo "On-macOS: $(On-macOS)"
85+
@echo "CC: $(CC)"
86+
@echo "CFLAGS: $(CFLAGS)"
87+
@echo "Target-Name: $(Target-Name)"
88+
@echo "USER: $(whoami)"
89+
@echo "PWD: $(shell pwd)"
90+
@echo "UID: $(id -u)"
91+
@echo "GID: $(id -g)"
92+
# 检查HOME环境变量
93+
@if [ -z "$(HOME)" ]; then \
94+
echo "HOME environment variable is not set!"; \
95+
else \
96+
echo "HOME: $(HOME)"; \
97+
fi
8098

8199
test-xy:
82100
@$(CC) test/xy.c $(CFLAGS) -o xy
@@ -86,6 +104,19 @@ test-fw:
86104
@$(CC) test/fw.c $(CFLAGS) -o fw
87105
@./fw
88106

107+
# DEB package targets
108+
deb-prepare: $(Target-Name)
109+
@echo "Preparing for DEB package build..."
110+
111+
deb-build: deb-prepare
112+
@echo "Building DEB package..."
113+
@debuild -us -uc -b
114+
115+
deb-clean:
116+
@echo "Cleaning DEB build artifacts..."
117+
-@rm -rf debian/chsrc/
118+
-@rm -f ../chsrc_*.deb ../chsrc_*.changes ../chsrc_*.buildinfo
119+
89120
# AUR package 安装时将执行此 target
90121
fastcheck: $(Target-Name)
91122
@perl ./test/cli.pl fastcheck
@@ -99,3 +130,10 @@ clean:
99130
-@rm fw 2>/dev/null
100131
-@rm chsrc 2>/dev/null
101132
-@rm README.md.bak* 2>/dev/null
133+
134+
135+
install: $(Target-Name)
136+
install -D -m 755 $(Target-Name) $(DESTDIR)/usr/bin/$(Target-Name)
137+
install -D -m 644 doc/chsrc.1 $(DESTDIR)/usr/share/man/man1/chsrc.1
138+
139+
.PHONY: all CI debug test test-xy test-fw fastcheck test-cli clean deb-prepare deb-build deb-clean install

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
chsrc (1.0.0) unstable; urgency=medium
2+
3+
* Initial debian package release
4+
5+
-- Aoran Zeng <ccmywish@qq.com> Mon, 10 Jun 2025 00:00:00 +0000

debian/control

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Source: chsrc
2+
Section: utils
3+
Priority: optional
4+
Maintainer: sanchuanhehe <wyihe5520@gmail.com>
5+
Build-Depends: debhelper-compat (= 13), build-essential, libc6-dev
6+
Standards-Version: 4.6.0
7+
Homepage: https://github.com/RubyMetric/chsrc
8+
Vcs-Git: https://github.com/RubyMetric/chsrc.git
9+
Vcs-Browser: https://github.com/RubyMetric/chsrc
10+
11+
Package: chsrc
12+
Architecture: any
13+
Depends: ${shlibs:Depends}, ${misc:Depends}
14+
Description: Change Source - A tool for changing software sources
15+
chsrc is a command-line tool for changing software sources (mirrors)
16+
for various package managers and programming language ecosystems.
17+
It supports automatic detection and switching of sources for better
18+
download speeds in different regions.

debian/copyright

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: chsrc
3+
Upstream-Contact: Aoran Zeng <ccmywish@qq.com>
4+
Source: https://github.com/RubyMetric/chsrc
5+
6+
Files: *
7+
Copyright: 2023-2025 Aoran Zeng <ccmywish@qq.com>
8+
License: GPL-3.0-or-later
9+
10+
Files: debian/*
11+
Copyright: 2025 Aoran Zeng <ccmywish@qq.com>
12+
License: GPL-3.0-or-later
13+
14+
License: GPL-3.0-or-later
15+
This program is free software: you can redistribute it and/or modify
16+
it under the terms of the GNU General Public License as published by
17+
the Free Software Foundation, either version 3 of the License, or
18+
(at your option) any later version.
19+
.
20+
This program is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU General Public License for more details.
24+
.
25+
You should have received a copy of the GNU General Public License
26+
along with this program. If not, see <https://www.gnu.org/licenses/>.
27+
.
28+
On Debian systems, the complete text of the GNU General
29+
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".

debian/postinst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
# postinst script for chsrc
3+
4+
set -e
5+
6+
case "$1" in
7+
configure)
8+
# Update man database
9+
if command -v mandb >/dev/null 2>&1; then
10+
mandb -q /usr/share/man/man1/chsrc.1 2>/dev/null || true
11+
fi
12+
13+
# Make sure chsrc is executable
14+
chmod +x /usr/bin/chsrc
15+
16+
echo "chsrc has been successfully installed!"
17+
echo "Run 'chsrc help' to get started."
18+
;;
19+
20+
abort-upgrade|abort-remove|abort-deconfigure)
21+
;;
22+
23+
*)
24+
echo "postinst called with unknown argument \`$1'" >&2
25+
exit 1
26+
;;
27+
esac
28+
29+
#DEBHELPER#
30+
31+
exit 0

debian/prerm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
# prerm script for chsrc
3+
4+
set -e
5+
6+
case "$1" in
7+
remove|upgrade|deconfigure)
8+
# Nothing special to do during removal
9+
;;
10+
11+
failed-upgrade)
12+
;;
13+
14+
*)
15+
echo "prerm called with unknown argument \`$1'" >&2
16+
exit 1
17+
;;
18+
esac
19+
20+
#DEBHELPER#
21+
22+
exit 0

debian/rules

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/make -f
2+
3+
%:
4+
dh $@
5+
6+
override_dh_auto_build:
7+
$(MAKE) all
8+
9+
override_dh_auto_install:
10+
$(MAKE) install DESTDIR=$(CURDIR)/debian/chsrc

0 commit comments

Comments
 (0)