Skip to content

Commit

Permalink
PHP 8.3 + Cache on workflows + Pint + Build script
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Nov 30, 2023
1 parent 5e24f60 commit 2d3442a
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 34 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build-phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
types: [ created ]

jobs:
build:
build-phar:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
Expand All @@ -23,6 +23,12 @@ jobs:
php-version: '8.2'
tools: composer:v2

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-8.2-composer-ubuntu-latest

- name: Install Dependencies
run: composer install

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
php-version: '8.2'
tools: composer:v2

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-8.2-composer-ubuntu-latest

- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"

Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ jobs:
os: [ubuntu-latest]
php: [8.2, 8.3]

name: Test with php ${{ matrix.php }} on ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ matrix.os }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: xdebug

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ matrix.os }}

- name: Install Dependencies
run: composer install --dev --no-interaction --prefer-dist --optimize-autoloader

Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Bumped https://github.com/SRWieZ/php-svg-ps-converter to 1.1.1
- Compiled binaries

## [1.0.5] - 2023-11-01
More robust autoload

## [1.0.4] - 2023-11-01
Fix binary vendor autoload

## [1.0.3] - 2023-11-01
Fix composer binary vendor autoload

## [1.0.2] - 2023-11-01
Fixed composer binary path from svgtinyps.phpto svgtinyps

## [1.0.1] - 2023-11-01
Automatic .phar asset on release

## [1.0.0] - 2023-11-01
First version
11 changes: 9 additions & 2 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ This project use [Pest](https://pestphp.com/) for testing.
composer test
```

## Building
## 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.
A build script has been created to build the project. (tested only on macOS x86_64)
```bash
composer build
```

You can also build it from Github Workflow, or locally using [act](https://github.com/nektos/act)
```bash
#upcomming soon
act manual -j build-macos-binary -P macos-latest=-self-hosted
act manual -j build-linux-binary
act manual -j build-windows-binary
```
## Roadmap
Pull requests are welcome! Here are some ideas to get you started:
- Option to set <title>
Expand Down
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"main": "src/svgtinyps.php",
"output": "build/svgtinyps.phar",
"output": "build/bin/svgtinyps.phar",
"banner": false,
"blacklist": [
"tests"
Expand Down
51 changes: 37 additions & 14 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
# removing old build files
rm -rf ./build/
#rm -rf ./tmp/
# Removing old build files
rm -rf build/bin/
#rm -rf build/buildroot/
#rm -rf build/downloads/
#rm -rf build/source/
#rm -rf build/static-php-cli/

# Directories
mkdir -p build/bin/

# Build phar file using box and bos.json
composer pint
composer box compile

#mkdir -p ./tmp
#cd tmp
#curl -O https://dl.static-php.dev/static-php-cli/common/php-8.2.12-micro-macos-x86_64.tar.gz
#tar -xvf php-8.2.12-micro-macos-x86_64.tar.gz
#cd ..
# Fetch or update static-php-cli
if [ -d "build/static-php-cli" ]; then
cd build/static-php-cli/
# git reset --hard HEAD
git pull
else
cd build/
git clone https://github.com/crazywhalecc/static-php-cli.git
cd static-php-cli/
fi

# Install dependencies
composer install --no-interaction
chmod +x bin/spc

# Back to main directory
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

#TODO : build static php first to have pretty much only ext-dom and reduce size of binary
#TODO : Make it CI/CD ready
# Build binary
./static-php-cli/bin/spc micro:combine bin/svgtinyps.phar --output=bin/svgtinyps
chmod 0755 bin/svgtinyps

mkdir -p ./build/macos-x86_64
cat ./tmp/micro.sfx ./build/svgtinyps.phar > ./build/macos-x86_64/svgtinyps
chmod 0755 ./build/macos-x86_64/svgtinyps
# Check if it's working !
cd ../
./build/bin/svgtinyps help
9 changes: 0 additions & 9 deletions changelog.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/svgtinyps.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function getComposerVersion($package = 'composer/composer'): ?string
return \Composer\InstalledVersions::getPrettyVersion($package) ?? null;
}


return null;
}

Expand All @@ -57,6 +56,7 @@ function showHelp()
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 '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;
Expand Down

0 comments on commit 2d3442a

Please sign in to comment.