2424 - name : Check if we should run
2525 id : should_run
2626 run : |
27+ # Configure git safe directory
28+ git config --global --add safe.directory /__w/sshctl/sshctl
29+
2730 # Check if commit message contains [force-aur]
2831 if [[ "${{ github.event.head_commit.message }}" == *"[force-aur]"* ]]; then
2932 echo "run=true" >> $GITHUB_OUTPUT
@@ -39,7 +42,133 @@ jobs:
3942 fi
4043
4144 # Check for relevant file changes in the last commit
42- if git diff-tree --no-commit-id --name-only -r HEAD | grep -E '^src/|^Cargo\.(toml|lock)$|^README\.md$|^LICENSE$'; then
45+ if git diff-tree --no-commit-id --name-only -r HEAD | grep -E '^src/|^Cargo\.(toml|lock)$|^README\.md$|^LICENSE
46+
47+ - name : Setup SSH for AUR
48+ if : steps.should_run.outputs.run == 'true'
49+ run : |
50+ mkdir -p /root/.ssh
51+ echo "${{ secrets.AUR_SSH_KEY }}" > /root/.ssh/aur
52+ chmod 600 /root/.ssh/aur
53+ chmod 700 /root/.ssh
54+ ssh-keyscan aur.archlinux.org >> /root/.ssh/known_hosts
55+
56+ - name : Test AUR connection
57+ if : steps.should_run.outputs.run == 'true'
58+ run : |
59+ if ssh -i /root/.ssh/aur -T aur@aur.archlinux.org 2>&1 | grep -q "Welcome to AUR"; then
60+ echo "AUR connection successful"
61+ else
62+ echo "AUR connection failed"
63+ exit 1
64+ fi
65+
66+ - name : Clone AUR git package
67+ if : steps.should_run.outputs.run == 'true'
68+ run : |
69+ export GIT_SSH_COMMAND="ssh -i /root/.ssh/aur -o StrictHostKeyChecking=no"
70+ git clone ssh://aur@aur.archlinux.org/sshctl-git.git aur-repo
71+
72+ - name : Calculate development version
73+ if : steps.should_run.outputs.run == 'true'
74+ id : version
75+ run : |
76+ # Extract version from Cargo.toml
77+ CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
78+
79+ # Get short commit hash (7 characters)
80+ SHORT_HASH=$(git rev-parse --short=7 HEAD)
81+
82+ # Create development version: cargo_version-short_hash
83+ DEV_VERSION="${CARGO_VERSION}-${SHORT_HASH}"
84+
85+ echo "dev_version=${DEV_VERSION}" >> $GITHUB_OUTPUT
86+ echo "Development version: ${DEV_VERSION}"
87+ echo "Cargo version: ${CARGO_VERSION}, Commit hash: ${SHORT_HASH}"
88+
89+ - name : Create development PKGBUILD
90+ if : steps.should_run.outputs.run == 'true'
91+ run : |
92+ cd aur-repo
93+ cat > PKGBUILD << 'PKGBUILD_EOF'
94+ # Maintainer: ${{ secrets.AUR_MAINTAINER_NAME }} <${{ secrets.AUR_MAINTAINER_EMAIL }}>
95+ pkgname=sshctl-git
96+ pkgver=${{ steps.version.outputs.dev_version }}
97+ pkgrel=1
98+ pkgdesc="SSH connection manager CLI tool (development version)"
99+ arch=('x86_64')
100+ url="https://github.com/${{ github.repository }}"
101+ license=('MIT')
102+ depends=('glibc')
103+ makedepends=('git' 'rust')
104+ provides=('sshctl')
105+ conflicts=('sshctl')
106+ source=("git+https://github.com/${{ github.repository }}.git")
107+ sha256sums=('SKIP')
108+
109+ pkgver() {
110+ cd "${srcdir}/sshctl"
111+ local cargo_ver=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
112+ local short_hash=$(git rev-parse --short=7 HEAD)
113+ printf "%s-%s" "${cargo_ver}" "${short_hash}"
114+ }
115+
116+ build() {
117+ cd "${srcdir}/sshctl"
118+ cargo build --release
119+ }
120+
121+ package() {
122+ cd "${srcdir}/sshctl"
123+ install -Dm755 "target/release/sshctl" "${pkgdir}/usr/bin/sshctl"
124+
125+ if [ -f README.md ]; then
126+ install -Dm644 README.md "${pkgdir}/usr/share/doc/sshctl/README.md"
127+ fi
128+
129+ if [ -f LICENSE ]; then
130+ install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/sshctl/LICENSE"
131+ fi
132+ }
133+ PKGBUILD_EOF
134+
135+ - name : Generate .SRCINFO for development package
136+ if : steps.should_run.outputs.run == 'true'
137+ run : |
138+ cd aur-repo
139+
140+ # Create non-root user for makepkg
141+ useradd -m -s /bin/bash builder
142+
143+ # Copy PKGBUILD to builder's home and generate .SRCINFO there
144+ cp PKGBUILD /home/builder/
145+ chown builder:builder /home/builder/PKGBUILD
146+
147+ # Generate .SRCINFO as non-root user
148+ su builder -c "cd /home/builder && makepkg --printsrcinfo" > .SRCINFO
149+
150+ # Ensure root owns the .SRCINFO in the repo
151+ chown root:root .SRCINFO
152+
153+ - name : Commit and push development version to AUR
154+ if : steps.should_run.outputs.run == 'true'
155+ run : |
156+ cd aur-repo
157+ export GIT_SSH_COMMAND="ssh -i /root/.ssh/aur -o StrictHostKeyChecking=no"
158+
159+ git config user.name "${{ secrets.AUR_MAINTAINER_NAME }}"
160+ git config user.email "${{ secrets.AUR_MAINTAINER_EMAIL }}"
161+
162+ git add PKGBUILD .SRCINFO
163+
164+ if git diff --cached --quiet; then
165+ echo "No changes to commit"
166+ else
167+ git commit -m "Update development version to ${{ steps.version.outputs.dev_version }}"
168+ git push origin master
169+ echo "AUR development package updated successfully!"
170+ fi
171+ ; then
43172 echo "run=true" >> $GITHUB_OUTPUT
44173 echo "Relevant files changed"
45174 else
0 commit comments