Skip to content

Commit

Permalink
chore(embed): deploy code embed renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
tericcabrel committed Sep 3, 2022
1 parent 906e5f8 commit 8d4ff99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/deploy-code-embed.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
name: Sharingan Deploy Code Embed
on:
workflow_dispatch:
inputs:
stage:
default: Production
options:
- Production
- Development
description: "Environment to deploy on"
required: true
push:
branches:
- main
- dev
paths:
- 'packages/database/prisma/**'
- 'packages/database/src/**'
Expand All @@ -21,7 +13,7 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.stage }}
environment: ${{ (github.ref == 'refs/heads/main' && 'Production') || 'Development' }}
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
EMBED_STYLE_URL: ${{ secrets.EMBED_STYLE_URL }}
Expand All @@ -41,14 +33,14 @@ jobs:

- name: Deploy the application in staging
working-directory: 'apps/functions/code-embed'
if: ${{ github.event.inputs.stage == 'Development' }}
if: ${{ github.ref == 'refs/heads/dev' }}
run: |
yarn setup:layer:remote
yarn sls deploy --stage dev
- name: Deploy the application in production
working-directory: 'apps/functions/code-embed'
if: ${{ github.event.inputs.stage == 'Production' }}
if: ${{ github.ref == 'refs/heads/main' }}
run: |
yarn setup:layer:remote
yarn sls deploy --stage prod
Expand Down
11 changes: 9 additions & 2 deletions apps/functions/code-embed/scripts/setup-layer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ yarn workspace @sharingan/database db:generate

cp -r node_modules/.prisma apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules

PRISMA_ENGINE_MACOS=apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-darwin.dylib.node
PRISMA_ENGINE_DOCKER_LINUX=apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-linux-musl.so.node

if [ $1 = "remote" ]; then
rm apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-darwin.dylib.node
rm apps/functions/code-embed/layers/prisma-layer/nodejs/node_modules/.prisma/client/libquery_engine-linux-musl.so.node
if [ -f "$PRISMA_ENGINE_MACOS" ]; then
rm $PRISMA_ENGINE_MACOS
fi
if [ -f "$PRISMA_ENGINE_DOCKER_LINUX" ]; then
rm $PRISMA_ENGINE_DOCKER_LINUX
fi
else
echo 'local'
fi
Expand Down
7 changes: 6 additions & 1 deletion apps/functions/code-embed/src/functions/renderer/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const shiki = require('shiki');
export const main: Handler<APIGatewayProxyEvent, APIGatewayProxyResult> = async (event) => {
const snippetId = event.pathParameters['id'];

const snippet = await dbClient.snippet.findFirst({ where: { id: snippetId, visibility: 'public' } });
const snippet = await dbClient.snippet.findFirst({
where: {
id: snippetId,
visibility: 'public',
},
});

const content = await renderSnippetToHtml({
options: {
Expand Down

0 comments on commit 8d4ff99

Please sign in to comment.