Skip to content

✨ feat: Add support for environment variables in deployment action #21

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 6 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: plotly/de-deploy@v2
- uses: plotly/de-deploy@main
with:
DE_HOST: ${{ secrets.DE_HOST }}
DE_USERNAME: ${{ secrets.DE_USERNAME }}
Expand All @@ -55,6 +55,7 @@ The inputs this action uses are:
| `create_redis` | `false` | None | True to create a Redis instance for the app. |
| `create_postgres` | `false` | None | True to create a Postgres instance for the app. |
| `create_persistent_filesystem` | `false` | None | True to create a persistent filesystem for the app. |
| `env_vars` | `false` | None | Environment variables to add. Separate multiple variables with a space. Example: `env_vars: "FOO=BAR FOO_SECRET=${{ secrets.FOO_SECRET }}"` |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work without quotation marks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current design, no. Without string, it would not be possible to split them. But er cam change it

To make it more transparent/less error prone, we can do this:

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    strategy:
      matrix:
        env_var:
          - name: "FOO"
            value: "BAR"
          - name: "FOO_SECRET"
            value: "${{ secrets.FOO_SECRET }}"

  

Or

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: plotly/de-deploy@add-adding-env-variables
        with:
           env_vars: FOO=BAR FOO_SECRET=${{ secrets.FOO_SECRET }}

Or

name: Deploy to Dash Enterprise

on:
  push:
    branches:
      - main

jobs:
  deploy:
    name: 'Deploy to Dash Enterprise'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: plotly/de-deploy@add-adding-env-variables
        with:
          env_vars: |
            FOO=BAR
            FOO_SECRET=${{ secrets.FOO_SECRET }}

(Note that | must be there)

What do you think?


### Preview deploy on pull request
This action will deploy branches using the `on: pull_request: types: ['opened', 'edited', 'synchronize', 'closed']` trigger as `https://${DE_HOST}/${APP_NAME}-${event_number}`, e.g. if you are deploying an app called `inventory-analytics` to `example.plotly.host` and your PR number is `15`, the deploy preview would be available at `https://example.plotly.host/inventory-analytics-15` and would be redeployed on every new commit to that PR.
Expand Down
12 changes: 7 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inputs:
group_viewers:
description: User groups to add as viewers to the app. If not provided, no groups will be added.
required: false
type: strong
type: string
group_co_owners:
description: User groups to add as co-owners to the app. If not provided, no groups will be added.
type: boolean
Expand All @@ -45,9 +45,7 @@ inputs:
description: True to create a persistent filesystem for the app.
type: boolean
required: false




runs:
using: composite
steps:
Expand Down Expand Up @@ -101,6 +99,11 @@ runs:
-H "X-GitHub-Api-Version: 2022-11-28"\
https://api.github.com/repos/${{ github.repository }}/statuses/${{github.event.pull_request.head.sha || github.sha}}\
-d '{"state":"success","target_url":"https://${{ inputs.DE_HOST }}/apps/${{ steps.app_name.outputs.app_name }}","description":"App manager ready!","context":"deploy/${{ steps.app_name.outputs.app_name }}"}'
- name: Set environment variables
run: |
name=${{ matrix.env_var.name }}
value=${{ matrix.env_var.value }}
de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-environment-variable "$name=$value"
- name: Create Redis
shell: bash
if: ${{ inputs.create_redis }}
Expand Down Expand Up @@ -154,7 +157,6 @@ runs:
DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}}
DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}}


branding:
icon: activity
color: purple