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: Publish Docker Image to GHCR | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*.*.*' # Semantic versioning pattern | |
| pull_request: | |
| # This triggers on any PR, but we filter by source branch in the job | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Only continue for PRs if the source branch is dev or release | |
| - name: Check PR source branch | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| echo "PR source branch: ${{ github.head_ref }}" | |
| if [[ "${{ github.head_ref }}" != "dev" && "${{ github.head_ref }}" != "release" ]]; then | |
| echo "Not a PR from dev or release branch. Skipping workflow." | |
| exit 1 | |
| fi | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| run: | | |
| IMAGE_NAME=ghcr.io/eed-solutions/eed_docker_python_uv | |
| TAG=latest | |
| SHOULD_BUILD_PUSH=false | |
| # Determine tag and build indicator based on context | |
| if [[ "${{ github.ref_type }}" == "branch" ]]; then | |
| case "${{ github.ref_name }}" in | |
| "main") | |
| TAG=main | |
| SHOULD_BUILD_PUSH=true | |
| ;; | |
| "dev") | |
| TAG=dev | |
| SHOULD_BUILD_PUSH=true | |
| ;; | |
| "release") | |
| TAG=release | |
| SHOULD_BUILD_PUSH=true | |
| ;; | |
| *) | |
| TAG=${{ github.ref_name }} | |
| ;; | |
| esac | |
| elif [[ "${{ github.ref_type }}" == "tag" ]]; then | |
| TAG=${{ github.ref_name }} | |
| if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| SHOULD_BUILD_PUSH=true | |
| fi | |
| fi | |
| # Build and push the image if indicated | |
| if [[ "$SHOULD_BUILD_PUSH" == "true" ]]; then | |
| docker build -t $IMAGE_NAME:$TAG -f .devcontainer/Dockerfile . | |
| docker push $IMAGE_NAME:$TAG | |
| else | |
| echo "Skipping build and push: not a main/dev/release branch or semantic version tag." | |
| fi | |
| # Push additional 'latest' tag for semantic version tags | |
| if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then | |
| docker tag $IMAGE_NAME:$TAG $IMAGE_NAME:latest | |
| docker push $IMAGE_NAME:latest | |
| fi |