Skip to content

Commit

Permalink
Merge branch 'main' into v2/layers-config
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanzweifel authored Dec 29, 2023
2 parents 4906692 + de048ce commit 1e12751
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Security Policy

If you discover any security related issues, please email hello@stefanzweifel.io instead of using the issue tracker.
If you discover any security related issues, please email stefan@stefanzweifel.dev instead of using the issue tracker.
10 changes: 10 additions & 0 deletions .github/workflows/laravel-pint-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Laravel Pint

on:
push:
branches:
- main

jobs:
pint:
uses: stefanzweifel/reusable-workflows/.github/workflows/laravel-pint-fixer.yml@main
23 changes: 0 additions & 23 deletions .github/workflows/php-cs-fixer.yml

This file was deleted.

21 changes: 4 additions & 17 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ on:
- 'phpstan.neon.dist'

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v2

- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
update_release_draft:
uses: stefanzweifel/reusable-workflows/.github/workflows/phpstan.yml@main
with:
php_version: '8.3'
6 changes: 1 addition & 5 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ on:

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: stefanzweifel/reusable-workflows/.github/workflows/release-drafter.yml@main
17 changes: 2 additions & 15 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,12 @@ jobs:
max-parallel: 1
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2, 8.3]
laravel: [8.*, 9.*, 10.*]
php: [8.2, 8.3]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: ^6.23
- laravel: 9.*
testbench: ^7.0
- laravel: 10.*
testbench: ^8.0
exclude:
- laravel: 8.*
stability: prefer-lowest
- laravel: 9.*
stability: prefer-lowest
- laravel: 10.*
stability: prefer-lowest
- laravel: 10.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
21 changes: 1 addition & 20 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,4 @@ on:

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
uses: stefanzweifel/reusable-workflows/.github/workflows/update-changelog.yml@main
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
composer.lock
Expand All @@ -11,6 +9,5 @@ phpstan.neon
testbench.yaml
vendor
node_modules
.php-cs-fixer.cache
.env
**/.DS_Store
40 changes: 0 additions & 40 deletions .php_cs.dist.php

This file was deleted.

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/stefanzweifel/sidecar-browsershot/compare/v1.13.0...HEAD)
## [Unreleased](https://github.com/stefanzweifel/sidecar-browsershot/compare/v1.13.1...HEAD)

## [v1.13.1](https://github.com/stefanzweifel/sidecar-browsershot/compare/v1.13.0...v1.13.1) - 2023-12-16

### Fixed

- Add internal support for Chromium Result ([#105](https://github.com/stefanzweifel/sidecar-browsershot/pull/105))

## [v1.13.0](https://github.com/stefanzweifel/sidecar-browsershot/compare/v1.12.0...v1.13.0) - 2023-11-06

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) Stefan Zweifel <hello@stefanzweifel.io>
Copyright (c) Stefan Zweifel <stefan@stefanzweifel.dev>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
"authors": [
{
"name": "Stefan Zweifel",
"email": "hello@stefanzweifel.io",
"email": "stefan@stefanzweifel.dev",
"role": "Developer"
}
],
"require": {
"php": "^8.0",
"php": "^8.2",
"hammerstone/sidecar": "^0.4.0",
"illuminate/contracts": "^8.0|^9.0|^10.0",
"spatie/browsershot": "^3.57.8",
"illuminate/contracts": "^10.0",
"spatie/browsershot": "^3.60",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"larastan/larastan": "^1.0|^2.0",
"laravel/pint": "^1.13",
"league/flysystem-aws-s3-v3": "^1.0|^2.0|^3.0",
"nunomaduro/collision": "^5.10|^6.0|^7.0",
"nunomaduro/larastan": "^1.0|^2.0",
"orchestra/testbench": "^6.22|^7.0|^8.0",
"pestphp/pest": "^1.21 | ^2.0",
"pestphp/pest-plugin-laravel": "^1.1 | ^2.0",
"nunomaduro/collision": "^7.0|^8.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9 | ^10",
"spatie/laravel-ray": "^1.26"
"phpunit/phpunit": "^10"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion config/sidecar-browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
/**
* Define the allocated memory available to SidecarBrowsershot in megabytes. (Defaults to 2GB)
* We suggest to allocate at least 513 MB of memory to push Chrome/Puppeteer out of "low-spec" mode.
*
* @see https://hammerstone.dev/sidecar/docs/main/functions/customization#memory
* @see https://github.blog/2021-06-22-framework-building-open-graph-images/
*/
'memory' => env('SIDECAR_BROWSERSHOT_MEMORY', 2048),

/**
* The default ephemeral storage available to SidecarBrowsershot, in megabytes. (Defaults to 512MB)
*
* @see https://hammerstone.dev/sidecar/docs/main/functions/customization#storage
*/
'storage' => env('SIDECAR_BROWSERSHOT_STORAGE', 512),

/**
* The default timeout to use for SidecarBrowsershot, in seconds. (Defaults to 300)
*
* @see https://hammerstone.dev/sidecar/docs/main/functions/customization#timeout
*/
'timeout' => env('SIDECAR_BROWSERSHOT_TIMEOUT', 300),

/**
*Number of warming instances to boot.
* Define the number of warming instances to boot.
*
* @see https://hammerstone.dev/sidecar/docs/main/functions/warming
*/
'warming' => env('SIDECAR_BROWSERSHOT_WARMING_INSTANCES', 0),
Expand Down
28 changes: 25 additions & 3 deletions src/BrowsershotLambda.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\Browsershot\Browsershot;
use Spatie\Browsershot\ChromiumResult;
use Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot;
use Spatie\Browsershot\Exceptions\ElementNotFound;
use Wnx\SidecarBrowsershot\Functions\BrowsershotFunction;
Expand All @@ -29,16 +30,37 @@ protected function callBrowser(array $command): string
$this->throwError($response);
}

// If the response is not valid JSON, it's probably a base64 encoded string representing a binary file.
// In this case, we will return the base64 decoded string.
if (json_decode($response->body(), true) === null) {
$result = base64_decode($response->body());
} else {
$result = $response->body();

// If the response is valid JSON, we can cast it to a Chromium Result.
// It will contain the result and additional information about the Chromium process.
if (is_array($chromiumResult = json_decode($response->body(), true))) {
$this->chromiumResult = new ChromiumResult($chromiumResult);
}
}

$s3 = Arr::get($command, 'options.s3');
$path = Arr::get($command, 'options.path');

if ($path && ! $s3) {
file_put_contents($path, base64_decode($response->body()));
file_put_contents($path, $result);

return $path;
} else {
return $response->body();
}

// If ChromiumResult is available, return the result from there.
if ($this->chromiumResult) {
return $this->chromiumResult->getResult();
}

// The result can now be either a base64 deocded string representing a binary file or a string representing
// the ETag of a file on S3.
return $result;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/Functions/BrowsershotFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function package()
'browser.cjs' => $this->modifiedBrowserJs(),
])
->includeExactly([
__DIR__ . '/../../resources/lambda/browsershot.js' => 'browsershot.js',
__DIR__.'/../../resources/lambda/browsershot.js' => 'browsershot.js',
])
->includeExactly($this->customFonts());
}
Expand All @@ -41,14 +41,14 @@ protected function customFonts(): array
if (file_exists($fontDirectory)) {
// Loop through all files in the custom fonts folder.
foreach (scandir($fontDirectory) as $file) {
if (is_file($fontDirectory . $file)) {
$fonts->prepend("fonts/$file", $fontDirectory . $file);
if (is_file($fontDirectory.$file)) {
$fonts->prepend("fonts/$file", $fontDirectory.$file);
}
}
}

// By default, we include the NotoColorEmoji font.
$fonts->prepend('fonts/NotoColorEmoji.ttf', __DIR__ . '/../../resources/lambda/fonts/NotoColorEmoji.ttf');
$fonts->prepend('fonts/NotoColorEmoji.ttf', __DIR__.'/../../resources/lambda/fonts/NotoColorEmoji.ttf');

// Ensure that we only have unique font values.
return $fonts->unique()->toArray();
Expand All @@ -72,7 +72,7 @@ protected function modifiedBrowserJs()
$browser = str_replace('const puppet = (pup || require(\'puppeteer\'));', '', $browser);

// Use pupeteer-core instead.
return "const puppet = require('puppeteer-core'); \n" . $browser;
return "const puppet = require('puppeteer-core'); \n".$browser;
}

/**
Expand All @@ -92,7 +92,7 @@ public function memory()
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function storage()
{
Expand All @@ -101,7 +101,7 @@ public function storage()
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function timeout()
{
Expand All @@ -110,7 +110,7 @@ public function timeout()
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function architecture()
{
Expand Down Expand Up @@ -139,7 +139,6 @@ public function layers()
$chromeAwsLambdaVersion = 37;
}


// Add Layers that each contain `puppeteer-core` and `@sparticuz/chromium`
// https://github.com/stefanzweifel/sidecar-browsershot-layer
// https://github.com/shelfio/chrome-aws-lambda-layer
Expand Down
Loading

0 comments on commit 1e12751

Please sign in to comment.