forked from coralogix/coralogix-aws-serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (150 loc) · 6.32 KB
/
Synchronizing.yml
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Synchronizing Cloudformation repo with serverless
on:
pull_request:
types: [closed]
branches: [master, main]
paths:
- "src/**/template.*"
- "src/**/README.md"
jobs:
Get-matrix:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
outputs:
packages: ${{ env.packages }}
steps:
- uses: actions/checkout@v4
- name: Read matrix YAML
id: read-matrix
run: |
export PACKAGES=$(jq -r '.[].name' matrix.js | jq -rcnR '[inputs]')
echo "packages=$PACKAGES" >> $GITHUB_ENV
# to save a directory as an Artifact it must contain a file
- name: Create template-readme-directory
run: |
mkdir template-readme-directory
touch template-readme-directory/file.tmp
- name: Upload template-readme-directory
uses: actions/[email protected]
with:
name: template-readme-directory
path: ./template-readme-directory/
- name: Create changes file list
run: touch change_file_list.txt
- name: Upload changes file list
uses: actions/[email protected]
with:
name: change_file_list
path: change_file_list.txt
Apply-changes:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
needs: Get-matrix
strategy:
matrix:
package: ${{ fromJSON(needs.Get-matrix.outputs.packages) }}
max-parallel: 1
steps:
- uses: actions/checkout@v4
- id: changes
uses: dorny/paths-filter@v3
with:
filters: |
'${{ matrix.package }}':
- 'src/${{ matrix.package }}/**'
- if: steps.changes.outputs[matrix.package] == 'true'
name: Change template and README to CF
run: |
chmod +x scripts/replace_codeuri.sh
scripts/replace_codeuri.sh src/${{ matrix.package }}/template.* ${{ matrix.package }} src/${{ matrix.package }}/README.md
- if: steps.changes.outputs[matrix.package] == 'true'
name: Create template and readme directory
run: mkdir template-readme-directory
- if: steps.changes.outputs[matrix.package] == 'true'
name: Download template and readme artifact
uses: actions/download-artifact@v4
with:
name: template-readme-directory
path: ./template-readme-directory
- if: steps.changes.outputs[matrix.package] == 'true'
name: Add integration to matrix file
run: |
mv src/${{ matrix.package }}/README.md template-readme-directory/${{ matrix.package }}_README
mv src/${{ matrix.package }}/template.* template-readme-directory/${{ matrix.package }}_template.yaml
if [ -f "src/${{ matrix.package }}/CHANGELOG.md" ]; then
mv src/${{ matrix.package }}/CHANGELOG.md template-readme-directory/${{ matrix.package }}_CHANGELOG.md
fi
- if: steps.changes.outputs[matrix.package] == 'true'
name: Upload template-readme-directory
uses: actions/[email protected]
with:
name: template-readme-directory-${{ matrix.package }}
path: ./template-readme-directory/
- if: steps.changes.outputs[matrix.package] == 'true'
name: Download change_file_list
uses: actions/download-artifact@v4
with:
name: change_file_list
- if: steps.changes.outputs[matrix.package] == 'true'
name: Add integration to change_file_list
run: echo "${{ matrix.package }}" >> change_file_list.txt
- if: steps.changes.outputs[matrix.package] == 'true'
name: Upload change_file_list
uses: actions/[email protected]
with:
name: change_file_list_${{ matrix.package }}
path: change_file_list.txt
Push-changes:
needs: Apply-changes
runs-on: ubuntu-latest
steps:
- name: Checkout destination repository
uses: actions/checkout@v4
with:
repository: coralogix/cloudformation-coralogix-aws
token: ${{ secrets.GH_TOKEN }}
- name: Create template-readme-directory
run: mkdir ./template-readme-directory
- name: Download template-readme-directory
uses: actions/download-artifact@v4
with:
# name: template-readme-directory
path: ./template-readme-directory
- name: Download change_file_list
uses: actions/download-artifact@v4
# with:
# name: change_file_list
- name: Commit and push change files
run: |
for file in change_file_list_*; do
line="${file#change_file_list_}"
if [[ -d "aws-integrations/lambda-integrations/$line" ]]; then
mv template-readme-directory-${line}/${line}_README aws-integrations/lambda-integrations/$line/README.md
mv template-readme-directory-${line}/${line}_template.yaml aws-integrations/lambda-integrations/$line/template.yaml
if [ -f "template-readme-directory-${line}/${line}_CHANGELOG.md" ]; then
mv template-readme-directory-${line}/${line}_CHANGELOG.md aws-integrations/lambda-integrations/$line/CHANGELOG.md
fi
else
mkdir aws-integrations/lambda-integrations/$line
mv template-readme-directory-${line}/${line}_README aws-integrations/lambda-integrations/$line/README.md
mv template-readme-directory-${line}/${line}_template.yaml aws-integrations/lambda-integrations/$line/template.yaml
if [ -f "template-readme-directory-${line}/${line}_CHANGELOG.md" ]; then
mv template-readme-directory-${line}/${line}_CHANGELOG.md aws-integrations/lambda-integrations/$line/CHANGELOG.md
fi
fi
done
rm -rf change_file_list*
rm -rf template-readme-directory*
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout master
git pull
git add .
- uses: planetscale/[email protected]
with:
commit_message: "${{ github.event.pull_request.title }}"
repo: coralogix/cloudformation-coralogix-aws
branch: master
file_pattern: '*.yaml *.md'
env:
GITHUB_TOKEN: ${{secrets.GH_TOKEN}}