Skip to content

Commit

Permalink
GitHub Actions CI optimisation (#3929)
Browse files Browse the repository at this point in the history
Efforts to reduce the resources used by CI:
* Only one git checkout
* Exclusion of irrelevant directories for several commands
* Fix some rtlcss warnings
* Move some commands from tests.yml to composer.json to make them reusasble
* Initial efforts to take avantage of all that from `make` (help welcome)
  • Loading branch information
Alkarex committed Oct 24, 2021
1 parent 07e00c7 commit 9416f45
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 22 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,3 +1,4 @@
*.min.js
node_modules/
p/scripts/vendor/
vendor/
34 changes: 17 additions & 17 deletions .github/workflows/tests.yml
Expand Up @@ -8,21 +8,24 @@ on:

jobs:

composer:
tests:
# https://github.com/actions/virtual-environments
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Git checkout source code
uses: actions/checkout@v2

# Composer tests

- name: Check PHP syntax
run: find . -name '*.php' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null
run: composer run-script php-lint

- name: Check PHTML syntax
run: find . -name '*.phtml' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null
run: composer run-script phtml-lint

- name: Check translations syntax
run: cli/manipulate.translation.php -a format && git diff --exit-code
run: composer run-script translations && git diff --exit-code

- name: Use Composer cache
id: composer-cache
Expand All @@ -33,17 +36,17 @@ jobs:
restore-keys: |
${{ runner.os }}-php-
- run: composer install --prefer-dist --no-progress
- name: Run Composer install
run: composer install --prefer-dist --no-progress
if: steps.composer-cache.outputs.cache-hit != 'true'

- name: Run PHP tests
run: composer run-script test
- name: Run PHP unit tests
run: composer run-script phpunit

- name: PHP_CodeSniffer
run: composer run-script phpcs

npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# NPM tests

- name: Uses Node.js
uses: actions/setup-node@v2
Expand All @@ -66,11 +69,7 @@ jobs:
- name: Check CSS syntax
run: npm run stylelint


shell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Shell tests

- name: Use shell cache
id: shell-cache
Expand All @@ -83,6 +82,7 @@ jobs:
run: mkdir -p bin/ && echo "${PWD}/bin" >> $GITHUB_PATH

- name: Setup Go
if: steps.shell-cache.outputs.cache-hit != 'true'
# Multiple Go versions are pre-installed but the default 1.15 is too old
# https://github.com/actions/setup-go
uses: actions/setup-go@v2
Expand Down
3 changes: 2 additions & 1 deletion .jshintignore
@@ -1,3 +1,4 @@
node_modules
node_modules/
p/scripts/bcrypt.min.js
p/scripts/vendor/
vendor/
2 changes: 2 additions & 0 deletions .markdownlintignore
@@ -1 +1,3 @@
node_modules/
p/scripts/vendor/
vendor/
3 changes: 3 additions & 0 deletions .stylelintignore
@@ -1,3 +1,6 @@
node_modules/
p/scripts/vendor/
vendor/
# ignore SASS-generated CSS
p/themes/Ansum/*.css
p/themes/Mapco/*.css
Expand Down
33 changes: 32 additions & 1 deletion Makefile
Expand Up @@ -159,7 +159,7 @@ endif
###########
.PHONY: rtl
rtl: ## Generate RTL CSS files
rtlcss -d p/themes && find . -type f -name '*.rtl.rtl.css' -delete
rtlcss -d p/themes/ && find p/themes/ -type f -name '*.rtl.rtl.css' -delete

.PHONY: pot
pot: ## Generate POT templates for docs
Expand All @@ -169,6 +169,37 @@ pot: ## Generate POT templates for docs
refresh: ## Refresh feeds by fetching new messages
@$(PHP) ./app/actualize_script.php

###############################
## New commands aligned on CI #
## Work in progress #
###############################

# TODO: Add composer install
.PHONY: composer-test
composer-test:
composer run-script test

.PHONY: composer-fix
composer-fix:
composer run-script fix

# TODO: Add npm install
.PHONY: npm-test
npm-test:
npm test

.PHONY: npm-fix
npm-fix:
npm run fix

# TODO: Add shellcheck, shfmt, hadolint
.PHONY: test-all
test-all: composer-test npm-test

.PHONY: fix-all
fix-all: composer-fix npm-fix


##########
## HELP ##
##########
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Expand Up @@ -24,14 +24,20 @@
"squizlabs/php_codesniffer": "^3.6"
},
"scripts": {
"phpcs": "phpcs . -p -s",
"php-lint": "find . -type d -name 'vendor' -prune -o -name '*.php' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null",
"phtml-lint": "find . -type d -name 'vendor' -prune -o -name '*.phtml' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null",
"phpcs": "phpcs . -s",
"phpcbf": "phpcbf . -p -s",
"phpunit": "phpunit --bootstrap ./tests/bootstrap.php --verbose ./tests",
"translations": "cli/manipulate.translation.php -a format",
"test": [
"@php-lint",
"@phtml-lint",
"@phpunit",
"@phpcs"
],
"fix": [
"@translations",
"@phpcbf"
]
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -23,7 +23,7 @@
"eslint_fix": "eslint --fix --ext .js .",
"markdownlint": "markdownlint '**/*.md'",
"markdownlint_fix": "markdownlint --fix '**/*.md'",
"rtlcss": "rtlcss -d p/themes && find . -type f -name '*.rtl.rtl.css' -delete",
"rtlcss": "rtlcss -d p/themes/ && find p/themes/ -type f -name '*.rtl.rtl.css' -delete",
"stylelint": "stylelint '**/*.css' && stylelint --syntax scss '**/*.scss'",
"stylelint_fix": "stylelint --fix '**/*.css' && stylelint --fix --syntax scss '**/*.scss'",
"test": "npm run eslint && npm run stylelint && npm run markdownlint",
Expand All @@ -41,5 +41,6 @@
"stylelint-config-recommended-scss": "^4.3.0",
"stylelint-order": "^4.1.0",
"stylelint-scss": "^3.21.0"
}
},
"rtlcssConfig": {}
}

0 comments on commit 9416f45

Please sign in to comment.