Skip to content

Commit

Permalink
ci(cc): add continuous integration workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreyvanwyk committed Aug 15, 2024
1 parent 490b33c commit 9607e88
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 3 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
# This file is part of Cookiecutter for Laravel package.
#
# Cookiecutter for Laravel package is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# Cookiecutter for Laravel package is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Cookiecutter for Laravel package. If not, see <https://www.gnu.org/licenses/>.

##
# GitHub Actions workflow that lints and tests new code before its integration
# into the master branch of the source code repository.
#
# @see {@link https://docs.github.com/en/actions} GitHub Actions
# @author Geoffrey Bernardo van Wyk <geoffrey@vanwyk.biz>
# @copyright 2024 Geoffrey Bernardo van Wyk {@link https://geoffreyvanwyk.dev}
# @license {@link http://www.gnu.org/copyleft/gpl.html} GNU GPL v3 or later
##

name: Continuous Integration

on:
pull_request:
branches:
- master

jobs:
cut-package:
name: Cut package from template
runs-on: ubuntu-22.04

steps:
- name: Checkout the source code from Git
uses: actions/checkout@v4

- name: Install Cookiecutter
run: pip install cookiecutter

- name: Install jq - commandline JSON processor
run: sudo apt install --yes jq

- name: Fill in template values
run: >
jq '.vendor_name |= "spoorsny"' cookiecutter.json |
jq '.package_name |= "laravel-potjiekos"' |
jq '.package_tite |= "Potjiekos for Laravel"' |
jq '.package_description |= "Have some potjiekos with your Laravel."' |
jq '.php_namespace |= "Spoorsny\Laravel"' |
jq '.github_username |= "spoorsny"' |
jq '.github_repository |= "laravel-potjiekos"' |
jq '.author_name |= "John Doe"' |
jq '.author_email |= "john@example.com"' |
jq '.author_website |= "https://www.example.com"'
> values.json
&& rm cookiecutter.json
&& mv values.json cookiecutter.json
- name: Cut package from template
run: |
cd ..
cookiecutter --no-input cookiecutter-laravel-package
mv laravel-potjiekos cookiecutter-laravel-package
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
path: laravel-potjiekos
name: laravel-potjiekos
retention-days: 1

lint-github-actions:
name: Lint GitHub Actions workflows
needs: cut-package
runs-on: ubuntu-22.04

steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: laravel-potjiekos
path: laravel-potjiekos

- name: Set up Go
uses: actions/setup-go@v4

- name: Set up linter
run: go install github.com/rhysd/actionlint/cmd/actionlint@latest

- name: Lint workflows
run: actionlint laravel-potjiekos/.github/workflows/*.yml

test-commands:
name: Test package commands
needs: lint-github-actions
runs-on: ubuntu-22.04

steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: laravel-potjiekos
path: laravel-potjiekos

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: xdebug

- name: Test commands
run: |
cd laravel-potjiekos
composer install
artisan make:model --migration Car
artisan migrate
artisan make:test --unit ExampleTest
artisan make:test --feature ExampleTest
artisan cache:clear
composer cs-fix
composer test
composer test-coverage
4 changes: 2 additions & 2 deletions {{ cookiecutter.package_name }}/composer.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
},
"autoload": {
"psr-4": {
"{{ cookiecutter.php_namespace }}\\": "src/"
"{{ cookiecutter.php_namespace | replace('\\', '\\\\') }}\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"{{ cookiecutter.php_namespace }}\\Tests\\": "tests/"
"{{ cookiecutter.php_namespace | replace('\\', '\\\\')}}\\Tests\\": "tests/"
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.package_name }}/tests/TestCase.php.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @license {@link http://www.gnu.org/copyleft/gpl.html} GNU GPL v3 or later
*/

namespace {{ cookiecutter.php_namespace | replace('\\\\', '\\') }}\Tests;
namespace {{ cookiecutter.php_namespace }}\Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

Expand Down

0 comments on commit 9607e88

Please sign in to comment.