Update update-aur-git-dev.yml #22
This file contains hidden or 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
| # Update AUR git package on main branch changes | |
| name: Update AUR Git (Development) | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| update-aur-git-dev: | |
| runs-on: ubuntu-latest | |
| container: archlinux:latest | |
| steps: | |
| - name: Install dependencies | |
| run: | | |
| pacman -Syu --noconfirm | |
| pacman -S --noconfirm git openssh base-devel | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure git safe directory | |
| run: | | |
| git config --global --add safe.directory /__w/sshctl/sshctl | |
| - name: Check if we should run | |
| id: should_run | |
| run: | | |
| if [[ "${{ github.event.head_commit.message }}" == *"[force-aur]"* ]]; then | |
| echo "run=true" >> $GITHUB_OUTPUT | |
| echo "Forced AUR update via commit message" | |
| exit 0 | |
| fi | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "run=true" >> $GITHUB_OUTPUT | |
| echo "Manual trigger" | |
| exit 0 | |
| fi | |
| if git rev-parse HEAD^2 >/dev/null 2>&1; then | |
| echo "Merge commit detected, checking parent changes" | |
| CHANGED_FILES=$(git diff --name-only HEAD^1 HEAD^2) | |
| else | |
| CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD) | |
| fi | |
| if echo "$CHANGED_FILES" | grep -E '^src/|^Cargo\.(toml|lock)$|^README\.md$|^LICENSE$'; then | |
| echo "run=true" >> $GITHUB_OUTPUT | |
| echo "Relevant files changed" | |
| else | |
| echo "run=false" >> $GITHUB_OUTPUT | |
| echo "No relevant changes found, skipping AUR update" | |
| fi | |
| - name: Setup SSH for AUR | |
| if: steps.should_run.outputs.run == 'true' | |
| run: | | |
| mkdir -p /root/.ssh | |
| echo "${{ secrets.AUR_SSH_KEY }}" > /root/.ssh/aur | |
| chmod 600 /root/.ssh/aur | |
| chmod 700 /root/.ssh | |
| ssh-keyscan -t ed25519,rsa aur.archlinux.org >> /root/.ssh/known_hosts 2>/dev/null || true | |
| - name: Test AUR connection | |
| if: steps.should_run.outputs.run == 'true' | |
| run: | | |
| if ssh -i /root/.ssh/aur -T aur@aur.archlinux.org 2>&1 | grep -q "Welcome to AUR"; then | |
| echo "AUR connection successful" | |
| else | |
| echo "AUR connection failed" | |
| exit 1 | |
| fi | |
| - name: Clone AUR git package | |
| if: steps.should_run.outputs.run == 'true' | |
| run: | | |
| export GIT_SSH_COMMAND="ssh -i /root/.ssh/aur -o StrictHostKeyChecking=no" | |
| git clone ssh://aur@aur.archlinux.org/sshctl-git.git aur-repo | |
| - name: Calculate development version | |
| if: steps.should_run.outputs.run == 'true' | |
| id: version | |
| run: | | |
| CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
| SHORT_HASH=$(git rev-parse --short=7 HEAD) | |
| DEV_VERSION="${CARGO_VERSION}-${SHORT_HASH}" | |
| echo "dev_version=${DEV_VERSION}" >> $GITHUB_OUTPUT | |
| echo "Development version: ${DEV_VERSION}" | |
| echo "Cargo version: ${CARGO_VERSION}, Commit hash: ${SHORT_HASH}" | |
| - name: Create development PKGBUILD | |
| if: steps.should_run.outputs.run == 'true' | |
| run: | | |
| cd aur-repo | |
| cat > PKGBUILD << 'EOF' | |
| # Maintainer: ${{ secrets.AUR_MAINTAINER_NAME }} <${{ secrets.AUR_MAINTAINER_EMAIL }}> | |
| pkgname=sshctl-git | |
| pkgver=${{ steps.version.outputs.dev_version }} | |
| pkgrel=1 | |
| pkgdesc="SSH connection manager CLI tool (development version)" | |
| arch=('x86_64') | |
| url="https://github.com/${{ github.repository }}" | |
| license=('MIT') | |
| depends=('glibc') | |
| makedepends=('git' 'rust') | |
| provides=('sshctl') | |
| conflicts=('sshctl') | |
| source=("git+https://github.com/${{ github.repository }}.git") | |
| sha256sums=('SKIP') | |
| pkgver() { | |
| cd "${srcdir}/sshctl" | |
| local cargo_ver=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | |
| local short_hash=$(git rev-parse --short=7 HEAD) | |
| printf "%s-%s" "${cargo_ver}" "${short_hash}" | |
| } | |
| build() { | |
| cd "${srcdir}/sshctl" | |
| cargo build --release | |
| } | |
| package() { | |
| cd "${srcdir}/sshctl" | |
| install -Dm755 "target/release/sshctl" "${pkgdir}/usr/bin/sshctl" | |
| if [ -f README.md ]; then | |
| install -Dm644 README.md "${pkgdir}/usr/share/doc/sshctl/README.md" | |
| fi | |
| if [ -f LICENSE ]; then | |
| install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/sshctl/LICENSE" | |
| fi | |
| } | |
| EOF | |
| - name: Generate .SRCINFO for development package | |
| if: steps.should_run.outputs.run == 'true' | |
| run: | | |
| cd aur-repo | |
| useradd -m -s /bin/bash builder | |
| cp PKGBUILD /home/builder/ | |
| chown builder:builder /home/builder/PKGBUILD | |
| su builder -c "cd /home/builder && makepkg --printsrcinfo" > .SRCINFO | |
| chown root:root .SRCINFO | |
| - name: Commit and push development version to AUR | |
| if: steps.should_run.outputs.run == 'true' | |
| run: | | |
| cd aur-repo | |
| export GIT_SSH_COMMAND="ssh -i /root/.ssh/aur -o StrictHostKeyChecking=no" | |
| git config user.name "${{ secrets.AUR_MAINTAINER_NAME }}" | |
| git config user.email "${{ secrets.AUR_MAINTAINER_EMAIL }}" | |
| git add PKGBUILD .SRCINFO | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Update development version to ${{ steps.version.outputs.dev_version }}" | |
| git push origin master | |
| echo "AUR development package updated successfully!" | |
| fi |