Skip to content

Flex Deploy

Flex Deploy #537

Workflow file for this run

# Copyright (C) 2021-2023 Technology Matters
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.
# Publish a Twilio Flex-plugins with Github Actions
name: Flex Deploy
on:
workflow_dispatch:
inputs:
helpline_code:
description: The short (usually 2 character) upper case code used to identify the helpline internally, e.g. ZA, IN, BR.
required: true
type: string
environment_code:
description: Flex-plugins environment to deploy
required: true
type: choice
options:
- development
- staging
- production
self-hosted-deploy-bool:
description: If set to true, we will point the account at our s3 hosted version of the plugin rather than uploading it to Twilio.
type: boolean
workflow_call:
inputs:
helpline_code:
description: The short (usually 2 character) upper case code used to identify the helpline internally, e.g. ZA, IN, BR.
required: true
type: string
environment_code:
description: Flex-plugins environment to deploy
required: true
type: string
send-slack-message:
description: If set to false a slack message will not be sent - useful for E2E test deploys.
default: 'true'
type: string
self-hosted-deploy:
description: If set to true, we will point the account at our s3 hosted version of the plugin rather than uploading it to Twilio.
default: 'false'
type: string
invalidate-forms-cache:
description: 'Specifies if should invalidate CloudFront cache for form data. Defaults to true, set to false if the caller will handle cache invalidation.'
required: false
default: 'true'
type: string
env:
SELF_HOSTED_DEPLOY: ${{ inputs.self-hosted-deploy || inputs.self-hosted-deploy-bool }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Can be removed once we drop support for Twilio hosted plugins
- name: Use Node.js
# if: env.SELF_HOSTED_DEPLOY != 'true'
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
# Set ENVIRONMENT_NAME
- name: Set Helpline Environment
run: echo "ENVIRONMENT_NAME=${{inputs.environment_code}}" >> $GITHUB_ENV
- name: Set Twilio account SID
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "/${{env.ENVIRONMENT_NAME}}/twilio/${{inputs.helpline_code}}/account_sid"
env_variable_name: "TWILIO_ACCOUNT_SID"
- name: Set Twilio Auth Token
uses: "marvinpinto/action-inject-ssm-secrets@latest"
with:
ssm_parameter: "/${{env.ENVIRONMENT_NAME}}/twilio/${{env.TWILIO_ACCOUNT_SID}}/auth_token"
env_variable_name: "TWILIO_AUTH_TOKEN"
# Call main-action to compile and deploy secrets.AS_DEV_ACCOUNT_SID
- if: env.SELF_HOSTED_DEPLOY != 'true'
name: Executing main-action
uses: ./.github/actions/main-action
with:
account-sid: ${{env.TWILIO_ACCOUNT_SID}}
auth-token: ${{env.TWILIO_AUTH_TOKEN}}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
helpline-id: ${{inputs.helpline_code}}_${{inputs.environment_code}}
helpline_code: ${{inputs.helpline_code}}
environment: ${{inputs.environment_code}}
send-slack-message: ${{ inputs.send-slack-message }}
- if: env.SELF_HOSTED_DEPLOY != 'true'
name: Configure Account to use Twilio Hosted Plugin
shell: bash
run: |
curl --location 'https://flex-api.twilio.com/v1/Configuration' \
--header 'Content-Type: application/json' \
-u '${{env.TWILIO_ACCOUNT_SID}}:${{env.TWILIO_AUTH_TOKEN}}' \
--data '{
"account_sid": "${{env.TWILIO_ACCOUNT_SID}}",
"plugin_service_attributes":null
}'
# Install the Twilio CLI and the flex plugin, then disable the twilio hosted plugin
# These steps can be removed once Twilio hosted flex plugins are fully retired
# Ridiculous that we need top run from the plugin source with dependencies installed just to disable it on Twilio, but that seems to be the situation
- name: Install Flex Plugin
uses: ./.github/actions/install-flex-plugin
- if: env.SELF_HOSTED_DEPLOY == 'true'
name: Disable the Aselo plugin deployed to Twilio, if there is one.
run: twilio flex:plugins:release --disable-plugin=plugin-hrm-form -l debug || true
shell: bash
working-directory: ./plugin-hrm-form
# Point the account at the s3 hosted plugin
- if: env.SELF_HOSTED_DEPLOY == 'true'
name: Configure Account to point to S3 Hosted Plugin
shell: bash
run: |
curl --location 'https://flex-api.twilio.com/v1/Configuration' \
--header 'Content-Type: application/json' \
-u '${{env.TWILIO_ACCOUNT_SID}}:${{env.TWILIO_AUTH_TOKEN}}' \
--data '{
"account_sid": "${{env.TWILIO_ACCOUNT_SID}}",
"plugin_service_attributes":{
"custom_plugins": [{"name": "HRM Forms", "version": "0.0.1", "src": "https://assets-${{ inputs.environment_code }}.tl.techmatters.org/plugins/hrm-form/${{ github.ref_type }}/${{ github.ref_name }}/plugin-hrm-form.js"}]
}
}'
# Update deployment matrix with script and ssm parameters
- name: Update deployment matrix
if: env.SELF_HOSTED_DEPLOY == 'true'
uses: ./.github/actions/deployment-matrix
with:
account-sid: ${{env.TWILIO_ACCOUNT_SID}}
auth-token: ${{env.TWILIO_AUTH_TOKEN}}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
identifier: ${{ inputs.helpline_code }}
environment: ${{ inputs.environment_code}}
service_repo: 'flex-plugins'
version_tag: ${{ github.ref_name }}
deploy_form_definitions:
uses: ./.github/workflows/deploy-form-definitions.yml
needs: deploy
secrets: inherit
with:
helpline_code: ${{ inputs.helpline_code }}
environment: ${{ inputs.environment_code }}
send-slack-message: 'false'
invalidate-cache: ${{ inputs.invalidate-forms-cache }}