From 9c43e0d3710f202097d30656667041c3cbf8382c Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Mon, 11 Dec 2023 20:52:34 +0100 Subject: [PATCH] Add VERSION constants within AutoMapper class and use it to cache transformers (#21) * Add VERSION constants within AutoMapper class and use it to cache transformers * Add some documentation about contributing & releases * Add static version check in CI --- .github/scripts/check-version.sh | 5 +++++ .github/workflows/ci.yml | 20 ++++++++++++++++++++ CHANGELOG.md | 1 + docs/contributing.md | 16 ++++++++++++++++ docs/navigation.md | 3 ++- src/AutoMapper.php | 7 +++++++ src/MapperMetadata.php | 2 ++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/check-version.sh create mode 100644 docs/contributing.md diff --git a/.github/scripts/check-version.sh b/.github/scripts/check-version.sh new file mode 100755 index 00000000..e199334b --- /dev/null +++ b/.github/scripts/check-version.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +LAST_TAG=`git describe --tags --abbrev=0` +IFS=. components=(${LAST_TAG##*-}) +exit `php -r "require_once __DIR__.'/vendor/autoload.php'; use AutoMapper\AutoMapper; echo (AutoMapper::MAJOR_VERSION >= intval(\"${components[0]}\") && AutoMapper::MINOR_VERSION >= intval(\"${components[1]}\")) ? 0 : 1;"` diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95b357d1..540b4d56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,3 +61,23 @@ jobs: run: composer update --prefer-stable - name: tests run: vendor/bin/phpunit + check-version: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@master + - name: cache-composer + uses: actions/cache@v2 + with: + path: ~/.composer/cache/ + key: composer-${{ github.sha }} + - name: setup + uses: shivammathur/setup-php@2.9.0 + with: + php-version: 8.2 + coverage: none + extensions: mbstring, fileinfo, json, intl, dom + - name: composer install + run: composer update --prefer-stable + - name: check version + run: ./.github/scripts/check-version.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index c7321888..9dd06931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - [GH#22](https://github.com/jolicode/automapper/pull/22) Added generic AST extractor +- [GH#21](https://github.com/jolicode/automapper/pull/21) Add VERSION constants within AutoMapper class and use it for transformers hashes ### Changed - [GH#19](https://github.com/jolicode/automapper/pull/19) Use attributes everywhere instead of annotations diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 00000000..a351508c --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,16 @@ +# Contributing + +## Releasing + +Whenever you're doing a release you need to do some updates in order for the project to keep history on what was done +and some other stuff. + +### Changelog + +First you'll need to update the CHANGELOG file (`./CHANGELOG.md`), take everything under the `Unreleased` section and +create a new section for your new tag with the today's date. + +### Version + +When a new version is tagged, you have to update the version constants within the `AutoMapper/AutoMapper` so +transformers can be updated with last AutoMapper version. diff --git a/docs/navigation.md b/docs/navigation.md index fc4eb921..20b53ac5 100644 --- a/docs/navigation.md +++ b/docs/navigation.md @@ -1,2 +1,3 @@ - [Quick start](/) -- [Symfony](/symfony) \ No newline at end of file +- [Symfony](/symfony) +- [Contributing](/contributing) \ No newline at end of file diff --git a/src/AutoMapper.php b/src/AutoMapper.php index 10446f79..07537e8c 100644 --- a/src/AutoMapper.php +++ b/src/AutoMapper.php @@ -41,6 +41,13 @@ */ class AutoMapper implements AutoMapperInterface, AutoMapperRegistryInterface, MapperGeneratorMetadataRegistryInterface { + public const VERSION = '8.1.0-DEV'; + public const VERSION_ID = 80100; + public const MAJOR_VERSION = 8; + public const MINOR_VERSION = 1; + public const RELEASE_VERSION = 0; + public const EXTRA_VERSION = 'DEV'; + /** @var MapperGeneratorMetadataInterface[] */ private array $metadata = []; diff --git a/src/MapperMetadata.php b/src/MapperMetadata.php index b46755e2..115bc765 100644 --- a/src/MapperMetadata.php +++ b/src/MapperMetadata.php @@ -149,6 +149,8 @@ public function getHash(): string $hash .= filemtime($reflection->getFileName()); } + $hash .= AutoMapper::VERSION_ID; + return $hash; }