Skip to content

Commit

Permalink
MNT Add auto-tag workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 1, 2022
1 parent 84534e4 commit c8bd035
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 39 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Auto-tag
on:
push:
tags:
- '*.*.*'
jobs:
auto-tag:
name: Auto-tag
runs-on: ubuntu-latest
steps:
# TODO: delete debug
- name: Debug
run: |
echo ${{ github.ref_name }}
echo ${{ github.repository }}
- name: Auto-tag
# TODO: change to silverstripe/gha-auto-tag
uses: emteknetnz/gha-auto-tag@main
25 changes: 16 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: ci

name: CI
on:
workflow_call:
inputs:
# extra jobs must be multi-line string, as there's no support for type: array for inputs
# extra jobs must be multi-line string, as there's no support for `type: array` for inputs
extra_jobs:
type: string
required: false
Expand All @@ -12,9 +11,9 @@ on:
type: string
required: false
default: ''
# simple matrix will only run a single php 7.4 mysql 5.7 job instead of a full matrix
# TODO: change to matrix_options - 'simple disabled' space separated, allows for future config
# disabled would have no auto generated and only output extra_jobs
dynamic_matrix:
type: boolean
default: true
simple_matrix:
type: boolean
default: false
Expand All @@ -23,7 +22,6 @@ on:
default: true
phpcoverage:
type: boolean
# modules on silverstripe account will ignore this and always run codecov
default: false
phplinting:
type: boolean
Expand Down Expand Up @@ -63,6 +61,8 @@ jobs:
genmatrix:
name: Generate matrix
runs-on: ubuntu-latest

# gha-generate-matrix script.php will sanitise matrix outputs so they're safe to use within bash
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}

Expand Down Expand Up @@ -145,6 +145,7 @@ jobs:
${{ matrix.name_suffix }}
steps:

- name: Checkout code
uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # @v2

Expand Down Expand Up @@ -263,6 +264,10 @@ jobs:
INPUTS_COMPOSER_REQUIRE_EXTRA: ${{ inputs.composer_require_extra }}
MATRIX_COMPOSER_REQUIRE_EXTRA: ${{ matrix.composer_require_extra }}
run: |
# Remove double quotes
INPUTS_COMPOSER_REQUIRE_EXTRA=${INPUTS_COMPOSER_REQUIRE_EXTRA//\"/}
MATRIX_COMPOSER_REQUIRE_EXTRA=${MATRIX_COMPOSER_REQUIRE_EXTRA//\"/}
# Update composer.json and install dependencies
# github.base_ref is only available on pull-requests events is the target branch - is is NOT prefixed with refs/heads/
# github.ref_name is used for regular branch builds on events push - it is NOT prefixed with refs/heads/
Expand Down Expand Up @@ -303,11 +308,13 @@ jobs:
composer require silverstripe/cow:dev-master --dev --no-update
fi
if [ "$INPUTS_COMPOSER_REQUIRE_EXTRA" != "" ]; then
# TODO: test that requiring multiple modules seperated with a space here works
# $INPUTS_COMPOSER_REQUIRE_EXTRA is explicitly not wrapped in double quotes
# so that multiple requirements separated by spaces will work
composer require $INPUTS_COMPOSER_REQUIRE_EXTRA --no-update
fi
if [ "$MATRIX_COMPOSER_REQUIRE_EXTRA" != "" ]; then
# TODO: test that requiring multiple modules seperated with a space here works
# $MATRIX_COMPOSER_REQUIRE_EXTRA is explicitly not wrapped in double quotes
# so that multiple requirements separated by spaces will work
composer require $MATRIX_COMPOSER_REQUIRE_EXTRA --no-update
fi
Expand Down
90 changes: 60 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# GitHub Actions - CI

CI used by Silverstripe modules
CI for Silverstripe modules

Will use feature detection based on files in the root folder such as phpunit.xml.dist to build dynmaic matrix of tests to run
Uses feature detection based on files in the root folder such as phpunit.xml.dist to build dynamic matrix of jobs to run

It's highly recommended that you use a tagged version (e.g. v0.2) to ensure stability of your builds. If you have a relatively simple build that you have no intention of ever making more complex e.g. only phpunit tests using phpunit.xml.dist, then this is probably all you need for long term use.
It's highly recommended that you use a tagged version (e.g. v1) to ensure stability of your builds. If you have a relatively simple build that you have no intention of ever making more complex e.g. only phpunit tests using phpunit.xml.dist, then this is probably all you need for long term use.

This repository is currently in development and code on the `main` branch could change at any time, including taking on a whole new direction. It's expected that new functionality will be added.
Note: Unlike other silverstripe/gha-* repositories, this one is a [reusable workflow](https://docs.github.com/en/actions/using-workflows/reusing-workflows) rather than an [action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action). A reusable workflow is required to create a `matrix`.

Note: Unlike other silverstripe/gha-* repositiories, this one is a [reusable workflow](https://docs.github.com/en/actions/using-workflows/reusing-workflows) rather than an [action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action). A reusable workflow is required to create a `matrix`.
### Usage

### CI Usage

Create the following file in your module

(subsitute the tagged version for the most recent tag from this module)
Create the following file in your module, and substitute the tagged version for the most recent `v` from this module e.g. `@v1`

**.github/workflows/ci.yml**
```yml
Expand All @@ -30,47 +26,81 @@ jobs:
uses: silverstripe/ghi-ci/.github/workflows/ci.yml@main
```
Use the following if your module does not have a `phpcs.xml.dist` file

(or better still, copy paste this [sample phpcs.xml.dist](https://raw.githubusercontent.com/silverstripe/silverstripe-elemental/4/phpcs.xml.dist) file in to your module)
Set config specific to your needs via "inputs" defined under the `with:` key. For instance, to disable PHP linting because you module does not does not yet have a `phpcs.xml.dist` file

```yml
jobs:
ci:
uses: silverstripe/github-actions-ci-cd/.github/workflows/ci.yml@v0.2
uses: silverstripe/github-actions-ci-cd/.github/workflows/ci.yml@main
with:
phplinting: false
```

#### Some other "with" options
#### Inputs:

Extra composer requirements
You do not need to quote the string for multiple requirements
*Extra composer requirements*
Require additional modules through composer for matrix entries. You do not need to quote the string for multiple requirements
`composer_require_extra: silverstripe/widgets:^2 silverstripe/comments:^3`

Simple matrix - php 7.4 with mysql 5.7 only
*Simple matrix*
Create a smaller matrix with only the lowest supported PHP version lowest supported MySQL only instead of a full matrix of multiple PHP and database versions. Default is false, enable with:
`simple_matrix: true`

Enable php coverage (codecov - no feature detection)
Modules on the silverstripe account will automaticaly have this enabled
*Dyanmic matrix*
Dynamically generate a matrix using feature detection. If disabled, jobs must be defined using the extra_jobs input. Default is true, disable with:
`dynamic_matrix: false`

*PHPUnit tests*
Runs phpunit if config file is phpunit.xml or phpunit.xml.dist is available. Default is true, disable phpunit tests with:
`phpunit: false`

*PHP linting*
Runs phpcs and phpstan if config files phpcs.xml.dist or phpstan.neon.dist are available. Default is true, disable with:
`phplinting: false`

*PHP coverage*
Run codecov, does not require a configuration file. Default is false, though modules on the silverstripe account will always have this enabled, enable with:
`phpcoverage: true`

Disable end-to-end tests (behat.yml):
*End-to-end tests*
Runs behat tests is behat.yml is available. Default is true, disable end-to-end tests with:
`endtoend: false`

Disable JS tests (package.json - yarn lint, test and build diff):
*JS tests*
Runs JS tests such as yarn lint, yarn test and yarn build diff if config file package.json is available. Default is true, disable JS tests with:
`js: false`

Disable phpunit tests (phpunit.xml.dist / phpunit.xml)
`phpunit: false`

Disable php linting (phpcs.xml.dist, phpstan.neon.dist)
`phplinting: false`

Extra jobs
Define php version and/or db
*Extra jobs*
Define php version and/or db. All inputs are false by default so you only need to include config for the input you want enabled. All inputs except `dynamic_matrix` and `simple_matrix` are available in this context. Use a multi-line yml string.
```yml
extra_jobs: |
- php: '8.0'
db: pgsql
phpunit: true
phpunit_suite: api
- php: '8.1'
endtoend: true
endtoend_suite: admin
endtoend_config: vendor/silverstripe/admin/behat.yml
```

*Extra jobs - additional inputs*
Additional inputs that can be applied to individual jobs within the extra_jobs input

**php**
The version of PHP to run e.g. 8.1

**db**
The database to run e.g. mysql80 - for the list of support DB's - see [gha-generate-matrix](https://github.com/silverstripe/gha-generate-matrix/blob/main/script.php)

**name_suffix**
Text to suffix to job and artifact names to make them easier to identify

**phpunit_suite**
The PHPUnit suite to run as defined in phpunit.xml, translates to the `--testsuite

**endtoend_suite**
The end-to-end suite as defined in behat.yml. Must be defined, specify 'root' to run the default

**endtoend_config**
The behat.yml config file to used if not using the root behat.yml. Only used if running behat tests in a different module

0 comments on commit c8bd035

Please sign in to comment.