name: Update AUR Package on: release: types: [published] workflow_dispatch: inputs: tag_name: description: 'Release tag name (e.g., v1.2.3)' required: true type: string jobs: update-aur: runs-on: ubuntu-latest if: github.repository == 'Wraient/curd' steps: - name: Checkout main repository uses: actions/checkout@v4 - name: Extract version from tag id: version run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then TAG_NAME="${{ github.event.inputs.tag_name }}" else TAG_NAME="${{ github.event.release.tag_name }}" fi VERSION=$(echo "$TAG_NAME" | sed 's/^v//') echo "version=$VERSION" >> $GITHUB_OUTPUT echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT echo "Extracted version: $VERSION" - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y expect git sshpass - name: Set up SSH for AUR env: SSH_PASSPHRASE: "sex" run: | mkdir -p ~/.ssh # Write the SSH key, ensuring proper formatting cat > ~/.ssh/aur_rsa << 'EOF' ${{ secrets.AUR_SSH_KEY }} EOF chmod 600 ~/.ssh/aur_rsa # Create SSH config for AUR cat > ~/.ssh/config << EOF Host aur.archlinux.org HostName aur.archlinux.org User aur IdentityFile ~/.ssh/aur_rsa StrictHostKeyChecking no IdentitiesOnly yes EOF # Add AUR host key to known_hosts ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts # Start SSH agent and add key with passphrase eval $(ssh-agent -s) echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV # Debug: Check key format echo "Checking SSH key format..." head -1 ~/.ssh/aur_rsa # Try alternative method using expect with better error handling expect -c " set timeout 20 log_user 1 spawn ssh-add ~/.ssh/aur_rsa expect { \"Enter passphrase*\" { send \"$env(SSH_PASSPHRASE)\r\" expect { \"Identity added*\" { puts \"SUCCESS: Key added to agent\" exit 0 } \"Bad passphrase*\" { puts \"ERROR: Bad passphrase\" exit 1 } timeout { puts \"ERROR: Timeout after entering passphrase\" exit 1 } } } \"*already loaded*\" { puts \"Key already loaded\" exit 0 } timeout { puts \"ERROR: Timeout waiting for passphrase prompt\" exit 1 } eof { puts \"Unexpected end of file\" exit 1 } } " || { echo "Expect failed, trying alternative method..." # Alternative: try with DISPLAY set to avoid GUI prompts DISPLAY=:0 SSH_ASKPASS_REQUIRE=never ssh-add ~/.ssh/aur_rsa 2>&1 || echo "Alternative method also failed" } # Verify key is loaded echo "Checking loaded keys:" ssh-add -l 2>&1 || echo "No keys in agent" # Test connection with verbose output for debugging echo "Testing SSH connection with verbose output:" ssh -vT aur@aur.archlinux.org 2>&1 | head -20 || echo "SSH test completed" - name: Clone AUR repository run: | # Debug: Check if SSH agent is running echo "SSH_AUTH_SOCK: $SSH_AUTH_SOCK" echo "SSH_AGENT_PID: $SSH_AGENT_PID" # Debug: List loaded keys echo "Keys currently loaded in SSH agent:" ssh-add -l 2>&1 || echo "No keys in agent or agent not accessible" # Debug: Test if key file exists and has correct permissions echo "Checking key file:" ls -la ~/.ssh/aur_rsa # Try to manually load the key again with debugging echo "Attempting to load key manually..." expect -c " set timeout 30 log_user 1 spawn ssh-add -v ~/.ssh/aur_rsa expect { \"Enter passphrase*\" { send \"sex\r\" expect { \"Identity added*\" { puts \"SUCCESS: Key loaded\" exit 0 } \"Bad passphrase*\" { puts \"ERROR: Bad passphrase\" exit 1 } timeout { puts \"ERROR: Timeout after passphrase\" exit 1 } } } \"*already loaded*\" { puts \"Key already loaded\" exit 0 } timeout { puts \"ERROR: No passphrase prompt\" exit 1 } eof } " || echo "Manual key loading failed" # Check again if key is loaded echo "Keys after manual loading attempt:" ssh-add -l 2>&1 || echo "Still no keys in agent" # Try direct SSH test with key file echo "Testing direct SSH connection..." ssh -o PasswordAuthentication=no -o IdentitiesOnly=yes -i ~/.ssh/aur_rsa -T aur@aur.archlinux.org 2>&1 | head -10 # Clone with verbose output echo "Attempting to clone with SSH debugging..." GIT_SSH_COMMAND="ssh -v -o IdentitiesOnly=yes -i ~/.ssh/aur_rsa" git clone ssh://aur@aur.archlinux.org/curd.git aur-curd - name: Update PKGBUILD working-directory: aur-curd run: | # Configure git git config user.name "Wraient" git config user.email "rushikeshwastaken@gmail.com" # Update pkgver in PKGBUILD sed -i "s/^pkgver=.*/pkgver=${{ steps.version.outputs.version }}/" PKGBUILD # Reset pkgrel to 1 for new version sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD # Update .SRCINFO makepkg --printsrcinfo > .SRCINFO echo "Updated PKGBUILD:" cat PKGBUILD - name: Verify release exists run: | # Check if the release and binary exist curl -f -L -I "https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64" || { echo "Error: Release binary not found!" echo "Expected URL: https://github.com/Wraient/curd/releases/download/${{ steps.version.outputs.tag_name }}/curd-linux-x86_64" exit 1 } - name: Commit and push to AUR working-directory: aur-curd run: | # Check if there are changes to commit if git diff --quiet && git diff --cached --quiet; then echo "No changes to commit" exit 0 fi # Add and commit changes git add PKGBUILD .SRCINFO git commit -m "Update to version ${{ steps.version.outputs.version }}" # Push changes (SSH agent should still have the key loaded) git push origin master - name: Cleanup if: always() run: | # Clean up SSH keys and kill SSH agent rm -f ~/.ssh/aur_rsa if [ -n "$SSH_AGENT_PID" ]; then kill $SSH_AGENT_PID 2>/dev/null || true fi