/
action.yml
173 lines (173 loc) · 7.94 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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
node-version:
description: Node version to run the client-side tests with
required: false
default: '18'
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 id=$(composer config extra.tao-extension-name --no-interaction --no-plugins) >> $GITHUB_OUTPUT
echo name=$(composer config name --no-interaction --no-plugins) >> $GITHUB_OUTPUT
echo ref="$([ -z "$(git branch --show-current)" ] && git rev-parse --verify HEAD || git branch --show-current)" >> $GITHUB_OUTPUT
echo dependencies=$(composer show --self --direct | grep -E "\sdev-[^\s]+\sas\s" | sed "s/ /:/" | awk '{ print "\""$0"\""}') >> $GITHUB_OUTPUT
echo dev-dependencies=$(composer show --self --direct | awk "/requires \(dev\)/" RS= | tail -n +2 | sed "s/ /:/" | awk '{ print "\""$0"\""}') >> $GITHUB_OUTPUT
echo node-version=$([[ "${{ inputs.coverage }}" && "${{ inputs.node-version }}" && -f views/build/grunt/test.js ]] && echo "${{ inputs.node-version }}") >> $GITHUB_OUTPUT
- name: Use Node.js ${{ steps.extension.outputs.node-version }}
if: ${{ steps.extension.outputs.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ steps.extension.outputs.node-version }}
- 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: Configure NPM plugin
shell: bash
run: composer config allow-plugins.oat-sa/composer-npm-bridge ${{ steps.extension.outputs.node-version && 'true' || '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 }} ${{ steps.extension.outputs.dev-dependencies }}
- name: Generate localization files
if: ${{ steps.extension.outputs.node-version }}
shell: bash
run: php tao/scripts/tools/GenerateTranslationBundles.php
- name: Front-end tests
if: ${{ steps.extension.outputs.node-version }}
shell: bash
working-directory: tao/views/build
run: |
npm ci
npx grunt connect:test qunit_junit $(echo ${{ steps.extension.outputs.id }} | awk '{print tolower($0)}')test --force --reports=../../../junit-reports
- name: Publish the front-end test report
if: ${{ steps.extension.outputs.node-version }}
uses: mikepenz/action-junit-report@v3
id: fe-junit
with:
job_summary: false
- name: Front-end job summary
if: ${{ steps.extension.outputs.node-version }}
uses: mathiasvr/command-output@v2.0.0
id: fe-summary
with:
run: |
cat << EOF
# Front-end summary Node ${{ steps.extension.outputs.node-version }}
|💯 Total|✅ Passed|⏭️ Skipped|❌ Failed|
|-|-|-|-|
|${{ steps.fe-junit.outputs.total }}|${{ steps.fe-junit.outputs.passed }}|${{ steps.fe-junit.outputs.skipped }}|${{ steps.fe-junit.outputs.failed }}|
EOF
- uses: peter-evans/find-comment@v2
id: fe-summary-comment
if: ${{ github.event_name == 'pull_request' && steps.extension.outputs.node-version }}
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Front-end summary Node ${{ steps.extension.outputs.node-version }}
- name: Create or update front-end summary comment
uses: peter-evans/create-or-update-comment@v2
if: ${{ github.event_name == 'pull_request' && steps.extension.outputs.node-version }}
with:
comment-id: ${{ steps.fe-summary-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.fe-summary.outputs.stdout }}
edit-mode: replace
- name: Front-end job summary
if: ${{ steps.extension.outputs.node-version }}
shell: bash
run: echo "${{ steps.fe-summary.outputs.stdout }}" >> $GITHUB_STEP_SUMMARY
- 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" .
- id: check_back_end_test
uses: andstor/file-existence-action@v3
with:
files: src/${{ inputs.test-suites-path }}
- name: Back-end tests
id: backend_test
if: steps.check_back_end_test.outputs.files_exists == 'true'
shell: bash
run: |
vendor/bin/phpunit --bootstrap bootstrap.php${{ inputs.coverage && ' --coverage-clover coverage.xml' }} "src/${{ inputs.test-suites-path }}"
echo "completed='true'" >> $GITHUB_OUTPUT
- uses: codecov/codecov-action@v3
if: ${{ inputs.coverage && steps.files.backend_test.completed }}
- uses: Ana06/get-changed-files@v2.2.0
id: files
if: github.event_name == 'pull_request'
with:
format: 'csv'
- name: Execute script for filter
if: github.event_name == 'pull_request'
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,Squiz.Classes.ValidClassName -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
- name: Fail the job if front-end tests weren't OK
if: ${{ steps.extension.outputs.node-version }}
shell: bash
run: exit ${{ steps.fe-junit.outputs.failed }}