update github actions to pr builds

This commit is contained in:
2025-03-20 18:49:41 +03:00
parent 74d886bf0e
commit 1cdb0c8319

View File

@@ -30,23 +30,37 @@ jobs:
id: vars id: vars
run: echo "short_sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT run: echo "short_sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Build and push Docker image # Сборка для push-событий (ветки)
- name: Build and push Docker image (push event)
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
push: true push: true
tags: ${{ env.IMAGE_NAME }}:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }} tags: ${{ env.IMAGE_NAME }}:${{ replace(github.ref_name, '/', '-') }}-${{ steps.vars.outputs.short_sha }}
# Сборка для pull request
- name: Build and push Docker image (pull request)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}
${{ env.IMAGE_NAME }}:latest-pr
# Переопределение тега latest для основных веток (только для push-событий)
- name: Set the latest tag for the main branch - name: Set the latest tag for the main branch
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
run: | run: |
docker pull $IMAGE_NAME:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }} docker pull $IMAGE_NAME:${{ replace(github.ref_name, '/', '-') }}-${{ steps.vars.outputs.short_sha }}
docker tag $IMAGE_NAME:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest docker tag $IMAGE_NAME:${{ replace(github.ref_name, '/', '-') }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest
docker push $IMAGE_NAME:latest docker push $IMAGE_NAME:latest
- name: Set the latest tag for the dev branch - name: Set the latest tag for the dev branch
if: github.ref == 'refs/heads/dev' if: github.ref == 'refs/heads/dev' && github.event_name != 'pull_request'
run: | run: |
docker pull $IMAGE_NAME:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }} docker pull $IMAGE_NAME:${{ replace(github.ref_name, '/', '-') }}-${{ steps.vars.outputs.short_sha }}
docker tag $IMAGE_NAME:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest-dev docker tag $IMAGE_NAME:${{ replace(github.ref_name, '/', '-') }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest-dev
docker push $IMAGE_NAME:latest-dev docker push $IMAGE_NAME:latest-dev