-
Notifications
You must be signed in to change notification settings - Fork 2
204 lines (168 loc) · 6.89 KB
/
publish.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Publish
on:
push:
paths:
- 'template.yaml'
workflow_dispatch:
env:
AWS_DEFAULT_REGION: eu-central-1
AWS_SERVERLESS_BUCKET: coralogix-serverless-repo
AWS_S3_PREFIX: coralogix-aws-shipper
REPO_BUCKET_PREFIX: coralogix-serverless-repo
jobs:
check_version:
if: ${{ github.event_name != 'workflow_dispatch' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
outputs:
template_updated: ${{ env.updated }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2 # Fetches the last two commits for comparison
- name: install yq
run: sudo snap install yq
- name: check if specific value has changed
id: check_change
run: |
set -xv
# Extract the value from the current commit
current=$(yq '.Metadata."AWS::ServerlessRepo::Application".SemanticVersion' template.yaml)
echo "current_version=$current" >> $GITHUB_ENV
# Extract the value from the previous commit
git checkout HEAD^ template.yaml
previous=$(yq '.Metadata."AWS::ServerlessRepo::Application".SemanticVersion' template.yaml)
# Compare the two values
echo "updated=false" >> $GITHUB_ENV
[ "$current" != "$previous" ] && echo "updated=true" >> $GITHUB_ENV
lastcommit=$(git log -1 --pretty=%B)
[[ $lastcommit =~ .*skip-version-check.* ]] && echo "updated=true" >> $GITHUB_ENV
set +xv
- name: create tag
if: env.updated == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.current_version }}',
sha: context.sha
})
validate:
name: validate
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: sam validate
working-directory: ./
run: sam validate
build:
name: build
needs: validate
if: ${{ github.event_name == 'workflow_dispatch' || success() }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- arm64
- x86-64
steps:
- name: checkout
uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip' # caching pip dependencies
- run: pip3 install cargo-lambda
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: start ssh agent for rust private dependencies
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: install protobuf compiler
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: install yq
run: sudo snap install yq
- name: get_version
id: get_version
run: |
set -xv
# Extract the value from the current commit
current=$(yq '.Metadata."AWS::ServerlessRepo::Application".SemanticVersion' template.yaml)
echo "current_version=$current" >> $GITHUB_ENV
- name: sam build
env:
RUST_ARCH: ${{ matrix.target }}
run: sam build
- name: package
run: |
sam package \
--s3-bucket ${{ env.AWS_SERVERLESS_BUCKET }} \
--s3-prefix '${{ env.AWS_S3_PREFIX }}/${{ matrix.target }}' \
--output-template-file packaged.yaml
- name: s3upload-x86-64-build
if: ${{ matrix.target == 'x86-64' }}
run: |
aws s3 cp \
$(yq -r '.Resources | to_entries | .[] | select(.key == "LambdaLayer" or .key == "LambdaFunction") | .value.Properties | to_entries | .[] | select(.key == "ContentUri" or .key == "CodeUri") | .value' packaged.yaml) \
s3://${{ env.AWS_SERVERLESS_BUCKET }}-${{ env.AWS_DEFAULT_REGION }}/coralogix-aws-shipper-${{ matrix.target }}.zip
- name: s3upload-${{ matrix.target }}-build-versioned
run: |
aws s3 cp \
$(yq -r '.Resources | to_entries | .[] | select(.key == "LambdaLayer" or .key == "LambdaFunction") | .value.Properties | to_entries | .[] | select(.key == "ContentUri" or .key == "CodeUri") | .value' packaged.yaml) \
s3://${{ env.AWS_SERVERLESS_BUCKET }}-${{ env.AWS_DEFAULT_REGION }}/coralogix-aws-shipper-${{ matrix.target }}-${{ env.current_version }}.zip
- name: store-arm64-package
uses: actions/upload-artifact@v4
# only store the arm64 package as this is the
# only one that will be published to SAR
if: ${{ matrix.target == 'arm64' }}
with:
name: packaged.yaml
path: packaged.yaml
publish:
name: publish
needs: [check_version , build]
if: ${{ github.event_name == 'workflow_dispatch' || (success() && needs.check_version.outputs.template_updated == 'true' && github.ref == 'refs/heads/master') }}
runs-on: ubuntu-latest
env:
AWS_SERVERLESS_BUCKET: coralogix-serverless-repo
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: download
uses: actions/download-artifact@v4
with:
name: packaged.yaml
- name: publish
run: sam publish --template packaged.yaml
- name: store
run: |
aws s3 cp \
$(yq -r '.Resources | to_entries | .[] | select(.key == "LambdaLayer" or .key == "LambdaFunction") | .value.Properties | to_entries | .[] | select(.key == "ContentUri" or .key == "CodeUri") | .value' packaged.yaml) \
s3://${{ env.AWS_SERVERLESS_BUCKET }}-${{ env.AWS_DEFAULT_REGION }}/coralogix-aws-shipper.zip
# upload custom resource
aws s3 cp \
$(yq -r '.Resources | to_entries | .[] | select(.key == "CustomResourceFunction") | .value.Properties | .CodeUri' packaged.yaml) \
s3://${{ env.AWS_SERVERLESS_BUCKET }}-${{ env.AWS_DEFAULT_REGION }}/coralogix-aws-shipper-custom-resource.zip