.github/workflows/update-aur.yml

236 lines · 8030 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        env:
 42          SSH_PASSPHRASE: "sex"
 43        run: |
 44          mkdir -p ~/.ssh
 45          # Write the SSH key, ensuring proper formatting
 46          cat > ~/.ssh/aur_rsa << 'EOF'
 47          ${{ secrets.AUR_SSH_KEY }}
 48          EOF
 49          chmod 600 ~/.ssh/aur_rsa
 50          
 51          # Create SSH config for AUR
 52          cat > ~/.ssh/config << EOF
 53          Host aur.archlinux.org
 54            HostName aur.archlinux.org
 55            User aur
 56            IdentityFile ~/.ssh/aur_rsa
 57            StrictHostKeyChecking no
 58            IdentitiesOnly yes
 59          EOF
 60          
 61          # Add AUR host key to known_hosts
 62          ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts
 63          
 64          # Start SSH agent and add key with passphrase
 65          eval $(ssh-agent -s)
 66          echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV
 67          echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV
 68          
 69          # Debug: Check key format
 70          echo "Checking SSH key format..."
 71          head -1 ~/.ssh/aur_rsa
 72          
 73          # Try alternative method using expect with better error handling
 74          expect -c "
 75            set timeout 20
 76            log_user 1
 77            spawn ssh-add ~/.ssh/aur_rsa
 78            expect {
 79              \"Enter passphrase*\" {
 80                send \"$env(SSH_PASSPHRASE)\r\"
 81                expect {
 82                  \"Identity added*\" {
 83                    puts \"SUCCESS: Key added to agent\"
 84                    exit 0
 85                  }
 86                  \"Bad passphrase*\" {
 87                    puts \"ERROR: Bad passphrase\"
 88                    exit 1
 89                  }
 90                  timeout {
 91                    puts \"ERROR: Timeout after entering passphrase\"
 92                    exit 1
 93                  }
 94                }
 95              }
 96              \"*already loaded*\" {
 97                puts \"Key already loaded\"
 98                exit 0
 99              }
100              timeout {
101                puts \"ERROR: Timeout waiting for passphrase prompt\"
102                exit 1
103              }
104              eof {
105                puts \"Unexpected end of file\"
106                exit 1
107              }
108            }
109          " || {
110            echo "Expect failed, trying alternative method..."
111            # Alternative: try with DISPLAY set to avoid GUI prompts
112            DISPLAY=:0 SSH_ASKPASS_REQUIRE=never ssh-add ~/.ssh/aur_rsa 2>&1 || echo "Alternative method also failed"
113          }
114          
115          # Verify key is loaded
116          echo "Checking loaded keys:"
117          ssh-add -l 2>&1 || echo "No keys in agent"
118          
119          # Test connection with verbose output for debugging
120          echo "Testing SSH connection with verbose output:"
121          ssh -vT aur@aur.archlinux.org 2>&1 | head -20 || echo "SSH test completed"
122
123      - name: Clone AUR repository
124        run: |
125          # Debug: Check if SSH agent is running
126          echo "SSH_AUTH_SOCK: $SSH_AUTH_SOCK"
127          echo "SSH_AGENT_PID: $SSH_AGENT_PID"
128          
129          # Debug: List loaded keys
130          echo "Keys currently loaded in SSH agent:"
131          ssh-add -l 2>&1 || echo "No keys in agent or agent not accessible"
132          
133          # Debug: Test if key file exists and has correct permissions
134          echo "Checking key file:"
135          ls -la ~/.ssh/aur_rsa
136          
137          # Try to manually load the key again with debugging
138          echo "Attempting to load key manually..."
139          expect -c "
140            set timeout 30
141            log_user 1
142            spawn ssh-add -v ~/.ssh/aur_rsa
143            expect {
144              \"Enter passphrase*\" {
145                send \"sex\r\"
146                expect {
147                  \"Identity added*\" {
148                    puts \"SUCCESS: Key loaded\"
149                    exit 0
150                  }
151                  \"Bad passphrase*\" {
152                    puts \"ERROR: Bad passphrase\"
153                    exit 1
154                  }
155                  timeout {
156                    puts \"ERROR: Timeout after passphrase\"
157                    exit 1
158                  }
159                }
160              }
161              \"*already loaded*\" {
162                puts \"Key already loaded\"
163                exit 0
164              }
165              timeout {
166                puts \"ERROR: No passphrase prompt\"
167                exit 1
168              }
169              eof
170            }
171          " || echo "Manual key loading failed"
172          
173          # Check again if key is loaded
174          echo "Keys after manual loading attempt:"
175          ssh-add -l 2>&1 || echo "Still no keys in agent"
176          
177          # Try direct SSH test with key file
178          echo "Testing direct SSH connection..."
179          ssh -o PasswordAuthentication=no -o IdentitiesOnly=yes -i ~/.ssh/aur_rsa -T aur@aur.archlinux.org 2>&1 | head -10
180          
181          # Clone with verbose output
182          echo "Attempting to clone with SSH debugging..."
183          GIT_SSH_COMMAND="ssh -v -o IdentitiesOnly=yes -i ~/.ssh/aur_rsa" git clone ssh://aur@aur.archlinux.org/curd.git aur-curd
184
185      - name: Update PKGBUILD
186        working-directory: aur-curd
187        run: |
188          # Configure git
189          git config user.name "Wraient"
190          git config user.email "rushikeshwastaken@gmail.com"
191          
192          # Update pkgver in PKGBUILD
193          sed -i "s/^pkgver=.*/pkgver=${{ steps.version.outputs.version }}/" PKGBUILD
194          
195          # Reset pkgrel to 1 for new version
196          sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD
197          
198          # Update .SRCINFO
199          makepkg --printsrcinfo > .SRCINFO
200          
201          echo "Updated PKGBUILD:"
202          cat PKGBUILD
203
204      - name: Verify release exists
205        run: |
206          # Check if the release and binary exist
207          curl -f -L -I "https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64" || {
208            echo "Error: Release binary not found!"
209            echo "Expected URL: https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64"
210            exit 1
211          }
212
213      - name: Commit and push to AUR
214        working-directory: aur-curd
215        run: |
216          # Check if there are changes to commit
217          if git diff --quiet && git diff --cached --quiet; then
218            echo "No changes to commit"
219            exit 0
220          fi
221          
222          # Add and commit changes
223          git add PKGBUILD .SRCINFO
224          git commit -m "Update to version ${{ steps.version.outputs.version }}"
225          
226          # Push changes (SSH agent should still have the key loaded)
227          git push origin master
228
229      - name: Cleanup
230        if: always()
231        run: |
232          # Clean up SSH keys and kill SSH agent
233          rm -f ~/.ssh/aur_rsa
234          if [ -n "$SSH_AGENT_PID" ]; then
235            kill $SSH_AGENT_PID 2>/dev/null || true
236          fi