55 branches :
66 - main
77 tags :
8- - ' v* '
8+ - " v* "
99
1010env :
1111 REGISTRY : ghcr.io
@@ -23,103 +23,106 @@ jobs:
2323 image-version : ${{ steps.meta.outputs.version }}
2424
2525 steps :
26- - name : Checkout repository
27- uses : actions/checkout@v4
28-
29- - name : Validate version tag
30- if : startsWith(github.ref, 'refs/tags/v')
31- run : |
32- # Extract version from tag (e.g., v0.1.0 -> 0.1.0)
33- TAG_VERSION=${GITHUB_REF#refs/tags/v}
34- echo "Tag version: $TAG_VERSION"
35-
36- # Extract version from pyproject.toml
37- PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
38- echo "pyproject.toml version: $PYPROJECT_VERSION"
39-
40- # Compare versions
41- if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
42- echo "::error::Version mismatch! Tag version ($TAG_VERSION) doesn't match pyproject.toml version ($PYPROJECT_VERSION)"
43- exit 1
44- fi
45-
46- echo "::notice::Version validation passed: $TAG_VERSION"
47-
48- - name : Set up Docker Buildx
49- uses : docker/setup-buildx-action@v3
50-
51- - name : Log in to Container Registry
52- if : github.event_name != 'pull_request'
53- uses : docker/login-action@v3
54- with :
55- registry : ${{ env.REGISTRY }}
56- username : ${{ github.actor }}
57- password : ${{ secrets.GITHUB_TOKEN }}
58-
59- - name : Extract metadata (tags, labels) for Docker
60- id : meta
61- uses : docker/metadata-action@v5
62- with :
63- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
64- tags : |
65- type=ref,event=branch
66- type=ref,event=pr
67- type=semver,pattern={{version}}
68- type=semver,pattern={{major}}.{{minor}}
69- type=semver,pattern={{major}}
70- type=raw,value=latest,enable={{is_default_branch}}
71-
72- - name : Build and push Docker image
73- id : build
74- uses : docker/build-push-action@v5
75- with :
76- context : .
77- file : ./Dockerfile
78- platforms : linux/amd64,linux/arm64
79- push : ${{ github.event_name != 'pull_request' }}
80- tags : ${{ steps.meta.outputs.tags }}
81- labels : ${{ steps.meta.outputs.labels }}
82- cache-from : type=gha
83- cache-to : type=gha,mode=max
84- build-args : |
85- BUILDKIT_INLINE_CACHE=1
86-
87- - name : Determine scan tag
88- id : scan-tag
89- if : github.event_name != 'pull_request'
90- run : |
91- # Lowercase the image name (Docker registries require lowercase)
92- IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
93-
94- # Use the version tag if this is a tag push, otherwise use latest
95- if [[ "${{ github.ref }}" == refs/tags/* ]]; then
96- TAG="${GITHUB_REF#refs/tags/}"
97- SCAN_TAG="${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${TAG#v}"
98- else
99- SCAN_TAG="${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:latest"
100- fi
101- echo "tag=$SCAN_TAG" >> $GITHUB_OUTPUT
102- echo "Scanning image: $SCAN_TAG"
103-
104- - name : Run security scan on image
105- if : github.event_name != 'pull_request'
106- uses : aquasecurity/trivy-action@master
107- with :
108- image-ref : ${{ steps.scan-tag.outputs.tag }}
109- format : ' sarif'
110- output : ' trivy-results.sarif'
111-
112- - name : Upload Trivy scan results to GitHub Security tab
113- if : github.event_name != 'pull_request'
114- uses : github/codeql-action/upload-sarif@v3
115- with :
116- sarif_file : ' trivy-results.sarif'
117-
118- - name : Generate build summary
119- if : github.event_name != 'pull_request'
120- run : |
121- echo "## Docker Build Summary" >> $GITHUB_STEP_SUMMARY
122- echo "- **Image**: \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
123- echo "- **Tags**: \`${{ steps.meta.outputs.tags }}\`" >> $GITHUB_STEP_SUMMARY
124- echo "- **Platforms**: \`linux/amd64, linux/arm64\`" >> $GITHUB_STEP_SUMMARY
125- echo "- **Registry**: \`${{ env.REGISTRY }}\`" >> $GITHUB_STEP_SUMMARY
26+ - name : Checkout repository
27+ uses : actions/checkout@v4
28+
29+ - name : Validate version tag
30+ if : startsWith(github.ref, 'refs/tags/v')
31+ run : |
32+ # Extract version from tag (e.g., v0.1.0 -> 0.1.0)
33+ TAG_VERSION=${GITHUB_REF#refs/tags/v}
34+ echo "Tag version: $TAG_VERSION"
35+
36+ # Extract version from pyproject.toml
37+ PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
38+ echo "pyproject.toml version: $PYPROJECT_VERSION"
39+
40+ # Compare versions
41+ if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
42+ echo "::error::Version mismatch! Tag version ($TAG_VERSION) doesn't match pyproject.toml version ($PYPROJECT_VERSION)"
43+ exit 1
44+ fi
45+
46+ echo "::notice::Version validation passed: $TAG_VERSION"
47+
48+ - name : Set up Docker Buildx
49+ uses : docker/setup-buildx-action@v3
50+
51+ - name : Log in to Container Registry
52+ if : github.event_name != 'pull_request'
53+ uses : docker/login-action@v3
54+ with :
55+ registry : ${{ env.REGISTRY }}
56+ username : ${{ github.actor }}
57+ password : ${{ secrets.GITHUB_TOKEN }}
58+
59+ - name : Extract metadata (tags, labels) for Docker
60+ id : meta
61+ uses : docker/metadata-action@v5
62+ with :
63+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
64+ flavor : |
65+ latest=false
66+ tags : |
67+ type=ref,event=branch
68+ type=ref,event=pr
69+ type=semver,pattern={{version}}
70+ type=semver,pattern={{major}}.{{minor}}
71+ type=semver,pattern={{major}}
72+ type=raw,value=edge,enable={{is_default_branch}}
73+ type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
74+
75+ - name : Build and push Docker image
76+ id : build
77+ uses : docker/build-push-action@v5
78+ with :
79+ context : .
80+ file : ./Dockerfile
81+ platforms : linux/amd64,linux/arm64
82+ push : ${{ github.event_name != 'pull_request' }}
83+ tags : ${{ steps.meta.outputs.tags }}
84+ labels : ${{ steps.meta.outputs.labels }}
85+ cache-from : type=gha
86+ cache-to : type=gha,mode=max
87+ build-args : |
88+ BUILDKIT_INLINE_CACHE=1
89+
90+ - name : Determine scan tag
91+ id : scan-tag
92+ if : github.event_name != 'pull_request'
93+ run : |
94+ # Lowercase the image name (Docker registries require lowercase)
95+ IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
96+
97+ # Use the version tag if this is a tag push, otherwise use edge
98+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
99+ TAG="${GITHUB_REF#refs/tags/}"
100+ SCAN_TAG="${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${TAG#v}"
101+ else
102+ SCAN_TAG="${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:edge"
103+ fi
104+ echo "tag=$SCAN_TAG" >> $GITHUB_OUTPUT
105+ echo "Scanning image: $SCAN_TAG"
106+
107+ - name : Run security scan on image
108+ if : github.event_name != 'pull_request'
109+ uses : aquasecurity/trivy-action@master
110+ with :
111+ image-ref : ${{ steps.scan-tag.outputs.tag }}
112+ format : " sarif"
113+ output : " trivy-results.sarif"
114+
115+ - name : Upload Trivy scan results to GitHub Security tab
116+ if : github.event_name != 'pull_request'
117+ uses : github/codeql-action/upload-sarif@v4
118+ with :
119+ sarif_file : " trivy-results.sarif"
120+
121+ - name : Generate build summary
122+ if : github.event_name != 'pull_request'
123+ run : |
124+ echo "## Docker Build Summary" >> $GITHUB_STEP_SUMMARY
125+ echo "- **Image**: \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
126+ echo "- **Tags**: \`${{ steps.meta.outputs.tags }}\`" >> $GITHUB_STEP_SUMMARY
127+ echo "- **Platforms**: \`linux/amd64, linux/arm64\`" >> $GITHUB_STEP_SUMMARY
128+ echo "- **Registry**: \`${{ env.REGISTRY }}\`" >> $GITHUB_STEP_SUMMARY
0 commit comments