ci: strategy update and images cleaning #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Publish Docker Images | |
| on: | |
| push: | |
| branches: [ "main", "develop" ] | |
| pull_request: | |
| branches: [ "main", "develop" ] | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # needed to create the release | |
| packages: write # needed to publish the image | |
| # Skip building images for draft PRs or very old branches | |
| if: | | |
| github.event_name == 'push' || | |
| (github.event_name == 'pull_request' && | |
| github.event.pull_request.draft == false) | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Extract version from pyproject.toml | |
| id: project_version | |
| run: | | |
| VERSION=$(grep 'version =' pyproject.toml | sed -E 's/version = "([^"]+)"/\1/') | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| # For main branch: latest and version tags | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=raw,value=${{ steps.project_version.outputs.version }},enable={{is_default_branch}} | |
| # For develop branch: develop tag | |
| type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }} | |
| # For PRs: pr-{number} tag | |
| type=ref,event=pr,prefix=pr- | |
| # For feature branches: branch name (sanitized) | |
| type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} | |
| labels: | | |
| org.opencontainers.image.title=${{ github.repository }} | |
| org.opencontainers.image.description=${{ github.event.repository.description }} | |
| org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
| org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
| org.opencontainers.image.revision=${{ github.sha }} | |
| org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Create GitHub Release | |
| # Only create releases for main branch pushes | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.project_version.outputs.version }} | |
| name: Release v${{ steps.project_version.outputs.version }} | |
| body_path: CHANGELOG.md | |
| fail_on_unmatched_files: true |