Commit 73ba7bd488
Unsigned
Layout: unified · split
.github/workflows/update-aur.yml +76 −188
| @@ -10,227 +10,115 @@ on: | |||
| 10 | required: true | 10 | required: true |
| 11 | type: string | 11 | type: string |
| 12 | 12 | ||
| 13 | permissions: | ||
| 14 | contents: read | ||
| 15 | |||
| 13 | jobs: | 16 | jobs: |
| 14 | update-aur: | 17 | update-aur: |
| 15 | runs-on: ubuntu-latest | 18 | runs-on: ubuntu-24.04 |
| 16 | if: github.repository == 'Wraient/curd' | 19 | if: github.repository == 'Wraient/curd' |
| 17 | 20 | ||
| 18 | steps: | 21 | steps: |
| 19 | - name: Checkout main repository | 22 | - name: Install dependencies |
| 20 | uses: actions/checkout@v4 | 23 | run: | |
| 24 | sudo apt-get update | ||
| 25 | sudo apt-get install -y curl git openssh-client makepkg | ||
| 21 | 26 | ||
| 22 | - name: Extract version from tag | 27 | - name: Resolve release version and checksum |
| 23 | id: version | 28 | id: release |
| 24 | run: | | 29 | run: | |
| 30 | set -euo pipefail | ||
| 31 | |||
| 25 | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | 32 | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 26 | TAG_NAME="${{ github.event.inputs.tag_name }}" | 33 | TAG_NAME="${{ github.event.inputs.tag_name }}" |
| 27 | else | 34 | else |
| 28 | TAG_NAME="${{ github.event.release.tag_name }}" | 35 | TAG_NAME="${{ github.event.release.tag_name }}" |
| 29 | fi | 36 | 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 | 37 | ||
| 35 | - name: Install dependencies | 38 | if [ -z "$TAG_NAME" ]; then |
| 36 | run: | | 39 | echo "Release tag is empty" |
| 37 | sudo apt-get update | 40 | exit 1 |
| 38 | sudo apt-get install -y expect git sshpass | 41 | fi |
| 42 | |||
| 43 | VERSION="${TAG_NAME#v}" | ||
| 44 | ASSET_URL="https://github.com/Wraient/curd/releases/download/${TAG_NAME}/curd-linux-x86_64" | ||
| 45 | |||
| 46 | TMP_ASSET="$(mktemp)" | ||
| 47 | curl -fL --retry 3 --retry-all-errors --connect-timeout 20 "$ASSET_URL" -o "$TMP_ASSET" | ||
| 48 | SHA256="$(sha256sum "$TMP_ASSET" | awk '{print $1}')" | ||
| 49 | rm -f "$TMP_ASSET" | ||
| 39 | 50 | ||
| 40 | - name: Set up SSH for AUR | 51 | echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 52 | echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT" | ||
| 53 | echo "sha256=$SHA256" >> "$GITHUB_OUTPUT" | ||
| 54 | |||
| 55 | - name: Configure SSH for AUR | ||
| 41 | env: | 56 | env: |
| 42 | SSH_PASSPHRASE: "sex" | 57 | AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY || secrets.AUR_SSH_KEY }} |
| 43 | run: | | 58 | run: | |
| 44 | mkdir -p ~/.ssh | 59 | set -euo pipefail |
| 45 | # Write the SSH key, ensuring proper formatting | 60 | |
| 46 | cat > ~/.ssh/aur_rsa << 'EOF' | 61 | if [ -z "${AUR_SSH_PRIVATE_KEY:-}" ]; then |
| 47 | ${{ secrets.AUR_SSH_KEY }} | 62 | echo "Missing secret: AUR_SSH_PRIVATE_KEY (or AUR_SSH_KEY)" |
| 48 | EOF | 63 | exit 1 |
| 49 | chmod 600 ~/.ssh/aur_rsa | 64 | fi |
| 50 | 65 | ||
| 51 | # Create SSH config for AUR | 66 | install -m 700 -d ~/.ssh |
| 52 | cat > ~/.ssh/config << EOF | 67 | printf '%s\n' "$AUR_SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/aur_deploy |
| 53 | Host aur.archlinux.org | 68 | |
| 54 | HostName aur.archlinux.org | 69 | if [ ! -s ~/.ssh/aur_deploy ]; then |
| 55 | User aur | 70 | echo "SSH key file is empty after writing secret" |
| 56 | IdentityFile ~/.ssh/aur_rsa | 71 | exit 1 |
| 57 | StrictHostKeyChecking no | 72 | fi |
| 58 | IdentitiesOnly yes | 73 | |
| 59 | EOF | 74 | if ! ssh-keygen -y -f ~/.ssh/aur_deploy >/dev/null 2>&1; then |
| 60 | 75 | echo "Invalid SSH private key in secret (or key is passphrase-protected)" | |
| 61 | # Add AUR host key to known_hosts | 76 | exit 1 |
| 77 | fi | ||
| 78 | |||
| 79 | chmod 600 ~/.ssh/aur_deploy | ||
| 62 | ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts | 80 | ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts |
| 63 | 81 | chmod 644 ~/.ssh/known_hosts | |
| 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 | 82 | ||
| 123 | - name: Clone AUR repository | 83 | - name: Clone AUR repository |
| 84 | env: | ||
| 85 | GIT_SSH_COMMAND: ssh -i ~/.ssh/aur_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes | ||
| 124 | run: | | 86 | run: | |
| 125 | # Debug: Check if SSH agent is running | 87 | set -euo pipefail |
| 126 | echo "SSH_AUTH_SOCK: $SSH_AUTH_SOCK" | 88 | git clone --depth 1 ssh://aur@aur.archlinux.org/curd.git aur-curd |
| 127 | echo "SSH_AGENT_PID: $SSH_AGENT_PID" | 89 | |
| 128 | 90 | - name: Update AUR package files | |
| 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 | 91 | working-directory: aur-curd |
| 187 | run: | | 92 | run: | |
| 188 | # Configure git | 93 | set -euo pipefail |
| 189 | git config user.name "Wraient" | 94 | |
| 190 | git config user.email "rushikeshwastaken@gmail.com" | 95 | sed -i "s/^pkgver=.*/pkgver=${{ steps.release.outputs.version }}/" PKGBUILD |
| 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 | 96 | sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD |
| 197 | 97 | sed -i "s|^source=.*|source=(\"https://github.com/Wraient/curd/releases/download/v\${pkgver}/curd-linux-x86_64\")|" PKGBUILD | |
| 198 | # Update .SRCINFO | 98 | sed -i "s|^sha256sums=.*|sha256sums=('${{ steps.release.outputs.sha256 }}')|" PKGBUILD |
| 199 | makepkg --printsrcinfo > .SRCINFO | ||
| 200 | |||
| 201 | echo "Updated PKGBUILD:" | ||
| 202 | cat PKGBUILD | ||
| 203 | 99 | ||
| 204 | - name: Verify release exists | 100 | makepkg --printsrcinfo > .SRCINFO |
| 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 | 101 | ||
| 213 | - name: Commit and push to AUR | 102 | - name: Commit and push to AUR |
| 214 | working-directory: aur-curd | 103 | working-directory: aur-curd |
| 104 | env: | ||
| 105 | GIT_SSH_COMMAND: ssh -i ~/.ssh/aur_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes | ||
| 215 | run: | | 106 | run: | |
| 216 | # Check if there are changes to commit | 107 | set -euo pipefail |
| 217 | if git diff --quiet && git diff --cached --quiet; then | 108 | |
| 109 | git config user.name "github-actions[bot]" | ||
| 110 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| 111 | |||
| 112 | if git diff --quiet; then | ||
| 218 | echo "No changes to commit" | 113 | echo "No changes to commit" |
| 219 | exit 0 | 114 | exit 0 |
| 220 | fi | 115 | fi |
| 221 | 116 | ||
| 222 | # Add and commit changes | ||
| 223 | git add PKGBUILD .SRCINFO | 117 | git add PKGBUILD .SRCINFO |
| 224 | git commit -m "Update to version ${{ steps.version.outputs.version }}" | 118 | git commit -m "Update to version ${{ steps.release.outputs.version }}" |
| 225 | 119 | git push origin HEAD:master | |
| 226 | # Push changes (SSH agent should still have the key loaded) | ||
| 227 | git push origin master | ||
| 228 | 120 | ||
| 229 | - name: Cleanup | 121 | - name: Cleanup |
| 230 | if: always() | 122 | if: always() |
| 231 | run: | | 123 | run: | |
| 232 | # Clean up SSH keys and kill SSH agent | 124 | rm -f ~/.ssh/aur_deploy |
| 233 | rm -f ~/.ssh/aur_rsa | ||
| 234 | if [ -n "$SSH_AGENT_PID" ]; then | ||
| 235 | kill $SSH_AGENT_PID 2>/dev/null || true | ||
| 236 | fi | ||