Skip to content

Commit 56fa365

Browse files
Actions (#96)
* ci: add/update deps * fix: php-cs-fixer * ci: refactor + add php-cs-fixer * ci: added * fix: typo * fix: typo * fix: add max-parallel * fix: move max-parallel up one level
1 parent 5170655 commit 56fa365

File tree

13 files changed

+160
-35
lines changed

13 files changed

+160
-35
lines changed

.github/workflows/ci.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@ concurrency:
88

99
jobs:
1010
basic:
11-
name: Run tests on PHP ${{ matrix.php_version }}
11+
name: Run tests on PHP ${{ matrix.php-versions }}
1212
runs-on: ubuntu-latest
1313
strategy:
14+
max-parallel: 1
1415
matrix:
15-
php_version: ['8.0', '8.1', '8.2']
16-
fail-fast: false
16+
php-versions: ['8.0', '8.1', '8.2']
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919

2020
- name: Setup PHP
2121
uses: shivammathur/setup-php@v2
2222
with:
23-
php-version: ${{ matrix.php_version }}
24-
tools: composer
23+
php-version: ${{ matrix.php-versions }}
24+
tools: composer:v2
2525

26-
- name: Install dependencies
27-
run: composer install
26+
- name: Deps
27+
run: composer install --no-interaction
2828

29-
- name: Run tests
30-
run: ./vendor/bin/phpunit
29+
- name: Quality
30+
if: matrix.php-versions == '8.0'
31+
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation
32+
33+
- name: Test
34+
run: vendor/bin/phpunit
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create release PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The new version number. Example: 1.40.1"
8+
required: true
9+
10+
jobs:
11+
init_release:
12+
name: 🚀 Create release PR
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Update CHANGELOG.md, Client.php and push release branch
20+
env:
21+
VERSION: ${{ github.event.inputs.version }}
22+
run: |
23+
npx --yes [email protected] --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=
24+
git config --global user.name 'github-actions'
25+
git config --global user.email '[email protected]'
26+
git checkout -q -b "release-$VERSION"
27+
git commit -am "chore(release): $VERSION"
28+
git push -q -u origin "release-$VERSION"
29+
30+
- name: Get changelog diff
31+
uses: actions/github-script@v6
32+
with:
33+
script: |
34+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
35+
core.exportVariable('CHANGELOG', get_change_log_diff())
36+
37+
- name: Open pull request
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
gh pr create \
42+
-t "chore(release): release ${{ github.event.inputs.version }}" \
43+
-b "# :rocket: ${{ github.event.inputs.version }}
44+
Make sure to use squash & merge when merging!
45+
Once this is merged, another job will kick off automatically and publish the package.
46+
# :memo: Changelog
47+
${{ env.CHANGELOG }}"

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
9+
jobs:
10+
Release:
11+
name: 🚀 Release
12+
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- uses: actions/github-script@v6
20+
with:
21+
script: |
22+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
23+
core.exportVariable('CHANGELOG', get_change_log_diff())
24+
25+
// Getting the release version from the PR source branch
26+
// Source branch looks like this: release-1.0.0
27+
const version = context.payload.pull_request.head.ref.split('-')[1]
28+
core.exportVariable('VERSION', version)
29+
30+
- name: Create release on GitHub
31+
uses: ncipollo/release-action@v1
32+
with:
33+
body: ${{ env.CHANGELOG }}
34+
tag: ${{ env.VERSION }}
35+
token: ${{ secrets.GITHUB_TOKEN }}

.php-cs-fixer.dist.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->in(__DIR__)
6+
;
7+
8+
$config = new PhpCsFixer\Config();
9+
return $config->setRules([
10+
'@PSR2' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
])
13+
->setFinder($finder)
14+
;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"get-stream/stream": "^7.0.1"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "^9.6",
20+
"friendsofphp/php-cs-fixer": "^3.14.0",
21+
"phpunit/phpunit": "^9.6.3",
2122
"mockery/mockery": "^1.5"
2223
},
2324
"autoload": {

scripts/get_changelog_diff.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Here we're trying to parse the latest changes from CHANGELOG.md file.
3+
The changelog looks like this:
4+
5+
## 0.0.3
6+
- Something #3
7+
## 0.0.2
8+
- Something #2
9+
## 0.0.1
10+
- Something #1
11+
12+
In this case we're trying to extract "- Something #3" since that's the latest change.
13+
*/
14+
module.exports = () => {
15+
const fs = require('fs')
16+
17+
changelog = fs.readFileSync('CHANGELOG.md', 'utf8')
18+
releases = changelog.match(/## [?[0-9](.+)/g)
19+
20+
current_release = changelog.indexOf(releases[0])
21+
previous_release = changelog.indexOf(releases[1])
22+
23+
latest_changes = changelog.substr(current_release, previous_release - current_release)
24+
25+
return latest_changes
26+
}

src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,16 @@ public function createActivity()
135135

136136
$to = $this->activityNotify();
137137

138-
if ( $to !== null )
139-
{
138+
if ($to !== null) {
140139
$activity['to'] = [];
141-
foreach ( $to as $feed )
142-
{
140+
foreach ($to as $feed) {
143141
$activity['to'][] = $feed->getId();
144142
}
145143
}
146144

147145
$extra_data = $this->activityExtraData();
148146

149-
if ( $extra_data !== null )
150-
{
147+
if ($extra_data !== null) {
151148
$activity = array_merge($activity, $extra_data);
152149
}
153150

src/GetStream/StreamLaravel/Enrich.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public function fromDb($model, $ids, $with = [])
2525
'Illuminate\Database\Eloquent\SoftDeletingTrait'
2626
];
2727

28-
if ((bool)array_intersect($softDeleteTraits, class_uses(get_class($model))) && $this->withTrashed) // previous withTrash method deprecated in Laravel 4.2
28+
if ((bool)array_intersect($softDeleteTraits, class_uses(get_class($model))) && $this->withTrashed) { // previous withTrash method deprecated in Laravel 4.2
2929
$query = $query->withTrashed();
30+
}
3031
$objects = $query->get();
3132
foreach ($objects as $object) {
3233
$results[$object->getKey()] = $object; // support for non-default UUID keys
@@ -80,8 +81,9 @@ private function injectObjects(&$activities, $objects)
8081
{
8182
foreach ($activities as $key => $activity) {
8283
foreach ($this->fields as $field) {
83-
if (!isset($activity[$field]))
84+
if (!isset($activity[$field])) {
8485
continue;
86+
}
8587
$value = $activity[$field];
8688
$reference = explode(':', $value);
8789
if (!array_key_exists($reference[0], $objects)) {

src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ protected function registerResources()
6161
} else {
6262
//only set if we dont have a config file for stream-laravel
6363
$namespace = 'stream-laravel.';
64-
foreach($config as $key => $value) {
65-
$this->app['config']->set($namespace . $key , $value);
64+
foreach ($config as $key => $value) {
65+
$this->app['config']->set($namespace . $key, $value);
6666
}
6767
}
6868
}

src/GetStream/StreamLaravel/StreamLumenServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function register()
3636
$this->registerResources();
3737
}
3838

39-
$this->app->singleton('feed_manager', function($app) {
39+
$this->app->singleton('feed_manager', function ($app) {
4040
$manager_class = config('stream-laravel.feed_manager_class');
4141
$api_key = config('stream-laravel.api_key');
4242
$api_secret = config('stream-laravel.api_secret');
@@ -62,8 +62,8 @@ protected function registerResources()
6262
} else {
6363
//only set if we dont have a config file for stream-laravel
6464
$namespace = 'stream-laravel.';
65-
foreach($config as $key => $value) {
66-
$this->app['config']->set($namespace . $key , $value);
65+
foreach ($config as $key => $value) {
66+
$this->app['config']->set($namespace . $key, $value);
6767
}
6868
}
6969
}

0 commit comments

Comments
 (0)