'Github actions - How can I load the full of env secrets insert to local env file

I read some question about the load a specified secret into the env file, It same like:

    - name: 'Create env file'
      run: |
        touch .env
        echo DEBUG="false" >> .env
        echo PORT=9000 >> .env
        echo JWT_ACCESS_SECRET=${{ secrets.JWT_ACCESS_SECRET }} >> .env
        echo JWT_REFRESH_SECRET=${{ secrets.JWT_REFRESH_SECRET }} >> .env
        echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} >> .env
        echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} >> .env
        echo AWS_SES_SENDER_ADDRESS=${{ secrets.AWS_SES_SENDER_ADDRESS }} >> .env
        echo AWS_OPENSEARCH_NODE=${{ secrets.AWS_OPENSEARCH_NODE }} >> .env
        echo DATABASE_URL=${{ secrets.DATABASE_URL }} >> .env
        cat .env

It works nicely.
But I want to create a secret key follow by:
name: ENV_PREVIEW
body:

# APP
DEBUG=true

# POSTGRES
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres

# Nest run locally
DB_HOST=xxx.rds.amazonaws.com
# Nest run in docker, change host to database container name
# DB_HOST=xxx
DB_PORT=xxx
DB_SCHEMA=xxx

And I want to insert the full value into my env file, so I write the commands:

    - name: 'Create env preview file'
      run: |
        touch .env.preview
        echo ${{ secrets.ENV_PREVIEW }} >> .env.preview
        cat .env.preview

But It couldn't work, The shell create an empty file and insert into nothing,
is a way to solve it?
Thanks.



Solution 1:[1]

I found some answers to solve it, It's a shell question.

    - name: 'Create env preview file'
      run: |
        cat > .env.preview <<EOF
        ${{ secrets.ENV_PREVIEW }}
        EOF

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ???