forked from deldrid1/chrome-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devops: added buildbot to test Lambda on CI
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 12.x | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Build project | ||
run: npm run build | ||
- name: Test lambda function | ||
run: bash buildbots/stub.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const chromium = require('../build/'); | ||
|
||
exports.handler = async (event, context) => { | ||
let browser = null; | ||
|
||
try { | ||
const browser = await chromium.puppeteer.launch({ | ||
executablePath: await chromium.executablePath, | ||
defaultViewport: chromium.defaultViewport, | ||
args: chromium.args, | ||
}); | ||
|
||
const page = await browser.newPage(); | ||
await page.goto(event.url); | ||
const data = await page.screenshot(); | ||
if (data.length === 0) { | ||
throw new Error(`Screenshot is empty`); | ||
} | ||
console.log('Page title: ', await page.title()); | ||
} catch (error) { | ||
throw error; | ||
} finally { | ||
if (browser !== null) { | ||
await browser.close(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#/bin/bash | ||
|
||
set -e | ||
|
||
LOG_FILE="log.txt" | ||
|
||
echo "Running Puppeteer lambda function" | ||
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:nodejs12.x buildbots/puppeteer.handler '{"url": "https://example.com"}' &> "$LOG_FILE" | ||
grep -Fq "Example Domain" "$LOG_FILE" | ||
echo "Sucessfully passed Puppeteer test" | ||
|
||
rm "$LOG_FILE" |