spicypizza / create-envfile Goto Github PK
View Code? Open in Web Editor NEWGithub Action to create a .env file with Github Secrets
License: MIT License
Github Action to create a .env file with Github Secrets
License: MIT License
I'm trying to use the environment file that I create in a subsequent step and it's failing because the python script is hard coded to put the file in path = "/github/workspace"
I'd like to create a change where instead of looking at that, it gets the GITHUB_WORKSPACE environment variable and sets it to that instead.
Im getting this, it seems to only be working on Linux.
How can I create .env file with my own custom name? for example for staging I want to create .staging.env file or for production .prod.env?
Can I do this?
I currently have this in my workflow:
name: Build and Deploy
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: [ubuntu-latest]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Install dependencies
run: npm install
# - name: Run tests
# run: npm test
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_DEBUG: false
envkey_FIRESTORE_API_TOKEN: ${{ FIRESTORE_API_TOKEN }}
file_name: .env
- name: Build
run: npm run react-build
- name: Deploy to firebase
uses: w9jds/firebase-action@master
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Am I doing something wrong?
This behavior causes inconsistencies in variable handling, especially who rely on specific key casing for their applications.
When I try to build a react-native App for iOS, I get an error.
Error: Container action is only supported on Linux
Currently, step passes even if I provided incorrect key-value to "with" section. It would be good if there would be a way to fail step on incorrect key-value pair
Through Github API, it is possible to retrieve the name of all secrets at once. It is also possible to retrieve the value of a secret. That makes the workflow definition much easier, as it would eliminate the need to specify any ENVKEYs for secrets; the action could just dump all secrets instead.
Github API authentication is also painless, as every Github workflow already provides an authentication token that can be used.
This is my workflow
# This is a basic workflow to help you get started with Actions
name: digitalocean-pull-and-setup-env
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the $default-branch branch
# push:
# branches: [ $default-branch ]
# pull_request:
# branches: [ $default-branch ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# SSH into digitalocean droplet
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
# create the env file
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
DEBUG: False
DEVELOPMENT_MODE: False
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET }}
directory: /home/django/all_django_projects
file_name: .django
i have already setup the ssh-action but it looks like it run the last step separately from the ssh action
I got error related to file not created
Creating file: /github/workspace/home/runner/work/ePricing/ePricing/.env
File "/opt/action/create-envfile.py", line 47, in <module>
with open(full_path, "w") as text_file:
FileNotFoundError: [Errno 2] No such file or directory: '/github/workspace/home/runner/work/ePricing/ePricing/.env'
Here's the workflow
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: SpicyPizza/create-envfile@main
with:
envkey_DEBUG: false
envkey_DB_SERVER: ${{ secrets.DB_SERVER }}
directory: ePricing/
file_name: .env
fail_on_empty: false
Any ideas?
Just want to know, what would happen if there's already an existing .env file in the specified directory present, and what to do if that would cause any conflicts?
I've observed that the keys on the generated env file are sorted.
However it breaks some variables that uses other variables in the env file.
For instance:
suppose a variable name DOMAIN_NAME=example.com
envkey_DOMAIN_NAME: 'example.com'
followed by another one such as BAR_HOST_FQDN=bar.${DOMAIN_NAME}.
envkey_BAR_HOST_FQDN: "bar.${DOMAIN_NAME}"
the original env file is created such as
DOMAIN_NAME=example.com
BAR_HOST_FQDN=bar.${DOMAIN_NAME}
But the resulting translated env file is:
BAR_HOST_FQDN=bar.${DOMAIN_NAME}
DOMAIN_NAME=example.com
However, DOMAIN_NAME is not defined by the time BAR_HOST_FQDN is evaluated resulting in:
BAR_HOST_FQDN: bar
DOMAIN_NAME: example.com
which is different from the produced in the original env file:
BAR_HOST_FQDN: bar.example.com
DOMAIN_NAME: example.com
This doesn't seem to be much but it broke several large env files I have.
Hi, I tried this as action but it doesnt work
action.yml
name: Create envfile
on: [ push ]
jobs:
create-envfile:
runs-on: ubuntu-latest
steps:
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_DEBUG: false
envkey_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
directory: thedirectory/
file_name: .env
fail_on_empty: false
workflow.yml
name: Build and deploy Python app
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get Environment Variables
uses: ./.github/actions/create_envfile // it fails here
Error
Error: /home/runner/work/thedirectory/thedirectory/./.github/actions/create_envfile/action.yml (Line: 16, Col: 27):
Error: /home/runner/work/thedirectory/thedirectory/./.github/actions/create_envfile/action.yml (Line: 16, Col: 27): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.CLIENT_SECRET
Any ideas?
As per doc, this key should set the directory in which you want to create env file. However, it is creating env file at $GITHUB_WORKSPACE even after specifying directory or even full path.
I would like the workflow step to fail if the secret is not defined. But currently, it is not the case.
- name: Make envfile for testing environment
uses: SpicyPizza/create-envfile@v1
with:
envkey_STRIPE_SECRET_KEY: ${{ secrets.SECRET_VARIABLE }}
file_name: .env
This still passes even if secrets.SECRET_VARIABLE is not defined
The Error
Build container for action use: '/home/thamjith/actions-runner/nextjs-app/_actions/SpicyPizza/create-envfile/v1/Dockerfile'.
Error: File not found: 'docker'
The yml file I'm using
name: Node.js CI
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_NEXT_PUBLIC_GA_ID: ${{ secrets.NEXT_PUBLIC_GA_ID }}
directory: './'
file_name: '.env'
- run: npm i
- run: npm run build --if-present
- run: npm run export
name: Create envfile
on: [ push ]
jobs:
create-envfile:
runs-on: ubuntu-latest
steps:
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_SOMETHING: something
I expected this to create the env file within my project directory e.g. /home/runner/work/application-name/application-name/.env
But I get the following:
Creating file: /github/workspace/.env
Only thing I can guess is GITHUB_WORKSPACE isn't set and it's defaulting to this path?
path = str(os.getenv("GITHUB_WORKSPACE", "/github/workspace"))
First of all, thanks a million for this action, it's super useful.
I was wondering how to escape multiline env vars. let's say I have a cert that I want to pass to my .env file from a github secret. This works locally because I can wrap the cert in quotes in my local .env file. How can I accomplish the same thing with this action? I don't think it does this by default, because right now I'm getting the following error when I try to run docker-compose
Run docker compose -f docker-compose.yml -f production.yml build
unexpected character "+" in variable name near "***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\n***\nPOSTGRES_DB=***\nPOSTGRES_HOST=***\nPOSTGRES_PASSWORD=***\nPOSTGRES_PORT=***\nPOSTGRES_USER=***\nREDIS_HOST=***\nREDIS_PASSWORD=***\nREDIS_PORT=***\n"
Error: Process completed with exit code 1.
Well, somehow this broke a project CI/CD pipeline I am working on. It was earlier configured to use empty Email Host Name, hence it's currently failing with the error **Empty env key**
. Any help would be appreciated
Originally posted by @mannyanebi in #40 (comment)
Hi,
I have a folder called:
"./server"
and i want to add an .env file in it.
using:
directory: server
the build return the next error:
Traceback (most recent call last):
File "/create-envfile.py", line 22, in <module>
with open(os.path.join(path, directory, file_name), "w") as text_file:
FileNotFoundError: [Errno 2] No such file or directory: 'None/server/.env'
Any ideas.
The README is non-explicit on wether SECRET is optional in a variable name.
This seems like a tiny oversight in documentation. I'm not sure how to fix it, because I don't really know wether it is optional, or the implications of not putting _SECRET_.
I am trying to create an .env
file as part of Github Action workflow as shown below.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: "10.x"
- name: Install npm dependencies
run: npm install
- name: Create the .env file
uses: SpicyPizza/create-envfile@v1
with:
envkey_QUERY_LIMIT: 20
envkey_GOOGLE_RECAPTCHA_SECRET_KEY: ${{ secrets.GOOGLE_RECAPTCHA_SECRET_KEY }}
file_name: .env
- name: Run build task
run: npm run build
The build job is successful but my app can not read the .env
after deployment, on the server that is.
Any ideas why?
Hey there, I hope you add a feature to get release version to env file
Traceback (most recent call last):
File "/create-envfile.py", line 22, in
with open(os.path.join(path, directory, file_name), "w") as text_file:
FileNotFoundError: [Errno 2] No such file or directory: 'None/***/.env'
Hello, I started to use this action for one use case I had. The issue is that for some keys, for example MyValidEnvVarName
it mutates it into MYVALIDENVVARNAME
. I am not sure if there is already a flag or something to not mutate the var name, I didn't find it on the documentation. Would be good having this. Currently my solution was updating the code, but for larger code (that do not depend on me only) it is kind of laborious and prone to errors.
Thanks in advance
yml file:
name: Run tests
on:
pull_request:
branches: [master, develop]
jobs:
create-envfile:
runs-on: ubuntu-18.04
steps:
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
NEXT_PUBLIC_CONTENTFUL_DELIVERY_TOKEN: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_DELIVERY_TOKEN }}
NEXT_PUBLIC_CONTENTFUL_SPACE_ID: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_SPACE_ID }}
SITE_SEARCH_API_KEY: ${{ secrets.SITE_SEARCH_API_KEY }}
NEXT_PUBLIC_CONTENTFUL_ENVIRONMENT: master
SITE_SEARCH_ENGINE_SLUG: test
directory: .
file_name: .env
- name: Install modules
run: yarn
- name: Run tests
run: yarn jest
- name: Run Translations & Build
run: yarn translations && yarn build
Result:
I'm creating multiple .env but file doesn't appear.
When creating multiple .env files in different directories, doesn't get directory specified and overrides on all steps.
Only gets a warning
Warning: Unexpected input(s) 'envkey_DOCKER_WEB_PORT', 'envkey_DOCKER_API_PORT', 'directory', valid inputs are ['entryPoint', 'args', 'file_name']
.yml file
runs-on: self-hosted
steps:
- name: Create ROOT .env file
uses: SpicyPizza/[email protected]
with:
envkey_DOCKER_WEB_PORT: ${{ secrets.DOCKER_WEB_PORT }}
envkey_DOCKER_API_PORT: ${{ secrets.DOCKER_API_PORT }}
directory: ./
file_name: .env
- name: Create WEB .env file
uses: SpicyPizza/[email protected]
with:
envkey_REACT_APP_API_URL: ${{ secrets.REACT_APP_API_URL }}
directory: ./web-react
file_name: .env
Hello, I was trying to use version 1.1 of this action, and after a lot of failed attempts to make it work, I noticed that there is a required parameter that the example on the readme does not cover.
Inside the create-envfile.py
at line 18 there is:
path = str(os.environ.get("INPUT_GITHUB_WORKSPACE"))
So it expects the user to manually input the GitHub workspace variable. If missing, that line will throw an error because it tries to output the env file into None/directory/.env
.
To make it work it should be used like this:
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_SOME_VARIABLE: "test"
directory: somedirectory
github_workspace: ${{ github.workspace }}
Also, in the master branch, the title in the readme should say SpicyPizza/create-envfile@master
(to use the master version) and not SpicyPizza/[email protected]
, which leads to confusion since the usage is a little different.
Hope it helps
I am facing issue while creating .env file
Traceback (most recent call last):
File "/opt/action/create-envfile.py", line 38, in
raise Exception("Absolute paths are not allowed. Please use a relative path.")
Exception: Absolute paths are not allowed. Please use a relative path. Please help to resolvee the issue @AngelOnFira
Originally posted by @ZinatSayyad in #10 (comment)
Hi,
Is there a plan to update to use node 20?
We're starting to see these warnings on CI.
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: SpicyPizza/[email protected]. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
I think this mainly needs an update here: https://github.com/SpicyPizza/create-envfile/blob/main/action.yml#L21
But bumping some CI packages and config like #164 and https://github.com/SpicyPizza/create-envfile/blob/main/.github/workflows/check-dist.yml#L29 can probably help.
Hey @AngelOnFira, thanks for creating this github action it helps alot.
I wanted to create .env
files in a specified directory rather than at root but this feature wasn't available, that's why I forked this repository and implemented those changes.
Please checkout this forked version and if you think that it can be merged with your repo, please let me know i'll raise a PR with the required changes.
NOTE: At first, I didn't thought that you'll want to add these changes that's why I have updated README.md
. Let me know if you want to add changes, then I will revert back all changes from README.md
.
Thanks!
When running this action I get the following error output:
Unexpected input(s) 'envkey_APP_ENV', 'envkey_APP_KEY', 'envkey_MIX_APP_URL', 'envkey_APP_URL', valid inputs are ['entryPoint', 'args', 'file_name']
My yaml looks like so:
- name: Generate .env file
uses: SpicyPizza/create-envfile@v1
with:
envkey_APP_ENV: staging
envkey_APP_KEY:
envkey_MIX_APP_URL: https://staging.example.com
envkey_APP_URL: https://staging.example.com
- run: sudo chown -R $(id -u):$(id -g) .env
APP_KEY
is initially empty and gets filled in later in a later -run
command.
Should these be nested under args
or something?
Hi! Thanks for building this action. It is extremely useful in my workflow.
And since my workflow requires to create .env
files inside the build I have created dump-env
sometime ago.
Its features:
.env
files from env vars.env
files from .env.template
It is written in python
and fits this project perfectly. Maybe we can join our forces here? 🙂
It throws following error when build starts;
Build container for action use: '/root/actions-runner/_work/_actions/SpicyPizza/create-envfile/v1.1/Dockerfile'.
Error: docker: command not found
Workflow file like below;
name: Continuous Deployment
on:
push:
branches:
- develop
jobs:
deployment:
runs-on: self-hosted
steps:
- name: Checkout develop branch
uses: actions/checkout@v2
with:
ref: develop
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Make envfile for vendure server
uses: SpicyPizza/[email protected]
with:
envkey_DEBUG: true
envkey_DB: "postgres"
...
I am facing issues with creating .env file. I am deploying my project using Google app engine. The project gets deployed but .env file is not created. Can you please help me with the issue.
This is my main.yaml file-
name: CI
on:
push:
branches: [ deploy ]
pull_request:
branches: [ deploy ]
jobs:
create-envfile:
runs-on: ubuntu-18.04
steps:
- name: Make envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_DEBUG: False
envkey_DATABASE_URL: ${{ secrets.DATABASE_URL }}
envkey_USER: ${{ secrets.USER }}
envkey_PASSWORD: ${{ secrets.PASSWORD }}
envkey_DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
file_name: .env
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Initialize Google Cloud SDK
uses: zxyle/publish-gae-action@master
with:
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.PROJECT_ID }}
gae_variables: ${{ secrets.GAE_VARIABLES }}
- name: Publish app to Google App Engine
run: |
gcloud auth activate-service-account ${{ secrets.GCP_SA_EMAIL }} --key-file=client-secret.json
gcloud config set project ${{ secrets.PROJECT_ID }}
gcloud -q app deploy app.yaml --promote
Please check the output at https://github.com/khannakshat7/Elektra/actions/runs/888591866
Hi
Using the following step:
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_FROM_ADDRESS: ${{ secrets.FROM_ADDRESS }}
envkey_SMTP_HOST: ${{ vars.SMTP_HOST }}
envkey_SMTP_PORT: ${{ vars.SMTP_PORT }}
envkey_SMTP_USERNAME: ${{ secrets.SMTP_USERNAME }}
envkey_SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
envkey_MAILDROP_INBOX: "test-maildropy-$${{github.job}}"
envkey_SMTP_SSL_MODE: "SSL"
directory: tests
file_name: .env
fail_on_empty: false
sort_keys: false
I get this warning:
Warning: Unexpected input(s) 'envkey_FROM_ADDRESS', 'envkey_SMTP_HOST', 'envkey_SMTP_PORT', 'envkey_SMTP_USERNAME', 'envkey_SMTP_PASSWORD', 'envkey_MAILDROP_INBOX', 'envkey_SMTP_SSL_MODE', valid inputs are ['file_name', 'directory', 'fail_on_empty', 'sort_keys']
It looks like the .env file is properly generated as I don't have any key error afterward but why this warning?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.