|
| 1 | +name: PDP CI Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: [master, main, v*] |
| 7 | + workflow_call: |
| 8 | + secrets: |
| 9 | + PDP_TESTER_API_KEY: |
| 10 | + required: true |
| 11 | + CLONE_REPO_TOKEN: |
| 12 | + required: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + pre-commit: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + - uses: actions/setup-python@v3 |
| 20 | + - uses: pre-commit/[email protected] |
| 21 | + |
| 22 | + pytests: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Python setup |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: '3.11.8' |
| 29 | + |
| 30 | + - name: Checkout code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Run Pytests |
| 34 | + run: | |
| 35 | + python -m pip install --upgrade pip |
| 36 | + pip install ".[dev]" |
| 37 | + pytest -s --cache-clear horizon/tests/ |
| 38 | +
|
| 39 | + pdp-tester: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Checkout code |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + repository: permitio/permit-opa |
| 48 | + ref: main |
| 49 | + path: './permit-opa' |
| 50 | + token: ${{ secrets.CLONE_REPO_TOKEN }} |
| 51 | + |
| 52 | + - name: Set up QEMU |
| 53 | + uses: docker/setup-qemu-action@v3 |
| 54 | + |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@v3 |
| 57 | + |
| 58 | + - name: Pre build PDP tests |
| 59 | + run: | |
| 60 | + echo "next" > permit_pdp_version |
| 61 | + rm -rf custom |
| 62 | + mkdir custom |
| 63 | + build_root="$PWD" |
| 64 | + cd ./permit-opa |
| 65 | + find * \( -name '*go*' -o -name 'LICENSE.md' \) -print0 | xargs -0 tar -czf "$build_root"/custom/custom_opa.tar.gz --exclude '.*' |
| 66 | +
|
| 67 | + - name: Build and load PDP Docker image |
| 68 | + uses: docker/build-push-action@v5 |
| 69 | + with: |
| 70 | + push: false |
| 71 | + load: true |
| 72 | + context: . |
| 73 | + platforms: linux/amd64 |
| 74 | + tags: permitio/pdp-v2:next |
| 75 | + cache-from: type=gha |
| 76 | + cache-to: type=gha,mode=max |
| 77 | + |
| 78 | + # Checkout the pdp-tester repository |
| 79 | + - name: Checkout pdp-tester repository |
| 80 | + uses: actions/checkout@v3 |
| 81 | + with: |
| 82 | + repository: "permitio/pdp-tester" |
| 83 | + token: ${{ secrets.CLONE_REPO_TOKEN }} |
| 84 | + path: './pdp-tester' |
| 85 | + |
| 86 | + # Setup Python environment |
| 87 | + - name: Setup Python |
| 88 | + uses: actions/setup-python@v3 |
| 89 | + with: |
| 90 | + python-version: "3.12" |
| 91 | + |
| 92 | + # Install dependencies for pdp-tester |
| 93 | + - name: Install pdp-tester dependencies |
| 94 | + working-directory: ./pdp-tester |
| 95 | + run: | |
| 96 | + pip install -r requirements.txt |
| 97 | +
|
| 98 | + # Run pdp-tester |
| 99 | + - name: Run pdp-tester |
| 100 | + working-directory: ./pdp-tester |
| 101 | + env: |
| 102 | + TOKEN: ${{ secrets.PDP_TESTER_API_KEY }} |
| 103 | + LOCAL_TAGS: '["next"]' |
| 104 | + INCLUDE_TAGS: '[]' |
| 105 | + AUTO_REMOVE: "False" |
| 106 | + SKIP_GENERATE: "True" |
| 107 | + ENABLE_APM: "False" |
| 108 | + run: | |
| 109 | + python -m pdp_tester.main |
| 110 | +
|
| 111 | + - name: Print Docker container logs |
| 112 | + if: always() |
| 113 | + run: | |
| 114 | + echo "Fetching logs for all Docker containers..." |
| 115 | + for container in $(docker ps -aq); do |
| 116 | + echo "========================================" |
| 117 | + echo "Logs for container: $container" |
| 118 | + echo "----------------------------------------" |
| 119 | + docker logs "$container" || true |
| 120 | + echo "========================================" |
| 121 | + echo "" |
| 122 | + done |
0 commit comments