From b523ead55ff124acb8856b785af0cc0517cdabc4 Mon Sep 17 00:00:00 2001 From: phil Date: Sun, 3 Nov 2024 19:12:28 +0100 Subject: [PATCH] CI: build container when the version is a clean tag --- .forgejo/workflows/build.yaml | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 28fdb2d..6605e1a 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -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 }}"