-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
99 lines (99 loc) · 4.29 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: TAO extension CI
description: Executes a CI pipeline on a TAO extension
inputs:
php:
description: PHP version to power the CI
required: true
coverage:
description: Boolean flag controlling whether or not the pipeline will generate a code coverage report
required: false
type: boolean
default: false
test-suites-path:
description: Relative path to the test suits
required: false
default: test/unit
github_token:
description: Pass the CI_GITHUB_TOKEN when calling this workflow
default: ''
required: false
runs:
using: composite
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php }}
- name: Fetch extension's properties
id: extension
shell: bash
run: |
echo ::set-output name=name::$(composer config name --no-interaction --no-plugins)
echo ::set-output name=ref::"$([ -z "$(git branch --show-current)" ] && git rev-parse --verify HEAD || git branch --show-current)"
echo ::set-output name=dependencies::$(composer show --self --direct | awk "/requires \(dev\)/" RS= | tail -n +2 | sed "s/ /:/" | awk '{ print "\""$0"\""}')
- name: Validate dependencies' list
shell: bash
run: composer validate --no-interaction --no-plugins
- name: Configure authorization for private repositories
shell: bash
run: composer config -g github-oauth.github.com ${{ inputs.github_token }}
if: ${{ inputs.github_token }}
- name: Move sources
shell: bash
run: mkdir src && mv * src || true
- name: Initialize composer dependencies
shell: bash
run: composer init --name oat-sa/tao-extension-ci-action --no-interaction && composer config repositories.0 path ./src --no-interaction
- name: Disable NPM plugin
shell: bash
run: composer config allow-plugins.oat-sa/composer-npm-bridge false --no-interaction --no-plugins
- name: Allow TAO extension installer plugin
shell: bash
run: composer config allow-plugins.oat-sa/oatbox-extension-installer true --no-interaction --no-plugins
- name: Set dev stability as a minimum
shell: bash
run: composer config minimum-stability dev
- name: Install the extension, its dev dependencies and phpunit if it's not required by the extension
shell: bash
run: composer require --prefer-stable -W --no-interaction "${{ steps.extension.outputs.name }}:dev-${{ steps.extension.outputs.ref }} as v99.99.99" "phpunit/phpunit:~9" "phpspec/prophecy:~1" "squizlabs/php_codesniffer:~3" ${{ steps.extension.outputs.dependencies }}
- name: Set phpunit coverage configuration
shell: bash
run: mv -n "${{ github.action_path }}/phpunit.xml" .
- name: Convert phpunit configuration
shell: bash
run: vendor/bin/phpunit --migrate-configuration || true
- name: Set phpunit bootstrap
shell: bash
run: mv -n "${{ github.action_path }}/bootstrap.php" .
- name: Execute Unit tests
shell: bash
run: vendor/bin/phpunit --bootstrap bootstrap.php${{ inputs.coverage && ' --coverage-clover coverage.xml' }} "src/${{ inputs.test-suites-path }}"
- uses: codecov/codecov-action@v3
if: ${{ inputs.coverage }}
- uses: Ana06/get-changed-files@v2.2.0
id: files
with:
format: 'csv'
- name: Execute script for filter
shell: bash
run: |
FILELIST=$(mktemp /tmp/psr12-check.XXXXXX)
mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}')
for FILE in "${added_modified_files[@]}"; do
EXT="${FILE##*.}"
echo "Changed file: " $FILE ", extension: " $EXT
if [[ "$EXT" == "php" && $FILE != migrations/Version* ]]; then
echo "src/${FILE}" >> "${FILELIST}"
echo "File added to the file list: " $FILE
fi
done
if [ -s "${FILELIST}" ]; then
vendor/bin/phpcs --standard=PSR12 --exclude=PSR1.Classes.ClassDeclaration -v --file-list="${FILELIST}"
RETVAL=$?
echo "The following files were tested for PSR-12 errors:"; echo
cat -n "$FILELIST"
else
echo "There are no changes in PHP files (no PSR-12 test performed)"
fi
rm "$FILELIST"
exit $RETVAL