Skip to content

Commit

Permalink
[#42] Converted to standalone Symfony Console CLI app (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 authored Mar 8, 2024
1 parent ef2c15c commit b5c19a7
Show file tree
Hide file tree
Showing 31 changed files with 598 additions and 363 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- run:
name: Deployment 1
command: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--force-push--circleci--[branch] \
--mode=force-push \
Expand All @@ -117,7 +117,7 @@ jobs:
- run:
name: Deployment 2
command: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--force-push--circleci--[branch] \
--mode=force-push \
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
- run:
name: Deployment 1
command: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--branch--circleci--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
Expand All @@ -183,7 +183,7 @@ jobs:
- run:
name: Deployment 2 - same branch
command: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--branch--circleci--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
Expand All @@ -203,7 +203,7 @@ jobs:
- run:
name: Deployment 2 - new branch
command: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--branch--circleci--[branch]--[timestamp:Y-m-d_H-i-s] \
--mode=branch \
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/box.json export-ignore
/tests export-ignore
/phpcs.xml export-ignore
/phpmd.xml export-ignore
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/release-php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release PHP

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
release-php:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1

- name: Install dependencies
run: composer install

- name: Build PHAR
run: composer build

- name: Test PHAR
run: ./.build/git-artifact || exit 1

- name: Get tag name
id: get-version
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
./.build/git-artifact
48 changes: 41 additions & 7 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,41 @@ jobs:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

build-php:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1

- name: Install dependencies
run: composer install

- name: Check composer version
run: composer --version

- name: Build PHAR
run: composer build

- name: Test PHAR
run: ./.build/git-artifact --help || exit 1
#;> PHP_PHAR

# Demonstration of deployment in 'force-push' mode.
deploy-force-push:
needs: test-php
needs:
- test-php
- build-php

runs-on: ubuntu-latest

Expand Down Expand Up @@ -123,7 +155,7 @@ jobs:
- name: Deployment 1
run: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--force-push--gha--[branch] \
--mode=force-push \
Expand All @@ -146,7 +178,7 @@ jobs:
- name: Deployment 2
run: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--force-push--gha--[branch] \
--mode=force-push \
Expand All @@ -164,7 +196,9 @@ jobs:
# of the second push. This is because the mode is intended to create a new
# branch per artifact deployment.
deploy-branch:
needs: test-php
needs:
- test-php
- build-php

runs-on: ubuntu-latest

Expand Down Expand Up @@ -223,7 +257,7 @@ jobs:
- name: Deployment 1
run: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
Expand All @@ -246,7 +280,7 @@ jobs:
- name: Deployment 2 - same branch
run: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
Expand All @@ -257,7 +291,7 @@ jobs:
- name: Deployment 2 - new branch
run: |
vendor/bin/robo artifact \
./git-artifact \
git@github.com:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i-s] \
--mode=branch \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/cobertura.xml
/composer.lock
/vendor
/vendor-bin
31 changes: 2 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,8 @@ composer require drevops/git-artifact
```

## Usage

Use provided [`RoboFile.php`](RoboFile.php) or create a custom `RoboFile.php`
in your repository with the following content:

```php
<?php
use DrevOps\Robo\ArtifactTrait;

/**
* Class RoboFile.
*/
class RoboFile extends \Robo\Tasks
{

use ArtifactTrait {
ArtifactTrait::__construct as private __artifactConstruct;
}

public function __construct()
{
$this->__artifactConstruct();
}
}
```

### Run
```shell
vendor/bin/robo artifact git@github.com:yourorg/your-repo-destination.git
./git-artifact git@github.com:yourorg/your-repo-destination.git
```

This will create an artifact from current directory and will send it to the
Expand All @@ -136,8 +110,7 @@ See examples:
Call from CI configuration or deployment script:
```shell
export DEPLOY_BRANCH=<YOUR_CI_PROVIDER_BRANCH_VARIABLE>
vendor/bin/robo --load-from "${HOME}/.composer/vendor/drevops/git-artifact/RoboFile.php" artifact \
git@github.com:yourorg/your-repo-destination.git \
./git-artifact git@github.com:yourorg/your-repo-destination.git \
--branch="${DEPLOY_BRANCH}" \
--push
```
Expand Down
28 changes: 0 additions & 28 deletions RoboFile.php

This file was deleted.

13 changes: 13 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"output": ".build/git-artifact",
"compression": "GZ",
"finder": [
{
"in": "./",
"exclude": [
"php-script",
"tests"
]
}
]
}
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drevops/git-artifact",
"type": "robo-tasks",
"type": "package",
"description": "Build artifact from your codebase in CI and push it to a separate git repo.",
"license": "GPL-2.0-or-later",
"authors": [
Expand All @@ -16,9 +16,14 @@
},
"require": {
"php": ">=8.1",
"consolidation/robo": "^4"
"cpliakas/git-wrapper": "^3.1",
"symfony/console": "^6",
"symfony/finder": "^6",
"symfony/filesystem": "^6",
"monolog/monolog": "^3.5"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"escapestudios/symfony2-coding-standard": "^3",
"phpmd/phpmd": "^2.15",
Expand All @@ -29,16 +34,17 @@
},
"autoload": {
"psr-4": {
"DrevOps\\Robo\\": "src"
"DrevOps\\GitArtifact\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"DrevOps\\Robo\\Tests\\": "tests"
"DrevOps\\GitArtifact\\Tests\\": "tests"
}
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
Expand All @@ -59,5 +65,8 @@
"box validate",
"box compile"
]
}
},
"bin": [
"git-artifact"
]
}
12 changes: 12 additions & 0 deletions git-artifact
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env php
<?php

foreach ([$GLOBALS['_composer_autoload_path'] ?? NULL, __DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
if ($file && file_exists($file)) {
require_once $file;
unset($file);
break;
}
}

require __DIR__ . '/src/app.php';
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@see https://github.com/squizlabs/PHP_CodeSniffer/issues/2916
-->
<file>src</file>
<file>RoboFile.php</file>
<file>tests</file>

<rule ref="Symfony.Commenting.License.Warning">
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parameters:
paths:
- src
- tests
- RoboFile.php

excludePaths:
- vendor/*
Expand Down
Loading

0 comments on commit b5c19a7

Please sign in to comment.