From d76c63002a11dbd2b2d7aeb0bc080a93f4a91b09 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:58:51 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20feat:=20Add=20support=20for=20e?= =?UTF-8?q?nvironment=20variables=20in=20deployment=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + action.yml | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5edbc94..4ebaf13 100644 --- a/README.md +++ b/README.md @@ -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 }}"` | ### 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. diff --git a/action.yml b/action.yml index 90cbfe7..5987906 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,11 @@ inputs: description: True to create a persistent filesystem for the app. type: boolean required: false - + env_vars: + description: Environment variables to add. Separate multiple variables with a space. + required: false + type: string + runs: @@ -138,6 +142,12 @@ runs: shell: bash if: github.event.action != 'closed' run: | + # Split the environment variables by space and add them + IFS=' ' read -r -a env_vars_array <<< "${{ inputs.env_vars }}" + for env_var in "${env_vars_array[@]}" + do + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-environment-variable "$env_var" + done de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-group-co-owner "${{ inputs.group_co_owners }}" --add-group-viewer "${{ inputs.group_viewers }}" env: From d13c15ea4a33f23dab657cc72c6bb35bc709a2d6 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:01:53 +0100 Subject: [PATCH 2/6] chore: Update de-deploy action to use main branch instead of v2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ebaf13..97fa915 100644 --- a/README.md +++ b/README.md @@ -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 }} From af9936a587960573c7ebf3bd50dfbd6f94af5ee1 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Tue, 11 Jun 2024 13:33:08 +0100 Subject: [PATCH 3/6] rework DE ENV VARS approach --- action.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 5987906..7c47580 100644 --- a/action.yml +++ b/action.yml @@ -45,13 +45,11 @@ inputs: description: True to create a persistent filesystem for the app. type: boolean required: false - env_vars: - description: Environment variables to add. Separate multiple variables with a space. + DE_ENV_VAR: + description: Environment variables to set for the app. List of name-value pairs. required: false type: string - - runs: using: composite steps: @@ -105,6 +103,16 @@ 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 + shell: bash + run: | + for env_var in "${DE_ENV_VAR[@]}"; do + name=$(echo $env_var | jq -r '.name') + value=$(echo $env_var | jq -r '.value') + de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-environment-variable "$name=$value" + done + env: + DE_ENV_VAR: ${{ toJson(inputs.DE_ENV_VAR) }} - name: Create Redis shell: bash if: ${{ inputs.create_redis }} @@ -142,12 +150,6 @@ runs: shell: bash if: github.event.action != 'closed' run: | - # Split the environment variables by space and add them - IFS=' ' read -r -a env_vars_array <<< "${{ inputs.env_vars }}" - for env_var in "${env_vars_array[@]}" - do - de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-environment-variable "$env_var" - done de --no-keyfile deploy ${{ inputs.app_directory }} --name ${{ steps.app_name.outputs.app_name }} --message "Deployed commit: $GITHUB_SHA" -y de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-group-co-owner "${{ inputs.group_co_owners }}" --add-group-viewer "${{ inputs.group_viewers }}" env: @@ -164,7 +166,6 @@ runs: DASH_ENTERPRISE_HOST: ${{inputs.DE_HOST}} DASH_ENTERPRISE_USERNAME: ${{inputs.DE_USERNAME}} - branding: icon: activity color: purple From 27de5f82de13ea56371a0d8e04ee222c64916de8 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Tue, 11 Jun 2024 13:33:27 +0100 Subject: [PATCH 4/6] fix group_viewers type typo --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7c47580..7f268fc 100644 --- a/action.yml +++ b/action.yml @@ -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 From 92c9192305051ca23b0c030aa4dc62d2e2a815a3 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Tue, 11 Jun 2024 13:40:34 +0100 Subject: [PATCH 5/6] improve env vars structure --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 7f268fc..1d58661 100644 --- a/action.yml +++ b/action.yml @@ -48,7 +48,8 @@ inputs: DE_ENV_VAR: description: Environment variables to set for the app. List of name-value pairs. required: false - type: string + type: array + default: [] runs: using: composite @@ -112,7 +113,7 @@ runs: de --no-keyfile apps update --name ${{ steps.app_name.outputs.app_name }} --add-environment-variable "$name=$value" done env: - DE_ENV_VAR: ${{ toJson(inputs.DE_ENV_VAR) }} + DE_ENV_VAR: ${{ inputs.DE_ENV_VAR }} - name: Create Redis shell: bash if: ${{ inputs.create_redis }} From 7f49f3615556f93817f1f7b686790b21017b67d1 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:05:47 +0100 Subject: [PATCH 6/6] improve env vars structure --- action.yml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index 1d58661..4bc8925 100644 --- a/action.yml +++ b/action.yml @@ -45,11 +45,6 @@ inputs: description: True to create a persistent filesystem for the app. type: boolean required: false - DE_ENV_VAR: - description: Environment variables to set for the app. List of name-value pairs. - required: false - type: array - default: [] runs: using: composite @@ -104,16 +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 - shell: bash - run: | - for env_var in "${DE_ENV_VAR[@]}"; do - name=$(echo $env_var | jq -r '.name') - value=$(echo $env_var | jq -r '.value') + - 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" - done - env: - DE_ENV_VAR: ${{ inputs.DE_ENV_VAR }} - name: Create Redis shell: bash if: ${{ inputs.create_redis }}