|
| 1 | +name: "Continuous integration" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + plugin-key: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + glpi-version: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + php-version: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + db-image: |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + |
| 19 | +jobs: |
| 20 | + ci: |
| 21 | + name: "Continuous integration" |
| 22 | + runs-on: "ubuntu-latest" |
| 23 | + container: |
| 24 | + image: "ghcr.io/glpi-project/githubactions-glpi:php-${{ inputs.php-version }}-glpi-${{ inputs.glpi-version }}" |
| 25 | + options: >- |
| 26 | + --volume ${{ github.workspace }}:/var/glpi/plugins:rw |
| 27 | + services: |
| 28 | + db: |
| 29 | + image: "ghcr.io/glpi-project/githubactions-${{ inputs.db-image }}" |
| 30 | + env: |
| 31 | + MYSQL_ALLOW_EMPTY_PASSWORD: "yes" |
| 32 | + MYSQL_DATABASE: "glpi" |
| 33 | + options: >- |
| 34 | + --shm-size=1g |
| 35 | + defaults: |
| 36 | + run: |
| 37 | + shell: "bash" |
| 38 | + working-directory: "/var/glpi/plugins/${{ inputs.plugin-key }}" |
| 39 | + steps: |
| 40 | + - name: "Checkout" |
| 41 | + uses: "actions/checkout@v4" |
| 42 | + with: |
| 43 | + path: "${{ inputs.plugin-key }}" |
| 44 | + - name: "Get dependencies cache directories" |
| 45 | + id: "composer-cache" |
| 46 | + run: | |
| 47 | + echo "composer_cache_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 48 | + echo "npm_cache_dir=$(npm config get cache)" >> $GITHUB_OUTPUT |
| 49 | + - name: "Restore dependencies cache" |
| 50 | + uses: "actions/cache@v3" |
| 51 | + with: |
| 52 | + path: | |
| 53 | + ${{ steps.composer-cache.outputs.composer_cache_dir }} |
| 54 | + ${{ steps.composer-cache.outputs.npm_cache_dir }} |
| 55 | + key: "${{ inputs.plugin-key }}-dependencies-${{ inputs.php-version }}-${{ github.job }}-${{ hashFiles('**/composer.lock', '**/package-lock.json') }}" |
| 56 | + restore-keys: | |
| 57 | + ${{ inputs.plugin-key }}-dependencies-${{ inputs.php-version }}-${{ github.job }}- |
| 58 | + ${{ inputs.plugin-key }}-dependencies-${{ inputs.php-version }}- |
| 59 | + ${{ inputs.plugin-key }}-dependencies- |
| 60 | + - name: "Install dependencies" |
| 61 | + run: | |
| 62 | + if [[ -f "composer.json" ]]; then |
| 63 | + composer install --ansi --no-interaction --no-progress --prefer-dist |
| 64 | + fi |
| 65 | + if [[ -f "package.json" ]]; then |
| 66 | + npm install --no-save |
| 67 | + fi |
| 68 | + - name: "PHP Lint" |
| 69 | + run: | |
| 70 | + if [[ -f "vendor/bin/parallel-lint" ]]; then |
| 71 | + echo -e "\033[0;33mExecuting PHP Parallel Lint...\033[0m" |
| 72 | + vendor/bin/parallel-lint --colors --exclude ./vendor/ --no-progress . |
| 73 | + fi |
| 74 | + if [[ -f "vendor/bin/phpcs" && -f ".phpcs.xml" ]]; then |
| 75 | + echo -e "\033[0;33mExecuting PHP CodeSniffer...\033[0m" |
| 76 | + vendor/bin/phpcs |
| 77 | + fi |
| 78 | + if [[ -f "vendor/bin/phpstan" && -f "phpstan.neon" ]]; then |
| 79 | + echo -e "\033[0;33mExecuting PHPStan...\033[0m" |
| 80 | + vendor/bin/phpstan analyze --ansi --memory-limit=2G --no-interaction --no-progress |
| 81 | + fi |
| 82 | + - name: "JS Lint" |
| 83 | + run: | |
| 84 | + if [[ -f "node_modules/.bin/eslint" && -f ".eslintrc.js" ]]; then |
| 85 | + echo -e "\033[0;33mExecuting ESLint...\033[0m" |
| 86 | + node_modules/.bin/eslint --color . |
| 87 | + fi |
| 88 | + - name: "CSS Lint" |
| 89 | + run: | |
| 90 | + if [[ -f "node_modules/.bin/stylelint" && -f ".stylelintrc.js" ]]; then |
| 91 | + echo -e "\033[0;33mExecuting Stylelint...\033[0m" |
| 92 | + node_modules/.bin/stylelint --color "**/*.css" "**/*.scss" |
| 93 | + fi |
| 94 | + - name: "Misc lint" |
| 95 | + run: | |
| 96 | + if [[ -f "vendor/bin/licence-headers-check" && -f "tools/HEADER" ]]; then |
| 97 | + echo -e "\033[0;33mExecuting licence headers checks...\033[0m" |
| 98 | + vendor/bin/licence-headers-check --ansi --no-interaction |
| 99 | + fi |
| 100 | + - name: "Install plugin" |
| 101 | + working-directory: "/var/glpi" |
| 102 | + run: | |
| 103 | + bin/console database:install --ansi --no-interaction --db-name=glpi --db-host=db --db-user=root --strict-configuration |
| 104 | + bin/console plugin:install --ansi --no-interaction --username=glpi ${{ inputs.plugin-key }} |
| 105 | + bin/console plugin:activate --ansi --no-interaction ${{ inputs.plugin-key }} |
| 106 | + - name: "PHPUnit" |
| 107 | + run: | |
| 108 | + if [[ -f "vendor/bin/phpunit" && -f "phpunit.xml" ]]; then |
| 109 | + echo -e "\033[0;33mExecuting PHPUnit...\033[0m" |
| 110 | + php vendor/bin/phpunit --colors=always |
| 111 | + fi |
0 commit comments