Skip to content

Commit

Permalink
New release process
Browse files Browse the repository at this point in the history
  • Loading branch information
dgafka committed May 28, 2023
1 parent 1fffeea commit 9c8b0e3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 53 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/php-cs-fixer.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: 'Ecotone Framework'
name: 'Releasing latest changes'

on:
push:
branches:
- main
tags:
- '*'

Expand All @@ -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:
Expand Down Expand Up @@ -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/}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions bin/get-packages
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ function getPackages(): array {
$packages[] = [
'directory' => $directory->getRealPath(),
'name' => getPackageNameFromComposerFile($file),
'organisation' => 'ecotoneframework',
'repository' => getRepositoryFromComposerFile($file)
];
}

$packages[] = [
'directory' => realpath(__DIR__ . "/../quickstart-examples"),
'name' => "quickstart-examples",
'organisation' => 'ecotoneframework',
'repository' => "quickstart-examples"
];

Expand Down
30 changes: 30 additions & 0 deletions bin/update-required-packages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

require __DIR__ . '/get-packages';
$packages = getPackages();

$version = $argv[1];
if (!$version) {
throw new \InvalidArgumentException("Pass version to update branch alias");
}
$packageNames = array_map(function ($package) {
return $package['organisation'] . '/' . $package['name'];
}, $packages);

foreach ($packages as $package) {
$composerFile = $package['directory'] . DIRECTORY_SEPARATOR . 'composer.json';
$composer = json_decode(file_get_contents($composerFile), true);
$composer['extra']['branch-alias']['dev-main'] = $version . '-dev';
foreach ($composer['require'] as $requiredPackage => $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));
}

0 comments on commit 9c8b0e3

Please sign in to comment.