diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 21a4e0c..03d0bd8 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,8 +1,6 @@ #See: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages name: Create and publish a Docker image -on: - release: - types: [ published ] +on: push env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -20,11 +18,17 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set environment variables + run: | + # Short name for current branch. For PRs, use target branch (base ref) + GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}} + echo "GIT_BRANCH=$GIT_BRANCH" >> $GITHUB_ENV - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ env.GIT_BRANCH }} + tags: latest - name: Build and push Docker image uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f2fddaa..0cb936a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: id: docker_meta uses: docker/metadata-action@v4 with: - images: ${{ env.DOCKER_IMAGE }} + images: ${{ env.DOCKER_IMAGE }}-${{ env.GIT_BRANCH }} tags: | type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}}