|
| 1 | +name: Update AUR Package |
| 2 | + |
| 3 | +on: |
| 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 | + |
| 13 | +jobs: |
| 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 | + # Write the SSH key |
| 44 | + cat > ~/.ssh/aur_rsa << 'EOF' |
| 45 | + ${{ secrets.AUR_SSH_KEY }} |
| 46 | + EOF |
| 47 | + chmod 600 ~/.ssh/aur_rsa |
| 48 | + |
| 49 | + # Add AUR host key |
| 50 | + ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts |
| 51 | + |
| 52 | + # Test the key directly (this should prompt for passphrase) |
| 53 | + echo "Testing SSH key..." |
| 54 | + expect -c " |
| 55 | + set timeout 30 |
| 56 | + spawn ssh -o PasswordAuthentication=no -o IdentitiesOnly=yes -i ~/.ssh/aur_rsa -T aur@aur.archlinux.org |
| 57 | + expect { |
| 58 | + \"Enter passphrase*\" { |
| 59 | + send \"sex\r\" |
| 60 | + expect { |
| 61 | + \"Welcome to AUR*\" { |
| 62 | + puts \"SUCCESS: SSH connection works\" |
| 63 | + exit 0 |
| 64 | + } |
| 65 | + \"Permission denied*\" { |
| 66 | + puts \"ERROR: Permission denied after passphrase\" |
| 67 | + exit 1 |
| 68 | + } |
| 69 | + timeout { |
| 70 | + puts \"ERROR: Timeout after passphrase\" |
| 71 | + exit 1 |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + \"Welcome to AUR*\" { |
| 76 | + puts \"SUCCESS: SSH works without passphrase\" |
| 77 | + exit 0 |
| 78 | + } |
| 79 | + \"Permission denied*\" { |
| 80 | + puts \"ERROR: Permission denied - wrong key or not authorized\" |
| 81 | + exit 1 |
| 82 | + } |
| 83 | + timeout { |
| 84 | + puts \"ERROR: Connection timeout\" |
| 85 | + exit 1 |
| 86 | + } |
| 87 | + } |
| 88 | + " |
| 89 | +
|
| 90 | + - name: Clone AUR repository |
| 91 | + run: | |
| 92 | + # Use expect to handle the passphrase during git clone |
| 93 | + expect -c " |
| 94 | + set timeout 60 |
| 95 | + spawn git clone ssh://aur@aur.archlinux.org/curd.git aur-curd |
| 96 | + expect { |
| 97 | + \"Enter passphrase*\" { |
| 98 | + send \"sex\r\" |
| 99 | + exp_continue |
| 100 | + } |
| 101 | + \"Cloning into*\" { |
| 102 | + puts \"Clone started successfully\" |
| 103 | + exp_continue |
| 104 | + } |
| 105 | + \"Permission denied*\" { |
| 106 | + puts \"ERROR: Permission denied\" |
| 107 | + exit 1 |
| 108 | + } |
| 109 | + eof { |
| 110 | + puts \"Clone completed\" |
| 111 | + exit 0 |
| 112 | + } |
| 113 | + timeout { |
| 114 | + puts \"ERROR: Clone timeout\" |
| 115 | + exit 1 |
| 116 | + } |
| 117 | + } |
| 118 | + " |
| 119 | + |
| 120 | + # Verify the clone worked |
| 121 | + if [ -d "aur-curd" ]; then |
| 122 | + echo "SUCCESS: AUR repository cloned" |
| 123 | + ls -la aur-curd/ |
| 124 | + else |
| 125 | + echo "ERROR: Clone failed" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | +
|
| 129 | + - name: Update PKGBUILD |
| 130 | + working-directory: aur-curd |
| 131 | + run: | |
| 132 | + # Configure git |
| 133 | + git config user.name "Wraient" |
| 134 | + git config user.email "rushikeshwastaken@gmail.com" |
| 135 | + |
| 136 | + # Update pkgver in PKGBUILD |
| 137 | + sed -i "s/^pkgver=.*/pkgver=${{ steps.version.outputs.version }}/" PKGBUILD |
| 138 | + |
| 139 | + # Reset pkgrel to 1 for new version |
| 140 | + sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD |
| 141 | + |
| 142 | + # Update .SRCINFO |
| 143 | + makepkg --printsrcinfo > .SRCINFO |
| 144 | + |
| 145 | + echo "Updated PKGBUILD:" |
| 146 | + cat PKGBUILD |
| 147 | +
|
| 148 | + - name: Verify release exists |
| 149 | + run: | |
| 150 | + # Check if the release and binary exist |
| 151 | + curl -f -L -I "https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64" || { |
| 152 | + echo "Error: Release binary not found!" |
| 153 | + echo "Expected URL: https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64" |
| 154 | + exit 1 |
| 155 | + } |
| 156 | +
|
| 157 | + - name: Commit and push to AUR |
| 158 | + working-directory: aur-curd |
| 159 | + run: | |
| 160 | + # Check if there are changes to commit |
| 161 | + if git diff --quiet && git diff --cached --quiet; then |
| 162 | + echo "No changes to commit" |
| 163 | + exit 0 |
| 164 | + fi |
| 165 | + |
| 166 | + # Add and commit changes |
| 167 | + git add PKGBUILD .SRCINFO |
| 168 | + git commit -m "Update to version ${{ steps.version.outputs.version }}" |
| 169 | + |
| 170 | + # Push with expect to handle passphrase |
| 171 | + expect -c " |
| 172 | + set timeout 60 |
| 173 | + spawn git push origin master |
| 174 | + expect { |
| 175 | + \"Enter passphrase*\" { |
| 176 | + send \"sex\r\" |
| 177 | + exp_continue |
| 178 | + } |
| 179 | + \"Everything up-to-date*\" { |
| 180 | + puts \"Nothing to push\" |
| 181 | + exit 0 |
| 182 | + } |
| 183 | + \"Permission denied*\" { |
| 184 | + puts \"ERROR: Permission denied during push\" |
| 185 | + exit 1 |
| 186 | + } |
| 187 | + eof { |
| 188 | + puts \"Push completed\" |
| 189 | + exit 0 |
| 190 | + } |
| 191 | + timeout { |
| 192 | + puts \"ERROR: Push timeout\" |
| 193 | + exit 1 |
| 194 | + } |
| 195 | + } |
| 196 | + " |
| 197 | +
|
| 198 | + - name: Cleanup |
| 199 | + if: always() |
| 200 | + run: | |
| 201 | + # Clean up SSH keys |
| 202 | + rm -f ~/.ssh/aur_rsa |
0 commit comments