All checks were successful
Build and Publish Docker Image / build-only (push) Successful in 3m23s
Build and Publish Docker Image / build-and-push-main (push) Has been skipped
Build and Publish Docker Image / build-and-push-tag (push) Has been skipped
Build and Publish Docker Image / build-only (pull_request) Successful in 2m7s
Build and Publish Docker Image / build-and-push-main (pull_request) Has been skipped
Build and Publish Docker Image / build-and-push-tag (pull_request) Has been skipped
- Replace complex single-job conditional steps with 3 separate jobs: build-only, build-and-push-main, build-and-push-tag - Use Gitea Actions-compatible startsWith() function instead of .startsWith() method call - Remove nested parentheses that Gitea Actions cannot parse - Push only on refs/heads/main and refs/tags/v* (not all branches)
100 lines
3.4 KiB
YAML
100 lines
3.4 KiB
YAML
name: Build and Publish Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
create:
|
|
refs/tags/v*
|
|
|
|
jobs:
|
|
build-only:
|
|
runs-on: ubuntu-latest
|
|
# All branches, all PRs, and anything that's not a push to main or a version tag
|
|
if: github.event_name != 'push' || (github.event_name == 'push' && !startsWith(gitea.ref, 'refs/tags/v') && gitea.ref != 'refs/heads/main')
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build (no push)
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: false
|
|
tags: |
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:build-test
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
build-and-push-main:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ secrets.DOCKER_REGISTRY }}
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Build and push (main branch)
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:main
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:latest
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:${{ gitea.sha }}
|
|
labels: |
|
|
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
|
|
org.opencontainers.image.description=Email Classifier Service
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
build-and-push-tag:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && startsWith(gitea.ref, 'refs/tags/v')
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ secrets.DOCKER_REGISTRY }}
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Build and push (tagged release)
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:${{ gitea.ref_name }}
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:latest
|
|
${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_USERNAME }}/email-classifier:${{ gitea.sha }}
|
|
labels: |
|
|
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
|
|
org.opencontainers.image.description=Email Classifier Service
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|