chore: Update GitHub Actions deploy workflows for AWS credentials #95
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
name: Main | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Setup job workspace | |
uses: ServerlessOpsIO/gha-setup-workspace@v1 | |
- name: Setup Python environment | |
uses: ServerlessOpsIO/gha-setup-python@v1 | |
with: | |
python_version: 3.12 | |
- name: Assume AWS Credentials | |
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1 | |
with: | |
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }} | |
gha_build_role_name: ${{ secrets.AWS_CICD_BUILD_ROLE_NAME }} | |
- name: Install AWS SAM | |
uses: aws-actions/setup-sam@v2 | |
# FIXME: We're only validating the top-level template and not the rest. | |
- name: Validate artifact | |
run: sam validate --lint | |
- name: Synethsize StackSet templates | |
run: | | |
for _f in $(find . -type f -name 'stackset.yaml'); do | |
_dir="$(dirname $_f)/" \ | |
yq \ | |
-i \ | |
'(.. | select(has("localTemplateFile")) | .localTemplateFile) |= load_str(strenv(_dir) + .)' \ | |
$_f; | |
done | |
- name: Upload SAM artifact | |
id: upload-sam-template | |
shell: bash | |
run: | | |
sam package \ | |
--template template.yaml \ | |
--s3-bucket aws-sam-cli-sourcebucket-346402060170-us-east-1 \ | |
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \ | |
--region us-east-1 \ | |
--output-template-file packaged-template.yaml | |
- name: Upload SAM artifact | |
id: upload-sam-stackset-template | |
shell: bash | |
run: | | |
sam package \ | |
--template delegate-template.yaml \ | |
--s3-bucket aws-sam-cli-sourcebucket-346402060170-us-east-1 \ | |
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \ | |
--region us-east-1 \ | |
--output-template-file packaged-delegate-template.yaml | |
- name: 'Upload pipeline artifact' | |
id: upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.GITHUB_REPOSITORY_SLUG }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.run_number }}-${{ github.sha }} | |
path: | | |
**/* | |
!.aws-sam/build | |
!**/.terraform/providers | |
!node_modules | |
!.git | |
if-no-files-found: error | |
retention-days: 30 | |
deploy_management: | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Setup job workspace | |
uses: ServerlessOpsIO/gha-setup-workspace@v1 | |
- name: Setup Python enviornment | |
uses: ServerlessOpsIO/gha-setup-python@v1 | |
with: | |
python_version: 3.12 | |
- name: Assume AWS Credentials | |
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1 | |
with: | |
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }} | |
gha_build_role_name: ${{ secrets.AWS_CICD_BUILD_ROLE_NAME }} | |
deploy_aws_account_id: ${{ secrets.AWS_MANAGEMENT_ACCOUNT_ID }} | |
gha_deploy_role_name: ${{ secrets.AWS_CICD_DEPLOY_ROLE_NAME }} | |
- name: Install AWS SAM | |
uses: aws-actions/setup-sam@v2 | |
- name: Process AWS Tags | |
id: processaws-tags | |
shell: bash | |
run: >- | |
AWS_CFN_TAGS=$( | |
cat cfn-tags.json | | |
jq -r ' | |
to_entries | | |
map("\(.key)=\(.value|tostring)") | | |
. += [ | |
"org:branch=${{ env.GITHUB_EVENT_REF_SLUG_URL }}", | |
"org:stackName=${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}" | |
] | | |
join(" ") | |
' | |
) && | |
echo "AWS_CFN_TAGS=--tags ${AWS_CFN_TAGS}">> $GITHUB_ENV | |
- name: Process AWS Cloudformation Parameters | |
id: process-aws-parameters | |
shell: bash | |
env: | |
GHA_SECRETS: ${{ tojson(secrets) }} | |
GHA_ENV: ${{ toJson(env) }} | |
run: >- | |
AWS_CFN_PARAMS=$( | |
jq \ | |
-n \ | |
--argjson secrets "$GHA_SECRETS" \ | |
--argjson env "$GHA_ENV" \ | |
-f cfn-parameters.json | | |
jq \ | |
-r ' | |
to_entries | | |
map("\(.key)=\(.value|tostring)") | | |
join(" ") | |
' | |
) && | |
echo "AWS_CFN_PARAMS=--parameter-overrides ${AWS_CFN_PARAMS}" >> $GITHUB_ENV | |
- name: Deploy via SAM | |
id: deploy-sam | |
shell: bash | |
run: | | |
sam deploy \ | |
--template-file packaged-template.yaml \ | |
--stack-name ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }} \ | |
--s3-bucket aws-sam-cli-sourcebucket-346402060170-us-east-1 \ | |
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \ | |
--region us-east-1 \ | |
--role-arn arn:aws:iam::349603509961:role/CfnExecIamRole \ | |
--on-failure DELETE \ | |
$AWS_CFN_PARAMS \ | |
$AWS_CFN_TAGS | |
deploy_delegate: | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Setup job workspace | |
uses: ServerlessOpsIO/gha-setup-workspace@v1 | |
- name: Setup Python enviornment | |
uses: ServerlessOpsIO/gha-setup-python@v1 | |
with: | |
python_version: 3.12 | |
- name: Assume AWS Credentials | |
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1 | |
with: | |
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }} | |
gha_build_role_name: ${{ secrets.AWS_CICD_BUILD_ROLE_NAME }} | |
deploy_aws_account_id: ${{ secrets.AWS_STACKSETS_ACCOUNT_ID }} | |
gha_deploy_role_name: ${{ secrets.AWS_CICD_DEPLOY_ROLE_NAME }} | |
- name: Install AWS SAM | |
uses: aws-actions/setup-sam@v2 | |
- name: Process AWS Tags | |
id: processaws-tags | |
shell: bash | |
run: >- | |
AWS_CFN_TAGS=$( | |
cat cfn-tags.json | | |
jq -r ' | |
to_entries | | |
map("\(.key)=\(.value|tostring)") | | |
. += [ | |
"org:branch=${{ env.GITHUB_EVENT_REF_SLUG_URL }}", | |
"org:stackName=${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}" | |
] | | |
join(" ") | |
' | |
) && | |
echo "AWS_CFN_TAGS=--tags ${AWS_CFN_TAGS}">> $GITHUB_ENV | |
- name: Process AWS Cloudformation Parameters | |
id: process-aws-parameters | |
shell: bash | |
env: | |
GHA_SECRETS: ${{ tojson(secrets) }} | |
GHA_ENV: ${{ toJson(env) }} | |
run: >- | |
AWS_CFN_PARAMS=$( | |
jq \ | |
-n \ | |
--argjson secrets "$GHA_SECRETS" \ | |
--argjson env "$GHA_ENV" \ | |
-f cfn-parameters.json | | |
jq \ | |
-r ' | |
to_entries | | |
map("\(.key)=\(.value|tostring)") | | |
join(" ") | |
' | |
) && | |
echo "AWS_CFN_PARAMS=--parameter-overrides ${AWS_CFN_PARAMS}" >> $GITHUB_ENV | |
- name: Deploy via SAM | |
id: deploy-sam | |
shell: bash | |
run: | | |
sam deploy \ | |
--template-file packaged-delegate-template.yaml \ | |
--stack-name ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }} \ | |
--s3-bucket aws-sam-cli-sourcebucket-346402060170-us-east-1 \ | |
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \ | |
--region us-east-1 \ | |
--role-arn arn:aws:iam::774305573766:role/CfnExecIamRole \ | |
--on-failure DELETE \ | |
$AWS_CFN_PARAMS \ | |
$AWS_CFN_TAGS |