Deploy form-definitions to S3 #21
Workflow file for this run
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
# 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/. | |
name: 'Deploy form-definitions to S3' | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: Environment to deploy | |
default: development | |
required: true | |
type: choice | |
options: | |
- development | |
- staging | |
- production | |
helpline_code: | |
description: Short helpline code | |
type: string | |
required: true | |
# version could be added in the future once we have more versions. For now, we only have one version. | |
workflow_call: | |
secrets: | |
AWS_ACCESS_KEY_ID: | |
required: true | |
AWS_SECRET_ACCESS_KEY: | |
required: true | |
inputs: | |
environment: | |
description: Environment to deploy. E.G = development, staging, production (must match with the AWS environment value). Default value = development | |
type: string | |
default: development | |
required: true | |
helpline_code: | |
description: Short helpline code Default value = as | |
type: string | |
default: as | |
required: true | |
send-slack-message: | |
description: 'Specifies if should send a Slack message at the end of successful run. Defaults to true' | |
required: false | |
default: 'true' | |
type: string | |
jobs: | |
deploy_form_definitions: | |
name: Deploy form-definitions to S3 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Validate and normalize input variables | |
run: bash .github/scripts/setupDeployFormDefinitionsEnv.sh ${{ inputs.environment }} ${{ inputs.helpline_code }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Deploy form-definitions to S3 | |
run: | | |
aws s3 sync ${{ env.helpline_dir }} s3://${{ env.s3_bucket }}/${{ env.path }} --acl public-read | |
CF_DISTRO=$(aws cloudfront list-distributions --query "DistributionList.Items[*].{id:Id,origin:Origins.Items[0].DomainName}[?origin=='${{ env.s3_bucket }}.s3-website.us-east-1.amazonaws.com'].id" --output text) | |
aws cloudfront create-invalidation --distribution-id $CF_DISTRO --paths /${{ env.path }}/* | |
# Set any env vars needed from Parameter Store here | |
- name: Set GITHUB_ACTIONS_SLACK_BOT_TOKEN | |
uses: 'marvinpinto/action-inject-ssm-secrets@latest' | |
with: | |
ssm_parameter: 'GITHUB_ACTIONS_SLACK_BOT_TOKEN' | |
env_variable_name: 'GITHUB_ACTIONS_SLACK_BOT_TOKEN' | |
- name: Set ASELO_DEPLOYS_CHANNEL_ID | |
uses: 'marvinpinto/action-inject-ssm-secrets@latest' | |
with: | |
ssm_parameter: 'ASELO_DEPLOYS_CHANNEL_ID' | |
env_variable_name: 'ASELO_DEPLOYS_CHANNEL_ID' | |
# Send Slack notifying success | |
- name: Slack Aselo channel | |
id: slack | |
uses: slackapi/slack-github-action@v1.14.0 | |
with: | |
channel-id: ${{ env.ASELO_DEPLOYS_CHANNEL_ID }} | |
slack-message: '`[Flex]` Deployment of ${{ github.ref_type }} `${{ github.ref_name }}` requested by `${{ github.triggering_actor }}` completed with SHA ${{ github.sha }}, helpine: `${{ env.helpline_code }}, environment `${{ env.environment }}` :rocket:.' | |
env: | |
SLACK_BOT_TOKEN: ${{ env.GITHUB_ACTIONS_SLACK_BOT_TOKEN }} | |
if: ${{ inputs.send-slack-message != 'false' }} |