Skip to content

Commit

Permalink
Build scripts update
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Sep 6, 2024
1 parent 763de4c commit 8febcbd
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-linux-arm-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BINARY_NAME: 'svgtinyps-linux-aarch64'
COMPILE_PHP_VERSION: '8.2'
COMPILE_PHP_VERSION: "8.3"
COMPILE_EXTENSIONS: 'phar,dom'

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-linux-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BINARY_NAME: 'svgtinyps-linux-x86_64'
COMPILE_PHP_VERSION: '8.2'
COMPILE_PHP_VERSION: "8.3"
COMPILE_EXTENSIONS: 'phar,dom'

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-macos-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BINARY_NAME: 'svgtinyps-macos-x86_64'
COMPILE_PHP_VERSION: '8.2'
COMPILE_PHP_VERSION: "8.3"
COMPILE_EXTENSIONS: 'phar,dom'

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: "8.3"
tools: composer:v2

- name: Get composer cache directory
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ on:
jobs:
pint:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: "8.3"
tools: composer:v2

- name: Get composer cache directory
Expand All @@ -35,10 +33,4 @@ jobs:
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Launch Pint inspection
run: composer pint

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: PHP Linting (Pint)
skip_fetch: true
run: composer pint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ composer.lock
/tmp
/build
.phpunit.result.cache
.DS_Store

14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ This project use [Pest](https://pestphp.com/) for testing.
composer test
```

## Contribute
This project follows PSR coding style. You can use `composer pint` to apply.

All tests are executed with pest. Use `composer pest`

It's recommended to execute `composer qa` before commiting (alias for executing Pint and Pest)

## Build from sources
This project use [box](https://github.com/box-project/box), [php-static-cli](https://github.com/crazywhalecc/static-php-cli) and [php-micro](https://github.com/dixyes/phpmicro).
A build script has been created to build the project. (tested only on macOS x86_64)

```bash
composer build
```
Then you can build the binary that you can retrieve in `build/bin/`

[//]: # (You can also build it from Github Workflow, or locally on MacOS using [act](https://github.com/nektos/act))

Expand All @@ -86,12 +95,9 @@ composer build
[//]: # (```)
## Roadmap
Pull requests are welcome! Here are some ideas to get you started:
- Option to set <title>
- Use Symfony Console for better ui
- Build binaries for Windows, Linux and MacOS
- Build binaries for MacOS arm64 and Windows
- Publish on Homebrew
- Automate everything with Github Actions


## Credits

Expand Down
7 changes: 4 additions & 3 deletions build-ci-linux-arm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ -d "build/static-php-cli" ]; then
git pull
else
cd build/
git clone https://github.com/crazywhalecc/static-php-cli.git
git clone --depth 1 https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli/
fi

Expand All @@ -44,8 +44,9 @@ chmod +x bin/spc-alpine-docker
#cd ../

# Build PHP Micro with only the extensions we need
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker download --with-php=8.2 --for-extensions=dom,phar
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker build dom,phar --build-micro
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker download --with-php="8.3" --for-extensions="dom,phar,zlib" --prefer-pre-built
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker switch-php-version "8.3"
SPC_USE_ARCH=aarch64 ./bin/spc-alpine-docker build --build-micro "dom,phar,zlib"

# Build binary
cat buildroot/bin/micro.sfx ../bin/svgtinyps.phar > "../bin/$binary_name"
Expand Down
7 changes: 4 additions & 3 deletions build-ci-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ -d "build/static-php-cli" ]; then
git pull
else
cd build/
git clone https://github.com/crazywhalecc/static-php-cli.git
git clone --depth 1 https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli/
fi

Expand All @@ -41,8 +41,9 @@ composer update --no-interaction
chmod +x bin/spc-alpine-docker

# Build PHP Micro with only the extensions we need
CACHE_API_EXEC=yes ./bin/spc-alpine-docker download --with-php=8.2 --for-extensions=dom,phar
./bin/spc-alpine-docker build dom,phar --build-micro
CACHE_API_EXEC=yes ./bin/spc-alpine-docker download --with-php="8.3" --for-extensions="dom,phar,zlib" --prefer-pre-built
./bin/spc-alpine-docker switch-php-version "8.3"
./bin/spc-alpine-docker build --build-micro "dom,phar,zlib"

# Build binary
cat buildroot/bin/micro.sfx ../bin/svgtinyps.phar > "../bin/$binary_name"
Expand Down
7 changes: 4 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ -d "build/static-php-cli" ]; then
git pull
else
cd build/
git clone https://github.com/crazywhalecc/static-php-cli.git
git clone --depth 1 https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli/
fi

Expand All @@ -45,8 +45,9 @@ cd ../

# Build PHP Micro with only the extensions we need
./static-php-cli/bin/spc doctor
./static-php-cli/bin/spc download --with-php=8.2 --for-extensions=dom,phar
./static-php-cli/bin/spc build dom,phar --build-micro
./static-php-cli/bin/spc download --with-php="8.3" --for-extensions="dom,phar,zlib" --prefer-pre-built
./static-php-cli/bin/spc switch-php-version "8.3"
./static-php-cli/bin/spc build --build-micro "dom,phar,zlib"

# Build binary
./static-php-cli/bin/spc micro:combine bin/svgtinyps.phar --output="bin/$binary_name"
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "srwiez/svgtinyps-cli",
"description": "SVG (Portable and Secure) commandline converter for BIMI compliance",
"type": "library",
"license": "MIT",
"authors": [
{
Expand Down Expand Up @@ -42,6 +41,10 @@
"Composer\\Config::disableProcessTimeout",
"./build.sh"
],
"qa": [
"@composer pint",
"@composer test"
],
"box": [
"./vendor/bin/box"
],
Expand Down
44 changes: 22 additions & 22 deletions src/svgtinyps.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SVGTinyPS\SVGTinyPS;

if (!class_exists('\Composer\InstalledVersions')) {
require __DIR__ . '/../vendor/autoload.php';
require __DIR__.'/../vendor/autoload.php';
}

// Argument parsing
Expand All @@ -31,7 +31,7 @@
function verboseLog($message, $isVerbose): void
{
if ($isVerbose) {
echo "[VERBOSE] $message" . PHP_EOL;
echo "[VERBOSE] $message".PHP_EOL;
}
}

Expand All @@ -48,25 +48,25 @@ function getComposerVersion($package = 'composer/composer'): ?string
function showHelp(): void
{
$version = '@git_tag@';
echo 'Usage: svgtinyps [options] [command] [input-file] [output-file]' . PHP_EOL;
echo 'Usage: svgtinyps [options] [command] [input-file] [output-file]'.PHP_EOL;
echo PHP_EOL;
echo 'Options:' . PHP_EOL;
echo ' -v, --verbose Enable verbose mode' . PHP_EOL;
echo ' --title= Set company name (<title> tag)' . PHP_EOL;
echo 'Options:'.PHP_EOL;
echo ' -v, --verbose Enable verbose mode'.PHP_EOL;
echo ' --title= Set company name (<title> tag)'.PHP_EOL;
echo PHP_EOL;
echo 'Commands:' . PHP_EOL;
echo ' convert [input] [output] - Convert SVG file' . PHP_EOL;
echo ' issues [input] - Check for issues in SVG file' . PHP_EOL;
echo 'Commands:'.PHP_EOL;
echo ' convert [input] [output] - Convert SVG file'.PHP_EOL;
echo ' issues [input] - Check for issues in SVG file'.PHP_EOL;
// echo ' minify [input] - Minify SVG file'.PHP_EOL;
echo ' help - Show this help information' . PHP_EOL;
echo ' help - Show this help information'.PHP_EOL;
echo PHP_EOL;
echo 'Informations:' . PHP_EOL;
echo !str_starts_with($version, '@git_tag') ? ' Version: ' . $version . PHP_EOL : '';
echo ' PHP version: ' . phpversion() . PHP_EOL;
echo 'Informations:'.PHP_EOL;
echo !str_starts_with($version, '@git_tag') ? ' Version: '.$version.PHP_EOL : '';
echo ' PHP version: '.phpversion().PHP_EOL;
// echo 'PHP sapi name: '.php_sapi_name().PHP_EOL;
echo ' Based on https://github.com/srwiez/php-svg-ps-converter (' . getComposerVersion('srwiez/php-svg-ps-converter') . ')' . PHP_EOL;
echo ' Built with https://github.com/box-project/box' . PHP_EOL;
echo php_sapi_name() == 'micro' ? ' Compiled with https://github.com/crazywhalecc/static-php-cli' . PHP_EOL : '';
echo ' Based on https://github.com/srwiez/php-svg-ps-converter ('.getComposerVersion('srwiez/php-svg-ps-converter').')'.PHP_EOL;
echo ' Built with https://github.com/box-project/box'.PHP_EOL;
echo php_sapi_name() == 'micro' ? ' Compiled with https://github.com/crazywhalecc/static-php-cli'.PHP_EOL : '';
}

if (!$command || $command === 'help') {
Expand All @@ -77,7 +77,7 @@ function showHelp(): void
function checkInputFile($inputFile): void
{
if (!$inputFile || !file_exists($inputFile)) {
echo "Error: Input file not provided or doesn't exist." . PHP_EOL;
echo "Error: Input file not provided or doesn't exist.".PHP_EOL;
exit(1);
}
}
Expand All @@ -86,7 +86,7 @@ function checkOutputFile($outputFile): void
{
$outputDir = $outputFile ? dirname($outputFile) : null;
if (empty($outputFile)) {
echo 'Error: Output file not provided for conversion.' . PHP_EOL;
echo 'Error: Output file not provided for conversion.'.PHP_EOL;
exit(1);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ function checkOutputFile($outputFile): void
// minifySvg($inputFile, $isVerbose);
// break;
default:
echo 'Invalid command!' . PHP_EOL;
echo 'Invalid command!'.PHP_EOL;
echo PHP_EOL;
showHelp();
exit(1);
Expand All @@ -140,7 +140,7 @@ function convertSvg($input, $output, $title, $isVerbose): void
}
$new_svg = $svgps->convert();
} catch (Exception $exception) {
echo "Error: " . $exception->getMessage() . PHP_EOL;
echo 'Error: '.$exception->getMessage().PHP_EOL;
exit(1);
}
file_put_contents($output, $new_svg);
Expand All @@ -154,10 +154,10 @@ function checkIssues($input, $isVerbose): void
$svgps = new SVGTinyPS(file_get_contents($input));
$issues = $svgps->identifyIssues();
foreach ($issues as $issue) {
echo "$issue" . PHP_EOL;
echo "$issue".PHP_EOL;
}
} catch (Exception $exception) {
echo "Error: " . $exception->getMessage() . PHP_EOL;
echo 'Error: '.$exception->getMessage().PHP_EOL;
exit(1);
}
}
Expand Down

0 comments on commit 8febcbd

Please sign in to comment.