Skip to content

Commit

Permalink
Create docker-publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
haravich authored Aug 13, 2023
1 parent ebe7194 commit 6b38812
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: fake-smtp-server build

on:
schedule:
- cron: "0 0 * * 0"
push:
branches:
- "**"
tags:
- "v*.*.*"
pull_request:
branches: [ "main" ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run curl command to get latest version
id: curl_output
run: |
response=$(curl -s "https://api.github.com/repos/:owner/:repo/releases/latest")
# Parse and extract tag_name from the JSON response
tag_name=$(echo $response | jq -r '.tag_name')
# Remove the leading 'v' from tag_name
latest_version=${tag_name#v}

- name: Display latest version
run: |
echo "Latest Version: $latest_version"
- name: Read version from file
id: read_version
run: |
echo "::set-output name=version::$(cat version.txt)"
- name: Display version from file
run: |
echo "Version from File: ${{ steps.read_version.outputs.version }}"
- name: Check if versions are different
id: check_versions
run: |
if [ "$latest_version" != "${{ steps.read_version.outputs.version }}" ]; then
echo "Versions are different, running Docker build..."
echo "::set-output name=build_docker::true"
else
echo "Versions are the same, skipping Docker build."
echo "::set-output name=build_docker::false"
fi
- name: Docker meta
if: steps.check_versions.outputs.build_docker == 'true'
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
haravich/fake-smtp-server
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
if: steps.check_versions.outputs.build_docker == 'true'
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
if: steps.check_versions.outputs.build_docker == 'true'
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
if: github.event_name != 'pull_request' && steps.check_versions.outputs.build_docker == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GHCR
if: github.event_name != 'pull_request' && steps.check_versions.outputs.build_docker == 'true'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
if: github.event_name != 'pull_request' && steps.check_versions.outputs.build_docker == 'true'
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 6b38812

Please sign in to comment.