-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Enhancement: Run phpstan on GitHub Actions #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,39 @@ on: | |
- master | ||
|
||
jobs: | ||
hello: | ||
name: Hello | ||
static-analysis: | ||
name: Static Analysis | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php-version: | ||
- 7.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we decide to run the static analysis on PHP 7.4, we only need to change the value here. |
||
|
||
steps: | ||
- name: Echo a greeting | ||
run: echo 'Hello, GitHub Actions!' | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to do something with the code, we need to check out the repository first. 💁♂️ For reference, see: |
||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use one of the PHP binaries that are natively available instead. However, these are currently limited to:
Additionally, a lot of extensions are installed, but not all (!) of them. Instead, a lot of people use Shivam Mathur does a great job in maintaining this action, and is very responsive. 💁♂️ For reference, see: |
||
with: | ||
coverage: none | ||
php-version: ${{ matrix.php-version }} | ||
|
||
- name: Determine composer cache directory | ||
id: determine-composer-cache-directory | ||
run: echo "::set-output name=directory::$(composer config cache-dir)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Steps can have outputs - for example, it is possible to define output parameters (like here) or environment variables. Here we determine the 💁♂️ For reference, see: |
||
|
||
- name: Cache dependencies installed with composer | ||
uses: actions/cache@v2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With 💁♂️ For reference, see: |
||
with: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the 💁♂️ For reference, see: |
||
path: ${{ steps.determine-composer-cache-directory.outputs.directory }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we pick up the output parameter again to specify a value for the Notice how we use the step identifier 💁♂️ For reference, see: |
||
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we specify a value for the Notice how we use the Also, we use the 💁♂️ For reference, see: |
||
restore-keys: php-${{ matrix.php-version }}-composer- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we can list one or more cache keys. Note that the inputs for an action need to be strings. If we want to specify more items, we need to use a multi-line string: diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index e7b00a0..07b7e54 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -38,7 +38,9 @@ jobs:
with:
path: ${{ steps.determine-composer-cache-directory.outputs.directory }}
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }}
- restore-keys: php-${{ matrix.php-version }}-composer-
+ restore-keys: |
+ php-${{ matrix.php-version }}-composer-
+ foo-bar-baz
- name: Install highest dependencies from composer.json
run: composer install --no-interaction Also note that the value for the 💁♂️ For reference, see: |
||
|
||
- name: Install dependencies | ||
run: composer install --no-interaction | ||
|
||
- name: Run phpstan/phpstan | ||
run: vendor/bin/phpstan analyse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By introducing a matrix strategy here, we can reference the resolved values using
${{ matrix.php-version }}
.Since we only run the static analysis for a single PHP version, it might seem that it does not make a lot of sense.
However, in my experience, it's quite useful, as we can reference the
${{ matrix.php-version }}
in multiple places without having to hard-code the actual PHP version.Also note how the matrix values are appended to the job name:
💁♂️ For reference, see: