From 816f9ed857e94c7c01359515f11cf7673429f314 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sun, 2 Feb 2025 13:08:45 +0100 Subject: [PATCH] added some protections against error cases --- .forgejo/steps/push/action.yml | 7 ++++++- common.sh | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.forgejo/steps/push/action.yml b/.forgejo/steps/push/action.yml index a7acf62..cce3130 100644 --- a/.forgejo/steps/push/action.yml +++ b/.forgejo/steps/push/action.yml @@ -33,7 +33,12 @@ runs: steps: - name: login shell: sh - run: 'skopeo login -u "${{ inputs.username }}" -p "${{ inputs.password }}" ${{ inputs.registry }}' + run: | + if [ -z "${{ inputs.password }}" ] ; then + echo The password is unset + exit 1 + fi + skopeo login -u "${{ inputs.username }}" -p "${{ inputs.password }}" ${{ inputs.registry }} env: REGISTRY_AUTH_FILE: ${{env.RUNNER_TEMP}}/auth.json - name: skopeo copy diff --git a/common.sh b/common.sh index 9eb0797..0fbbd3e 100644 --- a/common.sh +++ b/common.sh @@ -5,6 +5,7 @@ init_container () { local container_name="$1" local image="$2" buildah from -q -v "$empty_dir":/tmp:slave -v "$empty_dir":/var/cache:slave -v "$empty_dir":/var/tmp:slave -v "$empty_dir":/var/log:slave --pull=newer --name="$container_name" "${image}" >/dev/null + remove_container_on_exit "$container_name" buildah run --user 0:0 "$container_name" chmod -c 1777 /tmp /var/tmp buildah run --user 0:0 "$container_name" touch /tmp/test } @@ -13,4 +14,11 @@ commit(){ buildah config -e - -l - -a - -p - "$1" buildah config -e PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" "$1" buildah commit --rm -f oci --squash "$1" "$2" + trap - EXIT +} + +remove_container_on_exit() { + container="$1" + # shellcheck disable=SC2064 + trap "buildah rm ${container}" EXIT }