Skip to content

Commit

Permalink
Refactor determining target helplines as an action
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Aug 29, 2023
1 parent 6f68c21 commit b4fbe5b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
47 changes: 47 additions & 0 deletions .github/actions/determine-target-helplines-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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/.

# Install the Twilio CLI and the serverless plugin then deploy the function
name: 'determine-target-helplines-action'
description: 'Install the Twilio CLI and the serverless plugin then deploy the function'
inputs:
environment:
description: The environment to deploy to, e.g. staging, production, development
required: true
outputs:
target_helplines:
description: 'The short codes of each helpline in the target environment as a JSON array string'
value: ${{ steps.determine-target-helplines.outputs.target_helplines }}
runs:
using: 'composite'
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Determine helplines to deploy
id: determine-target-helplines
shell: bash
run: |
environment=${( inputs.environment }}
# Fetch all parameters under the path '/${environment}/twilio'
ssm_parameters=$(aws ssm get-parameters-by-path --path "/${environment}/twilio" --recursive --query "Parameters[].Name" --output json)
# Use jq to filter out parameters that match the pattern and extract accounts into an array
helplines=$(echo $ssm_parameters | jq -c 'map(select(test("/'$environment'/twilio/[^/]+/account_sid")) | gsub("/'$environment'/twilio/";"") | gsub("/account_sid";""))')
# Set the GitHub Actions output
echo "target_helplines=$helplines" >> $GITHUB_OUTPUT
15 changes: 7 additions & 8 deletions .github/workflows/deploy-all-production-accounts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ on:

jobs:
configure:
name: Load Configuration
name: Determine Configuration
runs-on: ubuntu-latest
outputs:
production_helplines: ${{ steps.read-config.outputs.production_helplines }}
target_helplines: ${{ steps.determine-target-helplines.outputs.target_helplines }}
steps:
- name: Checkout
uses: actions/checkout@v3
- id: read-config
run: |
content=`jq -c '.' ./.github/workflows/config/production-helplines.json`
echo "production_helplines=$content" >> $GITHUB_OUTPUT
id: determine-target-helplines
name: Executing main-action
uses: ./.github/actions/determine-target-helplines-action
with:
environment: production
deploy-helplines:
name: Run All Production Deployments
needs: configure
Expand Down
27 changes: 7 additions & 20 deletions .github/workflows/deploy-all-staging-accounts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,19 @@ jobs:
name: Determine Configuration
runs-on: ubuntu-latest
outputs:
staging_helplines: ${{ steps.determine-target-helplines.outputs.staging_helplines }}
target_helplines: ${{ steps.determine-target-helplines.outputs.target_helplines }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Determine staging helplines to deploy
id: determine-target-helplines
run: |
environment=staging
# Fetch all parameters under the path '/${environment}/twilio'
ssm_parameters=$(aws ssm get-parameters-by-path --path "/${environment}/twilio" --recursive --query "Parameters[].Name" --output json)
# Use jq to filter out parameters that match the pattern and extract accounts into an array
helplines=$(echo $ssm_parameters | jq -c 'map(select(test("/'$environment'/twilio/[^/]+/account_sid")) | gsub("/'$environment'/twilio/";"") | gsub("/account_sid";""))')
# Set the GitHub Actions output
echo "staging_helplines=$helplines" >> $GITHUB_OUTPUT
id: determine-target-helplines
name: Executing main-action
uses: ./.github/actions/determine-target-helplines-action
with:
environment: staging
deploy-helplines:
name: Run All Staging Deployments
needs: configure
uses: ./.github/workflows/deploy-multiple-accounts.yml
secrets: inherit
with:
helplines: ${{ needs.configure.outputs.staging_helplines }}
helplines: ${{ needs.configure.outputs.target_helplines }}
environments: '[ "STG" ]'

0 comments on commit b4fbe5b

Please sign in to comment.