.github/workflows/update-aur.yml
124 lines · 3969 bytes
1name: Update AUR Package
2
3on:
4 release:
5 types: [published]
6 workflow_dispatch:
7 inputs:
8 tag_name:
9 description: 'Release tag name (e.g., v1.2.3)'
10 required: true
11 type: string
12
13jobs:
14 update-aur:
15 runs-on: ubuntu-latest
16 if: github.repository == 'Wraient/curd'
17
18 steps:
19 - name: Checkout main repository
20 uses: actions/checkout@v4
21
22 - name: Extract version from tag
23 id: version
24 run: |
25 if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
26 TAG_NAME="${{ github.event.inputs.tag_name }}"
27 else
28 TAG_NAME="${{ github.event.release.tag_name }}"
29 fi
30 VERSION=$(echo "$TAG_NAME" | sed 's/^v//')
31 echo "version=$VERSION" >> $GITHUB_OUTPUT
32 echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
33 echo "Extracted version: $VERSION"
34
35 - name: Install dependencies
36 run: |
37 sudo apt-get update
38 sudo apt-get install -y expect git sshpass
39
40 - name: Set up SSH for AUR
41 run: |
42 mkdir -p ~/.ssh
43 echo "${{ secrets.AUR_SSH_KEY }}" > ~/.ssh/aur_rsa
44 chmod 600 ~/.ssh/aur_rsa
45
46 # Create SSH config for AUR
47 cat > ~/.ssh/config << EOF
48 Host aur.archlinux.org
49 HostName aur.archlinux.org
50 User aur
51 IdentityFile ~/.ssh/aur_rsa
52 StrictHostKeyChecking no
53 EOF
54
55 # Start SSH agent and add key with passphrase
56 eval $(ssh-agent -s)
57 echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
58 echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV
59
60 # Use expect to add the key with passphrase
61 expect -c "
62 spawn ssh-add ~/.ssh/aur_rsa
63 expect \"Enter passphrase\"
64 send \"sex\r\"
65 expect eof
66 "
67
68 - name: Clone AUR repository
69 run: |
70 # The SSH agent should still be running with the key loaded
71 git clone ssh://aur@aur.archlinux.org/curd.git aur-curd
72
73 - name: Update PKGBUILD
74 working-directory: aur-curd
75 run: |
76 # Configure git
77 git config user.name "Wraient"
78 git config user.email "rushikeshwastaken@gmail.com"
79
80 # Update pkgver in PKGBUILD
81 sed -i "s/^pkgver=.*/pkgver=${{ steps.version.outputs.version }}/" PKGBUILD
82
83 # Reset pkgrel to 1 for new version
84 sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD
85
86 # Update .SRCINFO
87 makepkg --printsrcinfo > .SRCINFO
88
89 echo "Updated PKGBUILD:"
90 cat PKGBUILD
91
92 - name: Verify release exists
93 run: |
94 # Check if the release and binary exist
95 curl -f -L -I "https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64" || {
96 echo "Error: Release binary not found!"
97 echo "Expected URL: https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64"
98 exit 1
99 }
100
101 - name: Commit and push to AUR
102 working-directory: aur-curd
103 run: |
104 # Check if there are changes to commit
105 if git diff --quiet && git diff --cached --quiet; then
106 echo "No changes to commit"
107 exit 0
108 fi
109
110 # Add and commit changes
111 git add PKGBUILD .SRCINFO
112 git commit -m "Update to version ${{ steps.version.outputs.version }}"
113
114 # Push changes (SSH agent should still have the key loaded)
115 git push origin master
116
117 - name: Cleanup
118 if: always()
119 run: |
120 # Clean up SSH keys and kill SSH agent
121 rm -f ~/.ssh/aur_rsa
122 if [ -n "$SSH_AGENT_PID" ]; then
123 kill $SSH_AGENT_PID 2>/dev/null || true
124 fi