Skip to content

Cloudformation Template Sync #1

Cloudformation Template Sync

Cloudformation Template Sync #1

Workflow file for this run

name: Cloudformation Template Sync
on:
workflow_dispatch:
workflow_run:
workflows: ["Publish"]
types:
- completed
env:
REPO_BUCKET_PREFIX: coralogix-serverless-repo
REPO_PACKAGE_ZIP: coralogix-aws-shipper.zip
CFN_INTEGRATION_DIR: aws-integrations/aws-shipper-lambda
CLOUDFORMATION_REPO: coralogix/cloudformation-coralogix-aws
jobs:
get-template:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch'}}
steps:
- name: checkout coralogix-aws-shipper repository
uses: actions/checkout@v4
- name: get last commit_message
id: commits
run: |
last_pr_name=$(curl -s -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
"https://api.github.com/repos/coralogix/coralogix-aws-shipper/pulls?state=closed&base=master&sort=updated&direction=desc" \
| jq -r '.[0].title')
echo last_commit=$last_pr_name >> $GITHUB_OUTPUT
- run: sudo snap install yq
# Update the CodeUri property of all AWS::Serverless::Function resources using Yq
- uses: actions/checkout@v4
- name: update-template
run: |
set -xv
# add CpuArch param
yq -i '.Parameters.CpuArch |= {
"Type": "String",
"AllowedValues": ["x86_64", "arm64"],
"Default": "arm64"
} | .Globals.Function.Architectures = [ {"Ref": "CpuArch"} ]' ./template.yaml
# add CpuArch Condition
yq -i '.Conditions.CpuArchIsx8664 = {
"Fn::Equals": [
{ "Ref": "CpuArch"},
"x86_64" ]
}' ./template.yaml
# update the CodeUri property of all AWS::Serverless::Function resources
# based on the CpuArch condition
yq -i '(.Resources[] |
select(
has("Type")
and .Type == "AWS::Serverless::Function"
and .Properties.CodeUri != null) |
.Properties.CodeUri) |= {
"Bucket": {"Fn::Sub": "coralogix-aws-shipper-${AWS::Region}"},
"Key": {
"Fn::If": [
"CpuArchIsx8664",
"coralogix-aws-shipper-x86-64.zip",
"coralogix-aws-shipper.zip"
]
}
}' template.yaml
# sed -i '3a\#Created automatically from coralogix\/coralogix-aws-shipper' ./template.yaml
# sed -i '4a\#Link to the repo: https:\/\/github.com\/coralogix\/coralogix-aws-shipper\/tree\/master/' ./template.yaml
sed -i '9a\ Created automatically from [coralogix-aws-shipper](https:\/\/github.com\/coralogix\/coralogix-aws-shipper) . To make a change to the template please go to the this [link](https:\/\/github.com\/coralogix\/coralogix-aws-shipper\/blob\/master\/template.yaml)' ./README.md
sed -i '10a\ ' ./README.md
cat ./template.yaml
set +xv
- name: store artifacts
uses: actions/upload-artifact@v4
with:
name: store
path: |
./template.yaml
./README.md
./CHANGELOG.md
outputs:
last_commit: ${{ steps.commits.outputs.last_commit }}
sync-changes:
runs-on: ubuntu-latest
permissions:
contents: write
needs: get-template
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch'}}
steps:
- uses: actions/checkout@v4
id: checkout
with:
repository: ${{ env.CLOUDFORMATION_REPO }}
token: ${{ secrets.GH_TOKEN }}
- run: mkdir .tmp
- name: download template
uses: actions/download-artifact@v4
with:
name: store
path: .tmp
- run: sudo snap install yq
- name: git-add
id: changes
# git add files if they've changed
run: |
set -xv
ls -ltr .tmp
mkdir -p ${{ env.CFN_INTEGRATION_DIR }}
mv -v ./.tmp/* ${{ env.CFN_INTEGRATION_DIR }}/
git add ${{ env.CFN_INTEGRATION_DIR }}/
git status
set +xv
# Commit all changed files back to the repository
- uses: planetscale/[email protected]
with:
commit_message: ${{ needs.get-template.outputs.last_commit }}
repo: ${{ env.CLOUDFORMATION_REPO }}
branch: master
file_pattern: '*.yaml *.md'
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}