mirror of
https://github.com/deadcxap/YandexMusicDiscordBot.git
synced 2026-01-09 23:51:45 +03:00
75 lines
2.6 KiB
YAML
75 lines
2.6 KiB
YAML
name: Docker Image CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
pull_request:
|
|
branches:
|
|
- '**'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/yandexmusicdiscordbot
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v2
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Get short SHA
|
|
id: vars
|
|
run: echo "short_sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Sanitize branch name
|
|
id: sanitize
|
|
run: |
|
|
sanitized=$(echo "${GITHUB_REF_NAME}" | tr '/' '-')
|
|
echo "sanitized=${sanitized}" >> $GITHUB_OUTPUT
|
|
env:
|
|
GITHUB_REF_NAME: ${{ github.ref_name }}
|
|
|
|
# Сборка для push-событий (ветки)
|
|
- name: Build and push Docker image (push event)
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ env.IMAGE_NAME }}:${{ steps.sanitize.outputs.sanitized }}-${{ 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
|
|
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
|
|
run: |
|
|
docker pull $IMAGE_NAME:${{ steps.sanitize.outputs.sanitized }}-${{ steps.vars.outputs.short_sha }}
|
|
docker tag $IMAGE_NAME:${{ steps.sanitize.outputs.sanitized }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest
|
|
docker push $IMAGE_NAME:latest
|
|
|
|
- name: Set the latest tag for the dev branch
|
|
if: github.ref == 'refs/heads/dev' && github.event_name != 'pull_request'
|
|
run: |
|
|
docker pull $IMAGE_NAME:${{ steps.sanitize.outputs.sanitized }}-${{ steps.vars.outputs.short_sha }}
|
|
docker tag $IMAGE_NAME:${{ steps.sanitize.outputs.sanitized }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest-dev
|
|
docker push $IMAGE_NAME:latest-dev
|