|
| 1 | +name: Post-Merge Build & Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-scan: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout Code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + # ------------------------------------------------------------ |
| 20 | + # 1. Python Setup |
| 21 | + # ------------------------------------------------------------ |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: '3.12' |
| 26 | + cache: 'pip' |
| 27 | + |
| 28 | + - name: Upgrade pip |
| 29 | + run: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | +
|
| 32 | + - name: Install Development Dependencies |
| 33 | + run: | |
| 34 | + python -m pip install -e '.[dev]' |
| 35 | +
|
| 36 | + # ------------------------------------------------------------ |
| 37 | + # 2. Python Validation |
| 38 | + # ------------------------------------------------------------ |
| 39 | + - name: Run Ruff Lint |
| 40 | + continue-on-error: true |
| 41 | + run: | |
| 42 | + ruff check . |
| 43 | +
|
| 44 | + - name: Run Unit Tests |
| 45 | + run: | |
| 46 | + pytest -q |
| 47 | +
|
| 48 | + - name: Run Release Checks |
| 49 | + run: | |
| 50 | + python scripts/check_release.py |
| 51 | +
|
| 52 | + # ------------------------------------------------------------ |
| 53 | + # 3. Build Python Package |
| 54 | + # ------------------------------------------------------------ |
| 55 | + - name: Build Python Package |
| 56 | + run: | |
| 57 | + python -m build |
| 58 | +
|
| 59 | + - name: List Python Build Artifacts |
| 60 | + run: | |
| 61 | + ls -lh dist/ |
| 62 | +
|
| 63 | + # ------------------------------------------------------------ |
| 64 | + # 4. Docker Build |
| 65 | + # ------------------------------------------------------------ |
| 66 | + - name: Set up Docker Buildx |
| 67 | + uses: docker/setup-buildx-action@v3 |
| 68 | + |
| 69 | + - name: Build Docker Image Locally |
| 70 | + uses: docker/build-push-action@v6 |
| 71 | + with: |
| 72 | + context: . |
| 73 | + file: docker/Dockerfile |
| 74 | + load: true |
| 75 | + push: false |
| 76 | + tags: salt-cli-api:local |
| 77 | + build-args: | |
| 78 | + PIP_INDEX_URL=https://pypi.org/simple |
| 79 | + cache-from: type=gha,scope=raas-cli |
| 80 | + cache-to: type=gha,mode=max,scope=raas-cli |
| 81 | + |
| 82 | + # ------------------------------------------------------------ |
| 83 | + # 5. Security Scan |
| 84 | + # ------------------------------------------------------------ |
| 85 | + - name: Run Trivy Vulnerability Scan |
| 86 | + uses: aquasecurity/trivy-action@v0.36.0 |
| 87 | + with: |
| 88 | + image-ref: 'salt-cli-api:local' |
| 89 | + format: 'table' |
| 90 | + exit-code: '0' |
| 91 | + ignore-unfixed: true |
| 92 | + vuln-type: 'os,library' |
| 93 | + severity: 'HIGH,CRITICAL' |
| 94 | + |
| 95 | + - name: Show Docker Image |
| 96 | + run: | |
| 97 | + docker images salt-cli-api |
0 commit comments