-
Notifications
You must be signed in to change notification settings - Fork 0
290 lines (277 loc) · 9.54 KB
/
ci.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
name: CI
on:
pull_request:
push:
branches: [main]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: open-turo/actions-gha/lint@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
test:
name: Test
runs-on: ubuntu-latest
needs: [test-upload, test-download]
steps:
- uses: open-turo/actions-gha/test@v2
with:
checkout-repo: true
github-token: ${{ secrets.GITHUB_TOKEN }}
test-upload:
name: Test / Upload
runs-on: ubuntu-latest
env:
AWSCMD: awslocal
S3_BUCKET: actions-s3-artifact-test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python dependency cache
uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache: "pip"
- name: Install python dependencies
run: pip install -r requirements.txt
- name: Setup LocalStack
uses: HarshCasper/[email protected]
- name: Create S3 bucket in localstack
run: awslocal s3 mb "s3://${S3_BUCKET}"
- name: Upload individual files
id: individual
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-upload
path: |
upload/action.yaml
download/action.yaml
- name: Upload directory contents with glob
id: glob
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-upload-glob
path: .github/*
- name: Upload with specified key
id: key
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-upload-key
key: ${{ hashFiles('upload/action.yaml') }}
path: upload/*
- name: Check if uploads were successful
run: |
echo "Check upload.individual: ${{ steps.individual.outputs.s3uri }}"
output=$(awslocal s3 ls "${{ steps.individual.outputs.s3uri }}")
echo "Found: $output"
if [[ "$output" == "None" ]]; then
echo "::error::Failed to find uploaded artifact"
exit 1
fi
echo "Check upload.glob: ${{ steps.glob.outputs.s3uri }}"
output=$(awslocal s3 ls "${{ steps.glob.outputs.s3uri }}")
echo "Found: $output"
if [[ "$output" == "None" ]]; then
echo "::error::Failed to find uploaded artifact"
exit 1
fi
echo "Check upload.key: ${{ steps.key.outputs.s3uri }}"
output=$(awslocal s3 ls "${{ steps.key.outputs.s3uri }}")
echo "Found: $output"
if [[ "$output" == "None" ]]; then
echo "::error::Failed to find uploaded artifact"
exit 1
fi
test-download:
name: Test / Download
runs-on: ubuntu-latest
env:
AWSCMD: awslocal
S3_BUCKET: actions-s3-artifact-test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python dependency cache
uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache: "pip"
- name: Install python dependencies
run: pip install -r requirements.txt
- name: Setup LocalStack
uses: HarshCasper/[email protected]
- name: Create S3 bucket in localstack
run: awslocal s3 mb "s3://${S3_BUCKET}"
- name: Upload a file
id: upload-individual
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-download
path: upload/action.yaml
- name: Upload a tree
id: upload-tree
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-download-tree
path: .github/*
- name: Download tar
id: tar
uses: ./download
with:
s3uri: ${{ steps.upload-individual.outputs.s3uri }}
path: artifact
- name: Download file to default path
id: file-default-path
uses: ./download
env:
AWSCMD: aws
with:
s3uri: s3://turo-github-runners/public/lambdas/v1.8.1/webhook.zip
- name: Download file to specified path
id: file-specified-path
uses: ./download
env:
AWSCMD: aws
with:
s3uri: s3://turo-github-runners/public/lambdas/v1.8.1/webhook.zip
path: artifact/webhook
- name: Download tree
id: download-tree
uses: ./download
with:
s3uri: ${{ steps.upload-tree.outputs.s3uri }}
path: artifact-tree
- name: Download tree and strip paths
id: download-tree-strip
uses: ./download
with:
s3uri: ${{ steps.upload-tree.outputs.s3uri }}
path: artifact-tree-strip
strip: 1
- name: Check if downloads were successful
run: |
tree -a -I ".git" .
echo "Check download.upload-individual: ${{ steps.upload-individual.outputs.s3uri }}"
if [[ ! -f artifact/upload/action.yaml ]]; then
echo "::error::Failed to find downloaded artifact"
exit 1
fi
echo "Check download.file-default-path: ${{ steps.file-default-path.outputs.s3uri }}"
if [[ ! -f webhook.zip ]]; then
echo "::error::Failed to find downloaded artifact"
exit 1
fi
echo "Check download.file-specified-path: ${{ steps.file-specified-path.outputs.s3uri }}"
if [[ ! -f artifact/webhook/webhook.zip ]]; then
echo "::error::Failed to find downloaded artifact"
exit 1
fi
echo "Check download.download-tree: ${{ steps.download-tree.outputs.s3uri }}"
if [[ ! -f artifact-tree/.github/workflows/ci.yaml ]]; then
echo "::error::Failed to find downloaded artifact"
exit 1
fi
echo "Check download.download-tree-strip: ${{ steps.download-tree-strip.outputs.s3uri }}"
if [[ ! -f artifact-tree-strip/workflows/ci.yaml ]]; then
echo "::error::Failed to find downloaded artifact"
exit 1
fi
test-cache:
name: Test / Cache
runs-on: ubuntu-latest
env:
AWSCMD: awslocal
S3_BUCKET: actions-s3-artifact-test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python dependency cache
uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache: "pip"
- name: Install python dependencies
run: pip install -r requirements.txt
- name: Setup LocalStack
uses: HarshCasper/[email protected]
- name: Create S3 bucket in localstack
run: awslocal s3 mb "s3://${S3_BUCKET}"
- name: Download cache (doesn't exist)
id: cache
uses: ./download
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-cache/cached.tgz
path: cache
not-found: ignore
- name: Create cache item
id: create-cache
if: steps.cache.outputs.success != 'true'
run: |
mkdir -p cache
echo "Hello World" > cache/hello.txt
echo "success=true" >> "$GITHUB_OUTPUT"
- name: Upload cache
id: upload-cache
if: steps.cache.outputs.success != 'true'
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-cache/
key: cached.tgz
path: cache
- name: Download cache (does exist)
id: cache-exists
uses: ./download
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-cache/cached.tgz
path: cache
not-found: ignore
- name: Create cache item
id: create-cache-exists
if: steps.cache-exists.outputs.success != 'true'
run: |
mkdir -p cache
echo "Hello World" > cache/hello.txt
echo "success=true" >> "$GITHUB_OUTPUT"
- name: Upload cache
id: upload-cache-exists
if: steps.cache-exists.outputs.success != 'true'
uses: ./upload
with:
s3uri: s3://${{ env.S3_BUCKET }}/test-cache
key: cached.tgz
path: cache
- name: Check step output
if: success() || failure()
run: |
echo "cache: ${{ steps.cache.outputs.success }}"
if [[ "${{ steps.cache.outputs.success }}" != "false" ]]; then
echo "::error::Cache already existed?"
exit 1
fi
echo "create-cache: ${{ steps.create-cache.outputs.success }}"
if [[ "${{ steps.create-cache.outputs.success }}" != "true" ]]; then
echo "::error::Failed to create cache"
exit 1
fi
echo "upload-cache: ${{ steps.upload-cache.outputs.s3uri }}"
if [[ "${{ steps.upload-cache.outputs.s3uri }}" == "" ]]; then
echo "::error::Failed to upload cache"
exit 1
fi
echo "cache-exists: ${{ steps.cache-exists.outputs.success }}"
if [[ "${{ steps.cache-exists.outputs.success }}" != "true" ]]; then
echo "::error::Cache didn't exist?"
exit 1
fi
echo "create-cache-exists: ${{ steps.create-cache-exists.outputs.success }}"
if [[ "${{ steps.create-cache-exists.outputs.success }}" == "true" ]]; then
echo "::error::Created cache when it already existed?"
exit 1
fi
echo "upload-cache-exists: ${{ steps.upload-cache-exists.outputs.s3uri }}"
if [[ "${{ steps.upload-cache-exists.outputs.s3uri }}" != "" ]]; then
echo "::error::Uploaded cache again?"
exit 1
fi