Created
November 9, 2025 07:09
-
-
Save pattihis/a6a67b139c4f80c28e488ac565140bd4 to your computer and use it in GitHub Desktop.
.github/workflows/test-deployment-connectivity.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Deployment Connectivity | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - test-deploy | |
| jobs: | |
| test-connectivity: | |
| name: Test SSH to ${{ matrix.server }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - server: "Test VPS 1" | |
| host: "101.99.80.16" | |
| port: "20203" | |
| user: "root" | |
| password: "XXXXXXXXXX" | |
| - server: "Test VPS 2" | |
| host: "101.99.93.18" | |
| port: "20200" | |
| user: "root" | |
| password: "XXXXXXXXXX" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get GitHub Actions runner IP | |
| run: | | |
| RUNNER_IP=$(curl -s --max-time 10 https://api.ipify.org || echo "unknown") | |
| echo "==========================================" | |
| echo "π GitHub Actions Runner Information" | |
| echo "==========================================" | |
| echo "Runner IP: $RUNNER_IP" | |
| echo "Target: ${{ matrix.host }}:${{ matrix.port }}" | |
| echo "User: ${{ matrix.user }}" | |
| echo "Server: ${{ matrix.server }}" | |
| echo "==========================================" | |
| echo "" | |
| - name: Test basic connectivity (ping/traceroute) | |
| continue-on-error: true | |
| run: | | |
| echo "==========================================" | |
| echo "π Network Connectivity Test" | |
| echo "==========================================" | |
| echo "" | |
| echo "Testing ping to ${{ matrix.host }}..." | |
| ping -c 4 ${{ matrix.host }} || echo "β οΈ Ping failed or blocked" | |
| echo "" | |
| echo "Testing traceroute to ${{ matrix.host }}..." | |
| traceroute -m 15 -w 2 ${{ matrix.host }} || echo "β οΈ Traceroute failed" | |
| echo "" | |
| echo "Testing port connectivity with nc (netcat)..." | |
| timeout 10 nc -zv ${{ matrix.host }} ${{ matrix.port }} 2>&1 || echo "β οΈ Port test failed" | |
| echo "" | |
| echo "Testing port connectivity with telnet..." | |
| timeout 10 bash -c "echo 'QUIT' | telnet ${{ matrix.host }} ${{ matrix.port }}" 2>&1 || echo "β οΈ Telnet test failed" | |
| echo "" | |
| - name: Install sshpass for password authentication | |
| run: | | |
| echo "Installing sshpass for password authentication..." | |
| sudo apt-get update -qq | |
| sudo apt-get install -y sshpass | |
| - name: Test SSH connection with verbose output | |
| run: | | |
| echo "==========================================" | |
| echo "π SSH Connection Test (Verbose)" | |
| echo "==========================================" | |
| echo "" | |
| echo "Attempting SSH connection to ${{ matrix.host }}:${{ matrix.port }}..." | |
| echo "User: ${{ matrix.user }}" | |
| echo "Password: ${{ matrix.password }}" | |
| echo "" | |
| # Test SSH with verbose output | |
| sshpass -p "${{ matrix.password }}" ssh -v \ | |
| -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| -o ConnectTimeout=30 \ | |
| -p ${{ matrix.port }} \ | |
| ${{ matrix.user }}@${{ matrix.host }} \ | |
| "echo 'β SSH CONNECTION SUCCESSFUL!' && hostname && whoami && uptime" 2>&1 || { | |
| echo "" | |
| echo "==========================================" | |
| echo "β SSH CONNECTION FAILED" | |
| echo "==========================================" | |
| echo "This could be due to:" | |
| echo "1. Cloud firewall blocking GitHub Actions IP" | |
| echo "2. SSH service not running" | |
| echo "3. Wrong credentials" | |
| echo "4. Port not accessible" | |
| echo "==========================================" | |
| exit 1 | |
| } | |
| - name: Generate connection info file | |
| run: | | |
| RUNNER_IP=$(curl -s --max-time 10 https://api.ipify.org || echo "unknown") | |
| TIMESTAMP=$(date -u '+%Y-%m-%d %H:%M:%S UTC') | |
| echo "==========================================" > connection-info.txt | |
| echo "GitHub Actions Deployment Test" >> connection-info.txt | |
| echo "==========================================" >> connection-info.txt | |
| echo "" >> connection-info.txt | |
| echo "Deployment Information:" >> connection-info.txt | |
| echo "-----------------------" >> connection-info.txt | |
| echo "Timestamp: $TIMESTAMP" >> connection-info.txt | |
| echo "GitHub Runner IP: $RUNNER_IP" >> connection-info.txt | |
| echo "Target Server: ${{ matrix.server }}" >> connection-info.txt | |
| echo "Target Host: ${{ matrix.host }}" >> connection-info.txt | |
| echo "Target Port: ${{ matrix.port }}" >> connection-info.txt | |
| echo "GitHub Workflow: ${{ github.workflow }}" >> connection-info.txt | |
| echo "GitHub Run ID: ${{ github.run_id }}" >> connection-info.txt | |
| echo "GitHub Actor: ${{ github.actor }}" >> connection-info.txt | |
| echo "" >> connection-info.txt | |
| echo "Connection Test:" >> connection-info.txt | |
| echo "-----------------------" >> connection-info.txt | |
| echo "Traceroute from GitHub Runner to ${{ matrix.host }}:" >> connection-info.txt | |
| traceroute -m 15 -w 2 ${{ matrix.host }} >> connection-info.txt 2>&1 || echo "Traceroute not available" >> connection-info.txt | |
| echo "" >> connection-info.txt | |
| echo "==========================================" >> connection-info.txt | |
| echo "Server Information:" >> connection-info.txt | |
| sshpass -p "${{ matrix.password }}" ssh \ | |
| -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| -o ConnectTimeout=30 \ | |
| -p ${{ matrix.port }} \ | |
| ${{ matrix.user }}@${{ matrix.host }} \ | |
| "echo 'Hostname: '\$(hostname) && echo 'Uptime: '\$(uptime) && echo 'IP Address: '\$(hostname -I) && echo 'Kernel: '\$(uname -r)" >> connection-info.txt 2>&1 | |
| echo "========================================" >> connection-info.txt | |
| echo "" | |
| echo "==========================================" | |
| echo "π Generated Connection Info File:" | |
| echo "==========================================" | |
| cat connection-info.txt | |
| - name: Deploy connection info file to server | |
| run: | | |
| echo "==========================================" | |
| echo "π€ Deploying connection-info.txt to server" | |
| echo "==========================================" | |
| echo "" | |
| # Create remote directory and upload file | |
| sshpass -p "${{ matrix.password }}" ssh \ | |
| -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| -o ConnectTimeout=30 \ | |
| -p ${{ matrix.port }} \ | |
| ${{ matrix.user }}@${{ matrix.host }} \ | |
| "mkdir -p /root/github-deployment-tests" | |
| sshpass -p "${{ matrix.password }}" scp \ | |
| -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| -o ConnectTimeout=30 \ | |
| -P ${{ matrix.port }} \ | |
| connection-info.txt \ | |
| ${{ matrix.user }}@${{ matrix.host }}:/root/github-deployment-tests/connection-info-$(date +%Y%m%d-%H%M%S).txt | |
| echo "" | |
| echo "β File deployed successfully!" | |
| echo "" | |
| echo "Verifying deployment..." | |
| sshpass -p "${{ matrix.password }}" ssh \ | |
| -o StrictHostKeyChecking=no \ | |
| -o UserKnownHostsFile=/dev/null \ | |
| -o ConnectTimeout=30 \ | |
| -p ${{ matrix.port }} \ | |
| ${{ matrix.user }}@${{ matrix.host }} \ | |
| "ls -lah /root/github-deployment-tests/ && echo '' && echo 'Latest file content:' && cat \$(ls -t /root/github-deployment-tests/*.txt | head -1)" | |
| - name: Test deployment summary | |
| if: always() | |
| run: | | |
| echo "" | |
| echo "==========================================" | |
| echo "π Deployment Test Summary" | |
| echo "==========================================" | |
| echo "Server: ${{ matrix.server }}" | |
| echo "Host: ${{ matrix.host }}:${{ matrix.port }}" | |
| echo "Status: ${{ job.status }}" | |
| echo "==========================================" | |
| if [ "${{ job.status }}" == "success" ]; then | |
| echo "β All tests passed!" | |
| echo "" | |
| echo "Next steps:" | |
| echo "1. Check the deployed file on the server:" | |
| echo " ssh -p ${{ matrix.port }} ${{ matrix.user }}@${{ matrix.host }}" | |
| echo " ls -la /root/github-deployment-tests/" | |
| echo "" | |
| echo "2. The connection from GitHub Actions is working!" | |
| echo "3. You can now use this server for actual deployments." | |
| else | |
| echo "β Some tests failed!" | |
| echo "" | |
| echo "Troubleshooting:" | |
| echo "1. Check if cloud firewall allows GitHub Actions IPs" | |
| echo "2. Verify SSH service is running on the server" | |
| echo "3. Confirm credentials are correct" | |
| echo "4. Check if port ${{ matrix.port }} is open" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment