Skip to content

Commit 0926c3a

Browse files
Merge pull request #3 from codenamephp/main
First release
2 parents 30fa29e + cec5f4b commit 0926c3a

65 files changed

Lines changed: 3125 additions & 346 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
/test export-ignore
22
/tools export-ignore
3+
/.github export-ignore
34
/.idea export-ignore
45
/.gitattributes export-ignore
56
/.gitignore export-ignore
67
/.cache export-ignore
78
/.logs export-ignore
89
/.php_cs.dist export-ignore
10+
/docker export-ignore
11+
/.env.dist export-ignore
12+
/docker-compose.yml export-ignore
913
/infection.json.dist export-ignore
1014
/phive.xml export-ignore
1115
/phpcomp.xml export-ignore
12-
/psalm.xml export-ignore
16+
/psalm.xml export-ignore
17+
.gitkeep export-ignore

.github/workflows/ci.yml

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: CI
23

34
on:
@@ -15,40 +16,7 @@ on:
1516
- '**.md'
1617

1718
jobs:
18-
test_latest:
19-
strategy:
20-
matrix:
21-
php-versions: [ '8.1' ]
22-
prefer: [ 'prefer-lowest', 'prefer-stable' ]
23-
name: Test with ${{ matrix.prefer }} dependency versions on PHP ${{ matrix.php-versions }}
24-
runs-on: ubuntu-latest
25-
26-
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v2
29-
30-
- name: Setup PHP
31-
uses: shivammathur/setup-php@v2
32-
with:
33-
php-version: ${{ matrix.php-versions }}
34-
coverage: xdebug
35-
36-
- name: Validate composer.json
37-
run: composer validate
38-
39-
- name: Get Composer Cache Directory
40-
id: composer-cache
41-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42-
- name: Setup cache
43-
uses: actions/cache@v2
44-
with:
45-
path: ${{ steps.composer-cache.outputs.dir }}
46-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.prefer }}-
47-
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
48-
49-
- name: Install dependencies
50-
if: steps.composer-cache.outputs.cache-hit != 'true'
51-
run: composer update --prefer-dist --no-ansi --no-interaction --no-progress --${{ matrix.prefer }}
52-
53-
- name: Run CI tools
54-
run: composer ci-all
19+
ci:
20+
uses: codenamephp/workflows.php/.github/workflows/ci.yml@main
21+
with:
22+
php-versions: '["8.1"]'

.github/workflows/post-release.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/prepare-release.yml

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,16 @@ on:
77

88
jobs:
99
calculate_next_version:
10-
name: Calculate next release version
11-
runs-on: ubuntu-latest
12-
outputs:
13-
version: ${{ steps.version.outputs.next-version }}
14-
steps:
15-
- name: calculate next version
16-
id: version
17-
uses: patrickjahns/version-drafter-action@v1
18-
env:
19-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20-
10+
uses: codenamephp/workflows.common/.github/workflows/calculate-next-version.yml@main
2111
draft_release:
22-
name: Create draft release
23-
runs-on: ubuntu-latest
2412
needs: calculate_next_version
25-
steps:
26-
- name: draft release
27-
uses: release-drafter/release-drafter@v5
28-
with:
29-
version: ${{ format('{0}', needs.calculate_next_version.outputs.version) }}
30-
tag: ${{ format('{0}', needs.calculate_next_version.outputs.version) }}
31-
name: ${{ format('{0}', needs.calculate_next_version.outputs.version) }}
32-
env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34-
13+
uses: codenamephp/workflows.common/.github/workflows/draft-release.yml@main
14+
with:
15+
version: ${{ needs.calculate_next_version.outputs.version }}
3516
update_changelog:
36-
name: Update changelog
37-
runs-on: ubuntu-latest
17+
uses: codenamephp/workflows.common/.github/workflows/update-changelog.yml@main
3818
needs: calculate_next_version
39-
steps:
40-
- name: checkout
41-
uses: actions/checkout@v2
42-
43-
- name: create changelog
44-
uses: charmixer/auto-changelog-action@v1.1
45-
with:
46-
token: ${{ secrets.GITHUB_TOKEN }}
47-
exclude_labels: "duplicate,question,invalid,wontfix,skip-changelog"
48-
future_release: ${{ format('{0}', needs.calculate_next_version.outputs.version) }}
49-
release_branch: 'release'
50-
51-
- name: commit updated changelog
52-
uses: EndBug/add-and-commit@v7
53-
with:
54-
message: "[CHANGELOG] Updated changelog"
55-
add: "CHANGELOG.md"
56-
signoff: true
19+
with:
20+
ref: ${{github.ref_name}}
21+
future_release: ${{ needs.calculate_next_version.outputs.version }}
22+
release_branch: 'release'

.github/workflows/update-changelog.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@ on:
77

88
jobs:
99
update_changelog:
10-
name: Update changelog
11-
runs-on: ubuntu-latest
12-
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v2
15-
16-
- name: create changelog
17-
uses: charmixer/auto-changelog-action@v1
18-
with:
19-
token: ${{ secrets.GITHUB_TOKEN }}
20-
exclude_labels: "duplicate,question,invalid,wontfix,skip-changelog"
21-
22-
- name: commit updated changelog
23-
uses: EndBug/add-and-commit@v7
24-
with:
25-
message: "[CHANGELOG] Updated changelog"
26-
add: "CHANGELOG.md"
27-
signoff: true
10+
uses: codenamephp/workflows.common/.github/workflows/update-changelog.yml@main
11+
with:
12+
ref: ${{github.ref_name}}

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/ci_all.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,116 @@ Base package that provides the very basic task interface, function abstraction a
88

99
## What is it?
1010

11-
This package is an extension to deployer that adds basic tasks and interfaces and abstracts the actual deployer API.
11+
This package is an extension to deployer that adds basic tasks and interfaces and abstracts the actual deployer API. Deployer can still be used as usual but I
12+
would recommend implementing your tasks as classes and write unit tests for them. If you have tasks you reuse across projects you should create your own
13+
packages. There are already several codenamephp/deployer.* packages available to use.
1214

13-
## But ... why?
15+
### But ... why?
1416

1517
I really like testable code and since the actual deploy.php is otherwise just a collection of callbacks that is hard to test I added basic interfaces and
1618
classes that encapsulate the tasks and make them reusable.
1719

1820
Sure, you could make it work with lambdas but since PHP is not intended to be a functional programming language it's far easier to just throw some classes into
19-
the mix.
21+
the mix.
22+
23+
## Install
24+
25+
Just add the package to composer, ideally by executing `composer require codenamephp/deployer.base` which should install the latest version with semver range.
26+
27+
## Usage
28+
29+
Just create your `deploy.php` as usual. Then just add existing tasks or implement your own and add them using the package functions:
30+
31+
```php
32+
const PROJECT_ROOT = __DIR__ . '/..'; // I have deployer in a seperate folder so this makes creating paths easier
33+
34+
$deployerFunctions = new All(); // Abstraction of deployer function and also has some additional methods
35+
36+
$deployerFunctions->registerTask(new UploadTransferables( // My version of deploying code in NEOS projects
37+
new Simple(PROJECT_ROOT . '/Configuration', '{{release_path}}'),
38+
new Simple(PROJECT_ROOT . '/DistributionPackages', '{{release_path}}', ['Tests/']),
39+
new Simple(PROJECT_ROOT . '/Packages', '{{release_path}}'),
40+
new Simple(PROJECT_ROOT . '/Web', '{{release_path}}', ['_Resources/']),
41+
new Simple(PROJECT_ROOT . '/flow', '{{release_path}}'),
42+
));
43+
44+
// additional tasks from other packages
45+
$deployerFunctions->task('composer:install', new \de\codenamephp\deployer\composer\task\install\Production())->desc('Run composer install for production.');
46+
$deployerFunctions->task('composer:install:development', new \de\codenamephp\deployer\composer\task\install\Development())->desc('Run composer install for production.');
47+
48+
(new ByTaskListAndMatchers(new AtLeastOne( // clean up the cli list
49+
new ByRegexTaskName('/provision:?.*/'),
50+
new ByRegexTaskName('/logs:caddy.*/'),
51+
new ByRegexTaskName('/deploy:.*/')
52+
)))->hide();
53+
```
54+
55+
### Implementing tasks
56+
57+
Deployer just expects a callable as task so in theory this is everything a task needs. This package contains the
58+
`\de\codenamephp\deployer\base\task\iTask` interface that enforces this so we can just add a new instance of the task.
59+
60+
There are also the `\de\codenamephp\deployer\base\task\iTaskWithName` and `\de\codenamephp\deployer\base\task\iTaskWithDescription` interfaces. These can be
61+
used to set the description and name of the task directly in the class so we don't have to set the same strings in each project and clutter up our deployment
62+
file. At the very least the `\de\codenamephp\deployer\base\task\iTaskWithName` has to be implemented so we can pass the task to
63+
`\de\codenamephp\deployer\base\functions\iTask::registerTask` that takes care of the rest.
64+
65+
### Deployer Functions
66+
67+
The built in deployer functions require a running Deployer instance and are global so they are very hard to mock. In order for our tasks to be testable there
68+
are several `\de\codenamephp\deployer\base\functions\*` interfaces, one for each method or method group. There is also an
69+
`\de\codenamephp\deployer\base\functions\iAll` interface that combines them all as convenience if we need several methods. Likewise there's an
70+
`\de\codenamephp\deployer\base\functions\All` implementation that acts mostly as a proxy for the global methods and also does some additional type checking.
71+
72+
The interfaces are mostly the same as the deployer built in methods but add some additional type hints and return hints for a cleaner API.
73+
74+
Use these interfaces in your tasks and either use the `\de\codenamephp\deployer\base\functions\All` implementation or write your own. In your tests you can then
75+
easily mock these interfaces.
76+
77+
### Host Check
78+
79+
Some task should not be executed by accident, for example pushing a database from local to production. This can be easily achieved by adding
80+
the `\de\codenamephp\deployer\base\hostCheck\iHostCheck` interface as dependency to your task and calling the
81+
`\de\codenamephp\deployer\base\hostCheck\iHostCheck::check` method in your `__invoke()` method.
82+
83+
#### DoNotRunOnProduction
84+
85+
This implementation assumes the production host actually has the alias "production" (can be changed in constructor) and checks against the current host. If the
86+
alias matches an `\de\codenamephp\deployer\base\UnsafeOperationException` is thrown which halts your deployer run. If you have things to clean up (e.g. a
87+
database dump) you should add cleanup tasks to the failure step.
88+
89+
#### WithDisallowList
90+
91+
Similar to DoNotRunOnProduction but with a whole list of disallowed aliases.
92+
93+
#### SkippableByOption
94+
95+
This is a decorator for the adding the `\de\codenamephp\deployer\base\hostCheck\iHostCheck` that takes an existing host check but only executes it if the
96+
`--cpd:skip-host-check` (or `-cpd:shc` as shorthand) are not set. This way we can skip the host check if we know what we are doing ... at your own risk of
97+
course. ;)
98+
99+
### Task Hider / Task Matcher
100+
101+
Deployer comes with a whole set of default tasks, like the whole `provision` namespace. These are usually used once (if at all) and just clutter up the CLI
102+
list. The `\de\codenamephp\deployer\base\taskHider\iTaskHider` can be used to hide those tasks you don't want. The default implementation The default
103+
implementation `\de\codenamephp\deployer\base\taskHider\ByTaskListAndMatchers` uses a `\de\codenamephp\deployer\base\taskMatcher\iTaskMatcher` implementation to
104+
find tasks to hide. There is also a collection that can be used to just add multiple matchers and hide all the matches.
105+
106+
An example could look like this:
107+
108+
```php
109+
(new ByTaskListAndMatchers(new AtLeastOne( // clean up the cli list
110+
new ByRegexTaskName('/provision:?.*/'),
111+
new ByRegexTaskName('/logs:caddy.*/'),
112+
new ByRegexTaskName('/deploy:.*/')
113+
)))->hide();
114+
```
115+
116+
### Transferables
117+
118+
There is a `\de\codenamephp\deployer\base\transferable\iTransferable` interface that makes file transfers more readable by clearly stating what is local and
119+
remote.
120+
121+
### Tasks
122+
123+
Maybe I'm going to include an Open API generated manual at some point but for now just check the classes in the `\de\codenamephp\deployer\base\task` namespace.

0 commit comments

Comments
 (0)