Skip to content

test

test #18

Workflow file for this run

name: Docker Image CI
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
workflow_dispatch:
inputs:
branch-tag:
description: Branch or Tag
required: true
default: 'develop'
workflow_call:
inputs:
branch-tag:
required: true
type: string
default: 'develop'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set version and branch
id: set-version-and-branch
run: |
export VERSION=`git log -1 --pretty=format:%h`
echo "Pushing version $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# the event_name is the event that triggered the caller workflow
# and not "workflow_call" like how it was supposed to be when
# another workflow is calling this one
if [ "${{ github.event_name }}" == 'push' ]; then
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
elif [ "${{ github.event_name }}" == 'pull_request' ]; then
BRANCH=${{ github.event.pull_request.head.ref }}
else
BRANCH=${{ inputs.branch_name }}
fi
ESCAPED_BRANCH=$(echo $BRANCH | sed 's/[^a-zA-Z0-9_.-]/-/g')
echo "from branch $BRANCH"
echo "branch=$ESCAPED_BRANCH" >> $GITHUB_OUTPUT
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# - name: Build the Docker image
# run: |
# pattern="^v[0-9]+\.[0-9]+\.[0-9]+$"
# input_branch=${{ github.event.inputs.branch-tag }}
# input_commit=${input_branch:-develop}
# echo "Checking out $input_commit"
# if [[ $pattern =~ $input_commit ]]; then
# tag=${{ github.event.inputs.branch-tag }}
# echo "Changed build tag to $tag"
# git checkout $tag
# else
# tag=$(date +%s)
# echo "Running build on develop branch"
# fi
# image_with_tag="ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:$(date +%s)"
# docker build . --file Dockerfile --tag $image_with_tag
# docker push $image_with_tag
- name: Build and push base image
uses: docker/build-push-action@v6
with:
file: Dockerfile
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.set-version-and-branch.outputs.branch }}