test #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 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} | |
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 |