Skip to content
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

Commit b8d1707

Browse files
committed
Inlined SVG images because Lambda cannot access filesystem
1 parent 2ec5d57 commit b8d1707

12 files changed

Lines changed: 63 additions & 13 deletions

File tree

modules/status/lambda/Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
include ../../../share/lambda/Makefile
2222

2323
# -----------------------------------------------------------------------------
24-
# Target hooks
24+
# Targets
2525
# -----------------------------------------------------------------------------
2626

27-
# Include assets in distribution files
28-
dist-post:
29-
@(cd dist && cp -r ../src/assets .)
27+
# Inline badges, because Lambda cannot read from the file system
28+
%.ts: %.svg
29+
@ echo "export = \"$(shell cat $< | sed 's/"/\\\\\\"/g')\"" > $@
30+
31+
# -----------------------------------------------------------------------------
32+
# Hooks
33+
# -----------------------------------------------------------------------------
34+
35+
# Build inlined badges
36+
dist-pre: $(patsubst %.svg, %.ts, $(shell find src/badges/*.svg))
37+
38+
# Clean inlined badges
39+
clean-pre:
40+
rm -rf src/badges/*.ts

modules/status/lambda/dist.zip

77 Bytes
Binary file not shown.

modules/status/lambda/src/assets

Lines changed: 0 additions & 1 deletion
This file was deleted.

modules/status/lambda/src/badges

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../share/badges

modules/status/lambda/src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
* IN THE SOFTWARE.
2121
*/
2222

23-
import * as fs from "fs"
2423
import * as GitHub from "github"
25-
import * as path from "path"
2624

2725
import { Callback, Context } from "aws-lambda"
2826
import { S3 } from "aws-sdk"
@@ -144,9 +142,9 @@ const mapping: CodeBuildGitHubMapping = {
144142
* GitHub build status to badge mapping
145143
*/
146144
const badges: GitHubBadgeMapping = {
147-
success: path.resolve(__dirname, "assets/success.svg"),
148-
failure: path.resolve(__dirname, "assets/failing.svg"),
149-
error: path.resolve(__dirname, "assets/errored.svg")
145+
success: "./badges/success",
146+
failure: "./badges/failing",
147+
error: "./badges/errored"
150148
}
151149

152150
/* ----------------------------------------------------------------------------
@@ -221,7 +219,7 @@ export default (event: CodeBuildPhaseChange, _: Context, cb: Callback) => {
221219
s3.putObject({
222220
Bucket: process.env.CODEBUILD_BUCKET!,
223221
Key: `${repo}/status.svg`,
224-
Body: fs.readFileSync(badges[state!], "utf8"),
222+
Body: require(badges[state!]),
225223
ACL: "public-read",
226224
CacheControl: "no-cache, no-store, must-revalidate",
227225
ContentType: "image/svg+xml"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": [
3+
"../tslint.json"
4+
],
5+
"rules": {
6+
"max-line-length": false
7+
}
8+
}

share/badges/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2017-2018 Martin Donath <martin.donath@squidfunk.com>
2+
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to
5+
# deal in the Software without restriction, including without limitation the
6+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
# sell copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
# IN THE SOFTWARE.
20+
21+
# Inlined badges
22+
*.ts

0 commit comments

Comments
 (0)