diff --git a/README.md b/README.md index e69de29..c7dabfd 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +Creates or updates a .env file with specified environment variables and outputs its base64-encoded content. diff --git a/action.yml b/action.yml index c21cdcd..a723d6a 100644 --- a/action.yml +++ b/action.yml @@ -1,47 +1,50 @@ -name: 'Prepare Environment' -description: 'Prepares .env file with necessary variables' +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: 'Stack name' + description: 'The name of the stack to set in the .env file.' required: true + outputs: exists: - description: 'Whether .env file exists' - value: 'true' + description: 'Indicates whether the .env file existed before running this action.' + value: ${{ steps.prepare.outputs.exists }} content: - description: 'Base64 encoded content of .env file' + description: 'Base64-encoded content of the resulting .env file.' value: ${{ steps.encode.outputs.content }} + runs: using: 'composite' steps: - id: prepare shell: bash run: | - echo "DEBUG: Checking if .env file exists" - if [ ! -f ".env" ]; then - echo "DEBUG: .env file not found, creating new one" + 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 - else - echo "DEBUG: .env file already exists, using existing file" fi - echo "DEBUG: Checking if STACK_NAME is already set in .env" - if grep -q "STACK_NAME=" .env; then - echo "DEBUG: STACK_NAME found in .env, updating value to '${{ inputs.stack_name }}'" - sed -i "s/STACK_NAME=.*/STACK_NAME=${{ inputs.stack_name }}/" .env + 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 "DEBUG: STACK_NAME not found in .env, adding value '${{ inputs.stack_name }}'" echo "STACK_NAME=${{ inputs.stack_name }}" >> .env + echo "DEBUG: Added STACK_NAME='${{ inputs.stack_name }}' to .env." fi - echo "DEBUG: Final .env file content:" + echo "DEBUG: Final .env content:" cat .env - id: encode shell: bash run: | - echo "DEBUG: Encoding .env file to base64" + set -euo pipefail ENV_BASE64=$(base64 -w 0 .env) echo "content=$ENV_BASE64" >> $GITHUB_OUTPUT - echo "DEBUG: .env file encoded successfully" - + echo "DEBUG: Successfully encoded .env file to base64." \ No newline at end of file