From 9c8b0e3e1cdd66e2836c082ed9ff44cfc95c3be1 Mon Sep 17 00:00:00 2001 From: Dariusz Gafka Date: Sun, 28 May 2023 21:59:22 +0200 Subject: [PATCH] New release process --- .github/workflows/php-cs-fixer.yml | 42 -------------- .../{split-packages.yml => release.yml} | 58 +++++++++++++++---- bin/get-packages | 2 + bin/update-required-packages.php | 30 ++++++++++ 4 files changed, 79 insertions(+), 53 deletions(-) delete mode 100644 .github/workflows/php-cs-fixer.yml rename .github/workflows/{split-packages.yml => release.yml} (56%) create mode 100644 bin/update-required-packages.php diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml deleted file mode 100644 index 2d34c2df5..000000000 --- a/.github/workflows/php-cs-fixer.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: 'Ecotone Framework' - -on: - push: - branches: - - 'main' - tags-ignore: - - '*.*' - -jobs: - php-cs-fixer: - name: "Auto fix PHP CS" - runs-on: ubuntu-latest - - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Install PHP-CS-Fixer - run: | - composer global require friendsofphp/php-cs-fixer - export PATH="$PATH:$HOME/.composer/vendor/bin" - - - name: Run PHP CS Fixer - run: php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes - -# Should be reverted to when a release for 3.9 is made. It eliminates a lot of the above steps. -# uses: docker://oskarstark/php-cs-fixer-ga -# with: -# args: --config=.php-cs-fixer.dist.php --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Fixes styling diff --git a/.github/workflows/split-packages.yml b/.github/workflows/release.yml similarity index 56% rename from .github/workflows/split-packages.yml rename to .github/workflows/release.yml index cdbac757c..a26e7d223 100644 --- a/.github/workflows/split-packages.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,7 @@ -name: 'Ecotone Framework' +name: 'Releasing latest changes' on: push: - branches: - - main tags: - '*' @@ -12,8 +10,45 @@ env: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} jobs: + prepare-code-for-release: + name: "Auto fix PHP CS and set up required package versions" + runs-on: ubuntu-latest + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + + - +# In order to not be in detached state due to tag checkout + uses: actions/checkout@v2 + with: + ref: "main" + + - name: Install PHP-CS-Fixer + run: | + composer global require friendsofphp/php-cs-fixer + export PATH="$PATH:$HOME/.composer/vendor/bin" + + - name: Run PHP CS Fixer + run: php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes + + - name: Run Update Required Packages + run: php bin/update-required-packages.php ${{ github.ref_name }} + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Release ${{ github.ref_name }} + get_packages: name: Package splitting + needs: prepare-code-for-release runs-on: ubuntu-latest steps: @@ -46,26 +81,27 @@ jobs: package: ${{ fromJson(needs.get_packages.outputs.matrix) }} steps: - - uses: actions/checkout@v2 - # no tag - - if: "!startsWith(github.ref, 'refs/tags/')" + if: "startsWith(github.ref, 'refs/tags/')" + uses: actions/checkout@v2 + with: +# this is because we need to commit to main branch changes with composer.json required versions + ref: "main" + fetch-depth: '0' + - uses: "danharrin/monorepo-split-github-action@v2.3.0" with: # ↓ split "packages/easy-coding-standard" directory package_directory: '${{ matrix.package.directory }}' # ↓ into https://github.com/symplify/easy-coding-standard repository - repository_organization: 'ecotoneframework' + repository_organization: '${{ matrix.package.organisation }}' repository_name: '${{ matrix.package.repository }}' # ↓ the user signed under the split commit user_name: "Dariusz Gafka" user_email: "dgafka.mail@gmail.com" - - # with tag - - if: "startsWith(github.ref, 'refs/tags/')" uses: "danharrin/monorepo-split-github-action@v2.3.0" with: tag: ${GITHUB_REF#refs/tags/} @@ -74,7 +110,7 @@ jobs: package_directory: '${{ matrix.package.directory }}' # ↓ into https://github.com/symplify/easy-coding-standard repository - repository_organization: 'ecotoneframework' + repository_organization: '${{ matrix.package.organisation }}' repository_name: '${{ matrix.package.repository }}' # ↓ the user signed under the split commit diff --git a/bin/get-packages b/bin/get-packages index e890f941f..7adc9f080 100755 --- a/bin/get-packages +++ b/bin/get-packages @@ -44,6 +44,7 @@ function getPackages(): array { $packages[] = [ 'directory' => $directory->getRealPath(), 'name' => getPackageNameFromComposerFile($file), + 'organisation' => 'ecotoneframework', 'repository' => getRepositoryFromComposerFile($file) ]; } @@ -51,6 +52,7 @@ function getPackages(): array { $packages[] = [ 'directory' => realpath(__DIR__ . "/../quickstart-examples"), 'name' => "quickstart-examples", + 'organisation' => 'ecotoneframework', 'repository' => "quickstart-examples" ]; diff --git a/bin/update-required-packages.php b/bin/update-required-packages.php new file mode 100644 index 000000000..6fd6545d4 --- /dev/null +++ b/bin/update-required-packages.php @@ -0,0 +1,30 @@ + $requiredVersion) { + if (in_array($requiredPackage, $packageNames)) { + $composer['require'][$requiredPackage] = "~" . $version; + } + } + foreach ($composer['require-dev'] as $requiredPackage => $requiredVersion) { + if (in_array($requiredPackage, $packageNames)) { + $composer['require-dev'][$requiredPackage] = '~' . $version; + } + } + + file_put_contents($composerFile, json_encode($composer, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)); +} \ No newline at end of file