From cb2283aa757c0cf869da190225cb420e6608af17 Mon Sep 17 00:00:00 2001 From: Andreas Hnida Date: Wed, 17 Apr 2024 22:01:43 +0200 Subject: [PATCH] Refactor workflow to check for existence and validity of deploy_env.json before setting ENV variable. --- .gitea/workflows/pipeline-test.yaml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/pipeline-test.yaml b/.gitea/workflows/pipeline-test.yaml index 6ed094d..830a9b6 100644 --- a/.gitea/workflows/pipeline-test.yaml +++ b/.gitea/workflows/pipeline-test.yaml @@ -13,9 +13,25 @@ jobs: - name: Set Environment id: set-env run: | - echo "ENV=$(cat deploy_env.json | jq -r '.env')" >> $GITHUB_ENV - echo "::set-output name=environment::$ENV" - + # Ensure the deploy_env.json file exists and is readable + if [ ! -f deploy_env.json ]; then + echo "deploy_env.json does not exist or cannot be read." + exit 1 + fi + + # Extract the environment variable using jq and check if it's empty + ENV=$(cat deploy_env.json | jq -r '.env') + if [ -z "$ENV" ]; then + echo "Environment variable is empty." + exit 1 + fi + + # Use GitHub's environment file syntax to set the ENV variable + echo "ENV=$ENV" >> $GITHUB_ENV + + # Output the environment variable for use in subsequent steps + echo "::set-output name=environment::$ENV" + - name: Set up Go uses: actions/setup-go@v5.0.0 with: