generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing those options: | Parameter | Required | Description | Example | |:-----------:|:--------:|----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------| | repository | true | The repository ref <owner>/<repo> | `repository: "Steph0/dotenv-configserver"` | | token | true | This should be a token with access to your repository scoped in as a secret | `token: ${{ secrets.GITHUB_TOKEN }}` | | branch | false | The remote branch to checkout (default: main) | `branch: "staging"` | | destination | false | The working folder to write configuration to (default 'RUNNER_TEMP') | `destination: "/my/dest/folder"` | | directory | false | Look for file in configserver subdirectory (default '.').<br>Useful if your configserver hosts several config directories in it | `directory: "my-app-dir"` | | filename | false | The config filename (default to '.env') | `filename: "my-application.env"` | | profile | false | Profile for file (ex: 'prod' will make tool <br>look for <filename_part>-<profile>.<filename_extension>)<br><br>If empty, won't apply. | `profile: "prod"`<br>Depending on filename will make action look for file:<br>`my-application-prod.env` | | cleanup | false | If false, won't delete configuration files downloaded after loading to GITHUB_ENV (default: true) | `cleanup: false` |
- Loading branch information
Showing
16 changed files
with
11,824 additions
and
4,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"action": "workflow_dispatch", | ||
"inputs": { | ||
"repository": "Steph0/test-configserver", | ||
"token": "", | ||
"branch": "test-profile", | ||
"directory": "test", | ||
"filename": "application.env", | ||
"profile": "prod" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: "Test action" | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
repository: | ||
description: "Repository to fetch (<owner>/<repo>)" | ||
required: true | ||
token: | ||
description: "Access token - PAT" | ||
required: true | ||
branch: | ||
description: "Remote branch to checkout (default: main)" | ||
required: false | ||
directory: | ||
description: "Look for file in subdirectory (default '.')" | ||
required: false | ||
filename: | ||
description: "Config filename, with or without extension (default to '.env')" | ||
required: false | ||
profile: | ||
description: "Profile for file (ex: 'prod' ~= prod.env)" | ||
required: false | ||
destination: | ||
description: "Working folder to write configuration to (default '.')" | ||
required: false | ||
cleanup: | ||
description: "If false, won't delete configuration files (default true)" | ||
required: false | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout" | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Launch action" | ||
uses: ./ | ||
with: | ||
repository: "${{ github.event.inputs.repository }}" | ||
token: "${{ github.event.inputs.token }}" | ||
branch: "${{ github.event.inputs.branch }}" | ||
directory: "${{ github.event.inputs.directory }}" | ||
filename: "${{ github.event.inputs.filename }}" | ||
profile: "${{ github.event.inputs.profile }}" | ||
destination: "${{ github.event.inputs.destination }}" | ||
cleanup: "${{ github.event.inputs.cleanup }}" | ||
|
||
# You should see your .env config in 'env' | ||
- name: "See exported values" | ||
run: env |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,7 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
# Custom | ||
*.secrets | ||
*.secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* @Steph0 | ||
* @actions/actions-runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,211 @@ | ||
# Create a JavaScript Action | ||
# Environment from remote dotenv config server | ||
|
||
<p align="center"> | ||
<a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a> | ||
</p> | ||
Load dotenv (.env) files from a remote repository and loads it to `GITHUB_ENV`. | ||
|
||
Use this template to bootstrap the creation of a JavaScript action.:rocket: | ||
Env variables will be then available using `${{ env.<KEY> }}` in your later jobs/actions. | ||
|
||
This template includes tests, linting, a validation workflow, publishing, and versioning guidance. | ||
**This action can work as a workaround from missing Github Environments tab in Github Teams plan** | ||
|
||
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) | ||
## Configuration | ||
|
||
## Create an action from this template | ||
| Parameter | Required | Description | Example | | ||
|:-----------:|:--------:|----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------| | ||
| repository | true | The remote repository (configserver). Format: `<owner>/<repo>` | `repository: "Steph0/dotenv-configserver"` | | ||
| token | false | This should be a token with access to your repository scoped in as a secret (default to GITHUB_TOKEN) | `token: ${{ secrets.GITHUB_TOKEN }}` | | ||
| branch | false | The remote branch to checkout (default: main) | `branch: "staging"` | | ||
| destination | false | The working folder to write configuration to (default 'RUNNER_TEMP') | `destination: "/my/dest/folder"` | | ||
| directory | false | Look for file in configserver subdirectory (default '.').<br>Useful if your configserver hosts several config directories in it | `directory: "my-app-dir"` | | ||
| filename | false | The config filename (default to '.env') | `filename: "my-application.env"` | | ||
| profile | false | Profile for file (ex: 'prod' will make tool <br>look for <filename_part>-<profile>.<filename_extension>)<br><br>If empty, won't apply. | `profile: "prod"`<br>Depending on filename will make action look for file:<br>`my-application-prod.env` | | ||
| cleanup | false | If false, won't delete configuration files downloaded after loading to GITHUB_ENV (default: true) | `cleanup: false` | | ||
|
||
Click the `Use this Template` and provide the new repo details for your action | ||
|
||
## Code in Main | ||
## Usage | ||
|
||
Install the dependencies | ||
This action allows many directory structure in your configserver. | ||
This section illustrates dotenv-configserver configurations according to common examples of configserver directory structures: | ||
|
||
```bash | ||
npm install | ||
``` | ||
### Basic | ||
|
||
Run the tests :heavy_check_mark: | ||
Configserver: | ||
<pre> | ||
(main branch) | ||
|_ .env | ||
</pre> | ||
|
||
```bash | ||
$ npm test | ||
Github Action: | ||
|
||
PASS ./index.test.js | ||
✓ throws invalid number (3ms) | ||
✓ wait 500 ms (504ms) | ||
✓ test runs (95ms) | ||
... | ||
```yaml | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout" | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Launch action" | ||
uses: Steph0/dotenv-configserver | ||
with: | ||
repository: "Steph0/test-configserver" | ||
token: "${{ secrets.ACTION_TOKEN }}" | ||
|
||
# You should see your .env config in 'env' | ||
- name: "See exported values" | ||
run: env | ||
``` | ||
## Change action.yml | ||
### Flat | ||
The action.yml defines the inputs and output for your action. | ||
Configserver: | ||
Update the action.yml with your name, description, inputs and outputs for your action. | ||
<pre> | ||
(main branch) | ||
|_ dev.env | ||
|_ staging.env | ||
|_ prod.env | ||
</pre> | ||
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) | ||
Github Action: | ||
## Change the Code | ||
```yaml | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout" | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Launch action" | ||
uses: Steph0/dotenv-configserver | ||
with: | ||
repository: "Steph0/test-configserver" | ||
token: "${{ secrets.ACTION_TOKEN }}" | ||
# Will look for 'prod.env' | ||
profile: "prod" | ||
|
||
# You should see your .env config in 'env' | ||
- name: "See exported values" | ||
run: env | ||
``` | ||
Most toolkit and CI/CD operations involve async operations so the action is run in an async function. | ||
### Env per branch | ||
```javascript | ||
const core = require('@actions/core'); | ||
... | ||
Configserver: | ||
<pre> | ||
(main branch) | ||
|_ .env | ||
async function run() { | ||
try { | ||
... | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
(dev branch) | ||
|_ .env | ||
</pre> | ||
run() | ||
Github Action: | ||
```yaml | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout" | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Launch action" | ||
uses: Steph0/dotenv-configserver | ||
with: | ||
repository: "Steph0/test-configserver" | ||
token: "${{ secrets.ACTION_TOKEN }}" | ||
# Will checkout 'dev' branch | ||
branch: "dev" | ||
|
||
# You should see your .env config in 'env' | ||
- name: "See exported values" | ||
run: env | ||
``` | ||
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. | ||
## Package for distribution | ||
### Nested directories | ||
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules. | ||
Configserver: | ||
<pre> | ||
(main branch) | ||
|_ front | ||
|_ application-prod.env | ||
|_ backend | ||
|_ application-prod.env | ||
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder. | ||
(dev branch) | ||
|_ front | ||
|_ application-dev.env | ||
|_ backend | ||
|_ application-dev.env | ||
</pre> | ||
Run prepare | ||
Github Action: | ||
```bash | ||
npm run prepare | ||
```yaml | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout" | ||
id: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: "Launch action" | ||
uses: Steph0/dotenv-configserver | ||
with: | ||
repository: "Steph0/test-configserver" | ||
token: "${{ secrets.ACTION_TOKEN }}" | ||
# Will checkout 'dev' branch | ||
branch: "dev" | ||
# Look for backend conf | ||
directory: backend | ||
# Override default filename | ||
filename: "application" # or `application.env` | ||
# Insert profile in filename (eg: application-dev.env) | ||
profile: "dev" | ||
|
||
# You should see your .env config in 'env' | ||
- name: "See exported values" | ||
run: env | ||
``` | ||
Since the packaged index.js is run from the dist folder. | ||
## Development | ||
Install | ||
```bash | ||
git add dist | ||
# Install dependencies | ||
npm install | ||
# Build action | ||
npm run all | ||
``` | ||
|
||
## Create a release branch | ||
|
||
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions. | ||
|
||
Checkin to the v1 release branch | ||
You can test actions locally using [ACT](https://github.com/nektos/act). | ||
Example: | ||
|
||
```bash | ||
git checkout -b v1 | ||
git commit -a -m "v1 release" | ||
# 'test.secrets' is a local file (automatically ignored) containing secrets like your Github PAT | ||
npm run prepare && \ | ||
act workflow_dispatch -e ./.github/workflows/act-test.event -b --secret-file ./.github/workflows/test.secrets | ||
``` | ||
|
||
```bash | ||
git push origin v1 | ||
``` | ||
## Inspiration | ||
|
||
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project. | ||
This project took great inspiration from: | ||
|
||
Your action is now published! :rocket: | ||
* [xom9ikk/dotenv](https://github.com/xom9ikk/dotenv) | ||
* [actions/checkout](https://github.com/actions/checkout) | ||
* [spring-cloud-config](https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.3.2.RELEASE/#_locating_remote_configuration_resources) | ||
|
||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) | ||
Heavily based also on the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages). | ||
|
||
## Usage | ||
## Contribute | ||
|
||
You can now consume the action by referencing the v1 branch | ||
Feel free to ask for support or features requests in the Issues tab of the project repository. | ||
|
||
```yaml | ||
uses: actions/javascript-action@v1 | ||
with: | ||
milliseconds: 1000 | ||
``` | ||
Contributions (bug fixes, new features) are welcomed! | ||
|
||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket: | ||
License: MIT |
Oops, something went wrong.