50 lines
1.6 KiB
YAML
50 lines
1.6 KiB
YAML
name: 'Prepare Env File'
|
|
description: 'Creates or updates a .env file with specified environment variables and outputs its base64-encoded content.'
|
|
|
|
inputs:
|
|
stack_name:
|
|
description: 'The name of the stack to set in the .env file.'
|
|
required: true
|
|
|
|
outputs:
|
|
exists:
|
|
description: 'Indicates whether the .env file existed before running this action.'
|
|
value: ${{ steps.prepare.outputs.exists }}
|
|
content:
|
|
description: 'Base64-encoded content of the resulting .env file.'
|
|
value: ${{ steps.encode.outputs.content }}
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- id: prepare
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
if [ -f ".env" ]; then
|
|
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
|
|
fi
|
|
|
|
if grep -q "^STACK_NAME=" .env; then
|
|
sed -i "s/^STACK_NAME=.*/STACK_NAME=${{ inputs.stack_name }}/" .env
|
|
echo "DEBUG: Updated existing STACK_NAME to '${{ inputs.stack_name }}'."
|
|
else
|
|
echo "STACK_NAME=${{ inputs.stack_name }}" >> .env
|
|
echo "DEBUG: Added STACK_NAME='${{ inputs.stack_name }}' to .env."
|
|
fi
|
|
|
|
echo "DEBUG: Final .env content:"
|
|
cat .env
|
|
|
|
- id: encode
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
ENV_BASE64=$(base64 -w 0 .env)
|
|
echo "content=$ENV_BASE64" >> $GITHUB_OUTPUT
|
|
echo "DEBUG: Successfully encoded .env file to base64." |