|
| 1 | +name: Test Secure Build Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - chore/secure-build-pipeline |
| 7 | + workflow_dispatch: {} # Allow manual triggering |
| 8 | + |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash |
| 12 | + |
| 13 | +env: |
| 14 | + GOPROXY: ${{ github.repository_owner == 'nginx' && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || github.ref_type == 'tag') && format('https://{0}:{1}@azr.artifactory.f5net.com/artifactory/api/go/f5-nginx-go-local-approved-dependency', secrets.ARTIFACTORY_USER, secrets.ARTIFACTORY_TOKEN) || github.repository_owner == 'nginx' && format('https://{0}:{1}@azr.artifactory.f5net.com/artifactory/api/go/f5-nginx-go-dev', secrets.ARTIFACTORY_USER, secrets.ARTIFACTORY_TOKEN) || 'direct' }} |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + test-production-conditions: |
| 21 | + name: Test Production Runner & Artifactory |
| 22 | + # Force production conditions by simulating a main branch push |
| 23 | + runs-on: ${{ github.repository_owner == 'nginx' && 'ubuntu-22.04-amd64' || 'ubuntu-24.04' }} |
| 24 | + steps: |
| 25 | + - name: Checkout Repository |
| 26 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 27 | + |
| 28 | + - name: Verify Runner Type |
| 29 | + run: | |
| 30 | + echo "🏃 Runner Information:" |
| 31 | + echo "Runner OS: $(uname -a)" |
| 32 | + echo "Runner Architecture: $(uname -m)" |
| 33 | + echo "Runner Name: $RUNNER_NAME" |
| 34 | + echo "Runner Environment: $RUNNER_ENVIRONMENT" |
| 35 | + echo "GitHub Repository Owner: ${{ github.repository_owner }}" |
| 36 | + echo "GitHub Event Name: ${{ github.event_name }}" |
| 37 | + echo "GitHub Ref: ${{ github.ref }}" |
| 38 | +
|
| 39 | + # Check if we're on a self-hosted runner |
| 40 | + if [[ "$RUNNER_NAME" == *"amd64"* ]] || [[ "$RUNNER_ENVIRONMENT" == "self-hosted" ]]; then |
| 41 | + echo "✅ SUCCESS: Running on self-hosted runner" |
| 42 | + else |
| 43 | + echo "ℹ️ INFO: Running on GitHub-hosted runner (expected for forks)" |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Test Production Artifactory Access |
| 47 | + run: | |
| 48 | + echo "🔐 Testing Artifactory Access:" |
| 49 | + echo "GOPROXY value: $GOPROXY" |
| 50 | +
|
| 51 | + # Force production artifactory URL for testing |
| 52 | + export TEST_GOPROXY="${{ github.repository_owner == 'nginx' && format('https://{0}:{1}@azr.artifactory.f5net.com/artifactory/api/go/f5-nginx-go-local-approved-dependency', secrets.ARTIFACTORY_USER, secrets.ARTIFACTORY_TOKEN) || 'direct' }}" |
| 53 | + echo "Test Production GOPROXY: $TEST_GOPROXY" |
| 54 | +
|
| 55 | + if [[ "$TEST_GOPROXY" == *"f5-nginx-go-local-approved-dependency"* ]]; then |
| 56 | + echo "✅ SUCCESS: Production artifactory URL configured" |
| 57 | + elif [[ "$TEST_GOPROXY" == "direct" ]]; then |
| 58 | + echo "ℹ️ INFO: Using direct proxy (expected for forks)" |
| 59 | + else |
| 60 | + echo "ℹ️ INFO: Using development artifactory" |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Setup Golang Environment |
| 64 | + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 |
| 65 | + with: |
| 66 | + go-version: stable |
| 67 | + cache-dependency-path: go.sum |
| 68 | + env: |
| 69 | + # Force production GOPROXY for this test |
| 70 | + GOPROXY: ${{ github.repository_owner == 'nginx' && format('https://{0}:{1}@azr.artifactory.f5net.com/artifactory/api/go/f5-nginx-go-local-approved-dependency', secrets.ARTIFACTORY_USER, secrets.ARTIFACTORY_TOKEN) || 'direct' }} |
| 71 | + |
| 72 | + - name: Test Go Module Resolution |
| 73 | + run: | |
| 74 | + echo "🧪 Testing Go Module Resolution:" |
| 75 | +
|
| 76 | + # Test basic Go functionality without modifying go.mod |
| 77 | + go version |
| 78 | + go env GOPROXY |
| 79 | +
|
| 80 | + # Verify we can list modules (read-only operation) |
| 81 | + echo "Current modules:" |
| 82 | + go list -m all | head -10 |
| 83 | +
|
| 84 | + # Test downloading a common dependency that should be in approved registry |
| 85 | + echo "Testing module download (read-only):" |
| 86 | + go mod download -x github.com/stretchr/testify |
| 87 | +
|
| 88 | + echo "✅ SUCCESS: Go module resolution working with configured proxy" |
| 89 | +
|
| 90 | + - name: Test Environment Variables |
| 91 | + run: | |
| 92 | + echo "🔧 Environment Test Results:" |
| 93 | + echo "Repository Owner: ${{ github.repository_owner }}" |
| 94 | + echo "Is NGINX repo: ${{ github.repository_owner == 'nginx' }}" |
| 95 | + echo "Event Name: ${{ github.event_name }}" |
| 96 | + echo "Ref: ${{ github.ref }}" |
| 97 | + echo "Ref Type: ${{ github.ref_type }}" |
| 98 | + echo "Branch: ${{ github.ref_name }}" |
| 99 | +
|
| 100 | + # Show what the actual conditions evaluate to |
| 101 | + echo "" |
| 102 | + echo "🎯 Condition Evaluations:" |
| 103 | + echo "Main branch push condition: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}" |
| 104 | + echo "Tag condition: ${{ github.ref_type == 'tag' }}" |
| 105 | + echo "Production condition: ${{ github.repository_owner == 'nginx' && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || github.ref_type == 'tag') }}" |
| 106 | + echo "Self-hosted runner condition: ${{ github.repository_owner == 'nginx' && (github.ref_type == 'tag' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) }}" |
| 107 | +
|
| 108 | + test-development-conditions: |
| 109 | + name: Test Development Configuration |
| 110 | + # This should use development artifactory and GitHub-hosted runners |
| 111 | + runs-on: ubuntu-24.04 |
| 112 | + steps: |
| 113 | + - name: Checkout Repository |
| 114 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 115 | + |
| 116 | + - name: Verify Development Configuration |
| 117 | + run: | |
| 118 | + echo "🧪 Testing Development Configuration:" |
| 119 | + echo "GOPROXY: $GOPROXY" |
| 120 | + echo "Runner: ubuntu-24.04 (GitHub-hosted)" |
| 121 | +
|
| 122 | + if [[ "$GOPROXY" == *"f5-nginx-go-dev"* ]]; then |
| 123 | + echo "✅ SUCCESS: Using development artifactory as expected" |
| 124 | + elif [[ "$GOPROXY" == "direct" ]]; then |
| 125 | + echo "ℹ️ INFO: Using direct proxy (expected for forks)" |
| 126 | + else |
| 127 | + echo "❌ UNEXPECTED: Not using expected development configuration" |
| 128 | + fi |
| 129 | +
|
| 130 | + - name: Setup Golang Environment |
| 131 | + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 |
| 132 | + with: |
| 133 | + go-version: stable |
| 134 | + cache-dependency-path: go.sum |
| 135 | + |
| 136 | + - name: Test Development Access |
| 137 | + run: | |
| 138 | + echo "🔧 Testing development Go proxy access:" |
| 139 | + go version |
| 140 | + go env GOPROXY |
| 141 | + go list -m all | head -5 |
| 142 | + echo "✅ SUCCESS: Development configuration working" |
| 143 | +
|
| 144 | + summary: |
| 145 | + name: Test Summary |
| 146 | + needs: [test-production-conditions, test-development-conditions] |
| 147 | + runs-on: ubuntu-24.04 |
| 148 | + if: always() |
| 149 | + steps: |
| 150 | + - name: Report Results |
| 151 | + run: | |
| 152 | + echo "🎉 Secure Build Pipeline Test Summary:" |
| 153 | + echo "==================================" |
| 154 | + echo "" |
| 155 | + echo "Production Test: ${{ needs.test-production-conditions.result }}" |
| 156 | + echo "Development Test: ${{ needs.test-development-conditions.result }}" |
| 157 | + echo "" |
| 158 | + echo "This test validates:" |
| 159 | + echo "✅ Self-hosted runner selection logic" |
| 160 | + echo "✅ GOPROXY artifactory configuration" |
| 161 | + echo "✅ Fork safety (repository_owner checks)" |
| 162 | + echo "✅ Environment-specific behavior" |
| 163 | + echo "" |
| 164 | + if [[ "${{ needs.test-production-conditions.result }}" == "success" ]] && [[ "${{ needs.test-development-conditions.result }}" == "success" ]]; then |
| 165 | + echo "🎯 ALL TESTS PASSED - Secure build pipeline ready!" |
| 166 | + else |
| 167 | + echo "❌ Some tests failed - check logs above" |
| 168 | + exit 1 |
| 169 | + fi |
0 commit comments