diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5f58681..86c1aa90 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,6 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} jobs: build: @@ -18,11 +17,20 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - with: - submodules: true + + - name: Get full image name + id: base_image_name + env: + BASE_IMAGE_NAME: ${{ github.repository }} + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + echo "image_name=${REGISTRY}/${BASE_IMAGE_NAME}" >> $GITHUB_OUTPUT + else + echo "image_name=${REGISTRY}/${BASE_IMAGE_NAME}-stage" >> $GITHUB_OUTPUT + fi - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -30,12 +38,17 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ steps.base_image_name.outputs.image_name }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ startsWith(github.ref, 'refs/heads') }} + type=semver,pattern={{version}},prefix=v + type=semver,pattern={{major}}.{{minor}},prefix=v - name: Build and push image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: context: . file: docker/php/Dockerfile