add description and more robust action
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Creates or updates a .env file with specified environment variables and outputs its base64-encoded content.
|
||||||
|
|||||||
43
action.yml
43
action.yml
@@ -1,47 +1,50 @@
|
|||||||
name: 'Prepare Environment'
|
name: 'Prepare Env File'
|
||||||
description: 'Prepares .env file with necessary variables'
|
description: 'Creates or updates a .env file with specified environment variables and outputs its base64-encoded content.'
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
stack_name:
|
stack_name:
|
||||||
description: 'Stack name'
|
description: 'The name of the stack to set in the .env file.'
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
exists:
|
exists:
|
||||||
description: 'Whether .env file exists'
|
description: 'Indicates whether the .env file existed before running this action.'
|
||||||
value: 'true'
|
value: ${{ steps.prepare.outputs.exists }}
|
||||||
content:
|
content:
|
||||||
description: 'Base64 encoded content of .env file'
|
description: 'Base64-encoded content of the resulting .env file.'
|
||||||
value: ${{ steps.encode.outputs.content }}
|
value: ${{ steps.encode.outputs.content }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
- id: prepare
|
- id: prepare
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
echo "DEBUG: Checking if .env file exists"
|
set -euo pipefail
|
||||||
if [ ! -f ".env" ]; then
|
if [ -f ".env" ]; then
|
||||||
echo "DEBUG: .env file not found, creating new one"
|
echo "exists=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "DEBUG: .env file exists. Updating STACK_NAME."
|
||||||
|
else
|
||||||
|
echo "exists=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "DEBUG: .env file does not exist. Creating new .env file."
|
||||||
touch .env
|
touch .env
|
||||||
else
|
|
||||||
echo "DEBUG: .env file already exists, using existing file"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "DEBUG: Checking if STACK_NAME is already set in .env"
|
if grep -q "^STACK_NAME=" .env; then
|
||||||
if grep -q "STACK_NAME=" .env; then
|
sed -i "s/^STACK_NAME=.*/STACK_NAME=${{ inputs.stack_name }}/" .env
|
||||||
echo "DEBUG: STACK_NAME found in .env, updating value to '${{ inputs.stack_name }}'"
|
echo "DEBUG: Updated existing STACK_NAME to '${{ inputs.stack_name }}'."
|
||||||
sed -i "s/STACK_NAME=.*/STACK_NAME=${{ inputs.stack_name }}/" .env
|
|
||||||
else
|
else
|
||||||
echo "DEBUG: STACK_NAME not found in .env, adding value '${{ inputs.stack_name }}'"
|
|
||||||
echo "STACK_NAME=${{ inputs.stack_name }}" >> .env
|
echo "STACK_NAME=${{ inputs.stack_name }}" >> .env
|
||||||
|
echo "DEBUG: Added STACK_NAME='${{ inputs.stack_name }}' to .env."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "DEBUG: Final .env file content:"
|
echo "DEBUG: Final .env content:"
|
||||||
cat .env
|
cat .env
|
||||||
|
|
||||||
- id: encode
|
- id: encode
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
echo "DEBUG: Encoding .env file to base64"
|
set -euo pipefail
|
||||||
ENV_BASE64=$(base64 -w 0 .env)
|
ENV_BASE64=$(base64 -w 0 .env)
|
||||||
echo "content=$ENV_BASE64" >> $GITHUB_OUTPUT
|
echo "content=$ENV_BASE64" >> $GITHUB_OUTPUT
|
||||||
echo "DEBUG: .env file encoded successfully"
|
echo "DEBUG: Successfully encoded .env file to base64."
|
||||||
|
|
||||||
Reference in New Issue
Block a user