-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (116 loc) · 4.5 KB
/
test.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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 }}