CI: build container when the version is a clean tag
All checks were successful
/ build (push) Successful in 10s
/ test (push) Successful in 17s

This commit is contained in:
phil 2024-11-03 19:12:28 +01:00
parent cc4584ae97
commit b523ead55f

View file

@ -1,25 +1,49 @@
on:
push:
workflow_dispatch:
inputs:
build:
description: "Build container"
required: true
default: true
type: boolean
jobs:
build:
runs-on: container
steps:
- uses: actions/checkout@v4
- name: Git unshallow - get all history from Git to get the tag for the computation of the version
run: git pull --unshallow
with:
fetch-depth: 0
- name: Get the version from git
id: version
run: echo "version=$(git describe --dirty --tags)" >> $GITHUB_OUTPUT
- name: Check if the container should be built
id: builder
env:
RUN: ${{ toJSON(inputs.build || !contains(steps.version.outputs.version, '-')) }}
run: |
echo "run=$RUN" >> $GITHUB_OUTPUT
echo "Run build: $RUN"
- name: Info - version and if the image container should be built
env:
VERSION: ${{ steps.version.outputs.version }}
RUN: ${{ steps.builder.outputs.run }}
FORCE: ${{ toJSON(inputs.build) }}
run: |
echo "Version $VERSION, force (manual input): $FORCE, run the build: $RUN"
- name: Workaround for bug of podman-login
if: fromJSON(steps.builder.outputs.run)
run: |
mkdir -p $HOME/.docker
echo "{ \"auths\": {} }" > $HOME/.docker/config.json
- name: Log in to the container registry (with another workaround)
if: fromJSON(steps.builder.outputs.run)
uses: actions/podman-login@v1
with:
registry: ${{ vars.REGISTRY }}
@ -28,6 +52,7 @@ jobs:
auth_file_path: /tmp/auth.json
- name: Build the container image
if: fromJSON(steps.builder.outputs.run)
uses: actions/buildah-build@v1
with:
image: treetrail-backend
@ -38,6 +63,7 @@ jobs:
./Containerfile
- name: Push the image to the registry
if: fromJSON(steps.builder.outputs.run)
uses: actions/push-to-registry@v2
with:
registry: "docker://${{ vars.REGISTRY }}"