Skip to content

Feature/adding environement variables #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ jobs:

> Note GITHUB_TOKEN is not needed for the `destroy` action

### Custom Environment Variables

You can pass custom environment variables to the Heroku Review App by using the custom-env-vars input in your workflow file. This allows you to set specific environment variables for your review app, which can be useful for testing different configurations.

```yml
name: Review App with Custom Variables
on:
pull_request:
types: [labeled]

jobs:
create-review-app:
if: ${{ github.event.label.name == 'create-review-app' }}
runs-on: ubuntu-latest

steps:
- uses: fastruby/manage-heroku-review-app@v1.3
with:
action: create
custom-env-vars: |
API_URL=https://staging.api.example.com
FEATURE_FLAG=true
env:
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
HEROKU_PIPELINE_ID: ${{ secrets.HEROKU_PIPELINE_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

# Configuration

## Inputs:
Expand All @@ -60,6 +88,7 @@ jobs:

- `create` will trigger a Review App creation for the current PR, will fail if the Review App already exists
- `destroy` will trigger a Review App destroy for the current PR, if any
- `custom-env-vars` (optional) This input allows you to define environment variables to be passed to the Review App. The format should be a multiline string where each line represents a variable (VAR_NAME=value).

> Review Apps will be re-deployed automatically after a new push, there's no need to trigger any action

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: 'One of: "create" or "destroy"'
required: true
default: "create"
custom-env-vars:
description: "Optional environment variables for the Heroku Review App (format: VAR1=value1 VAR2=value2)"
required: false
default: ""
runs:
using: "node12"
main: "dist/index.js"
17 changes: 17 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9183,6 +9183,20 @@ function run() {
return;
}
});
const parseCustomVariables = () => {
const customVarsInput = core.getInput("custom-env-vars");
const customVars = {};
if (customVarsInput) {
const lines = customVarsInput.split("\n");
lines.forEach((line) => {
const [key, value] = line.split("=");
if (key && value) {
customVars[key.trim()] = value.trim();
}
});
}
return customVars;
};
const createReviewApp = () => __awaiter(this, void 0, void 0, function* () {
core.debug("init octokit");
if (!process.env.GITHUB_TOKEN) {
Expand All @@ -9201,6 +9215,7 @@ function run() {
ref: branch,
});
try {
const customVars = parseCustomVariables(); // Parse the custom variables
core.info("Creating Review App");
core.debug(JSON.stringify({
branch,
Expand All @@ -9210,6 +9225,7 @@ function run() {
version,
},
pr_number,
customVars
}));
const response = yield heroku.post("/review-apps", {
body: {
Expand All @@ -9220,6 +9236,7 @@ function run() {
version,
},
pr_number,
environment: customVars,
},
});
core.debug(response);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading