|
| 1 | +name: Publish Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - pyproject.toml |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + version: |
| 12 | + description: 'Version to publish' |
| 13 | + required: false |
| 14 | + default: 'latest' |
| 15 | + type: string |
| 16 | + |
| 17 | +jobs: |
| 18 | + push_to_registry: |
| 19 | + name: Push Docker image to GitHub Packages |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read # required for actions/checkout |
| 23 | + packages: write # required for pushing to ghcr.io |
| 24 | + steps: |
| 25 | + - name: Check out the repo |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Setup python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: '3.10' |
| 32 | + cache: 'poetry' |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: poetry install |
| 36 | + |
| 37 | + - name: Install uv |
| 38 | + uses: astral-sh/setup-uv@v5 |
| 39 | + with: |
| 40 | + version: "0.7.17" |
| 41 | + |
| 42 | + - name: Download dependencies |
| 43 | + run: | |
| 44 | + uv sync |
| 45 | +
|
| 46 | + - name: Run ruff |
| 47 | + run: | |
| 48 | + uvx ruff check --fix --config ruff.toml |
| 49 | +
|
| 50 | + - name: Run Unit Tests |
| 51 | + run: | |
| 52 | + uv run pytest --capture=tee-sys --junitxml=pytest.xml |
| 53 | +
|
| 54 | + - name: Run Test Coverage |
| 55 | + run: | |
| 56 | + uv run pytest --cov=. --cov-report=xml |
| 57 | +
|
| 58 | + - name: Extract version |
| 59 | + id: extract_version |
| 60 | + run: | |
| 61 | + VERSION=$(grep 'version =' pyproject.toml | sed -e 's/version = "\(.*\)"/\1/')-$(echo $GITHUB_SHA | cut -c1-7) |
| 62 | + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: Log in to GitHub Container Registry |
| 65 | + uses: docker/login-action@v3 |
| 66 | + with: |
| 67 | + registry: ghcr.io |
| 68 | + username: ${{ github.actor }} |
| 69 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + - name: Build and push Docker image |
| 72 | + uses: docker/build-push-action@v5 |
| 73 | + with: |
| 74 | + context: . |
| 75 | + push: true |
| 76 | + tags: | |
| 77 | + ghcr.io/sysdiglabs/sysdig-mcp-server:latest |
| 78 | + ghcr.io/sysdiglabs/sysdig-mcp-server:v${{ steps.extract_version.outputs.VERSION }} |
| 79 | +
|
| 80 | + - name: "Check test reports exists" |
| 81 | + if: always() |
| 82 | + id: check-test-results-exists |
| 83 | + uses: andstor/file-existence-action@v3 |
| 84 | + with: |
| 85 | + files: "pytest.xml, coverage.xml" |
| 86 | + |
| 87 | + - name: Create pack-wise pytest report |
| 88 | + run: poetry run python .github/github_workflow_scripts/parse_junit_per_pack.py |
| 89 | + if: | |
| 90 | + always() && |
| 91 | + steps.check-test-results-exists.outputs.files_exists == 'true' && |
| 92 | + github.event.pull_request.head.repo.fork == false |
| 93 | +
|
| 94 | + - name: Upload junit & pack-wise pytest report |
| 95 | + uses: PaloAltoNetworks/upload-secure-artifact@v1.0.5 |
| 96 | + if: | |
| 97 | + always() && |
| 98 | + steps.check-test-results-exists.outputs.files_exists == 'true' && |
| 99 | + github.event.pull_request.head.repo.fork == false |
| 100 | + with: |
| 101 | + name: pytest |
| 102 | + path: | |
| 103 | + coverage.xml |
| 104 | + if-no-files-found: error |
| 105 | + |
| 106 | + - name: Pytest coverage comment |
| 107 | + if: | |
| 108 | + always() && |
| 109 | + steps.check-test-results-exists.outputs.files_exists == 'true' && |
| 110 | + steps.check-test-results-exists.outputs.files_exists == 'true' && |
| 111 | + ! github.event.pull_request.head.repo.fork |
| 112 | + uses: MishaKav/pytest-coverage-comment@v1.1.54 |
| 113 | + continue-on-error: true # may fail on output > 65k chars |
| 114 | + with: |
| 115 | + pytest-xml-coverage-path: coverage.xml |
| 116 | + junitxml-path: coverage.xml |
0 commit comments