ee0be0a315
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3 to 4. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v3...v4) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
130 lines
4.2 KiB
YAML
130 lines
4.2 KiB
YAML
name: Docker Build
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master]
|
|
paths:
|
|
- "Dockerfile"
|
|
- ".dockerignore"
|
|
- "src/**/*.py"
|
|
- "pyproject.toml"
|
|
- ".github/workflows/docker.yaml"
|
|
tags:
|
|
- "v*"
|
|
pull_request:
|
|
branches: [main, master]
|
|
paths:
|
|
- "Dockerfile"
|
|
- ".dockerignore"
|
|
- "src/**/*.py"
|
|
- "pyproject.toml"
|
|
- ".github/workflows/docker.yaml"
|
|
|
|
# Cancel in-progress runs for the same branch
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Docker Image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Container Registry
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=sha,prefix=sha-
|
|
|
|
- name: Get version for setuptools-scm
|
|
id: version
|
|
run: |
|
|
# Get version from git describe (matches setuptools-scm behavior)
|
|
# For tagged releases: v1.0.0 -> 1.0.0
|
|
# For dev builds: v1.0.0-5-g1234567 -> 1.0.0.dev5+g1234567
|
|
if git describe --tags --exact-match 2>/dev/null; then
|
|
VERSION=$(git describe --tags --exact-match | sed 's/^v//')
|
|
else
|
|
# Get the latest tag or use 0.0.0 if none exists
|
|
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
BASE_VERSION=$(echo "$LATEST_TAG" | sed 's/^v//')
|
|
# Count commits since tag
|
|
COMMITS=$(git rev-list "${LATEST_TAG}..HEAD" --count 2>/dev/null || echo "0")
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
VERSION="${BASE_VERSION}.dev${COMMITS}+g${SHORT_SHA}"
|
|
fi
|
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "Detected version: $VERSION"
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
VERSION=${{ steps.version.outputs.VERSION }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Test Docker image
|
|
run: |
|
|
# Build for current platform only for testing
|
|
docker build --build-arg VERSION=${{ steps.version.outputs.VERSION }} -t freecad-mcp:test .
|
|
|
|
# Test that the container starts and responds to MCP initialize
|
|
echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | \
|
|
timeout 30 docker run --rm -i \
|
|
-e FREECAD_MODE=xmlrpc \
|
|
freecad-mcp:test 2>&1 | \
|
|
grep -q '"result"' && echo "Container test passed" || echo "Container test completed"
|
|
|
|
- name: Scan for vulnerabilities
|
|
if: github.event_name != 'pull_request'
|
|
uses: aquasecurity/trivy-action@master
|
|
with:
|
|
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
|
|
format: "sarif"
|
|
output: "trivy-results.sarif"
|
|
continue-on-error: true
|
|
|
|
- name: Upload Trivy scan results
|
|
if: github.event_name != 'pull_request'
|
|
uses: github/codeql-action/upload-sarif@v4
|
|
with:
|
|
sarif_file: "trivy-results.sarif"
|
|
continue-on-error: true
|