forked from OpenCatalogi/opencatalogi
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (102 loc) · 4.38 KB
/
CI-workflows.yaml
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
name: CI Workflow
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, zip, xml, curl, intl, sqlite, gd, pdo_mysql
tools: cs2pr, phpcbf, phpcs, phpmd, phpunit
- name: Install Composer dependencies
run: composer install
- name: Run phpcbf
run: phpcbf .
continue-on-error: ${{ github.ref != 'refs/heads/main' }}
#- name: Commit code formatting changes
# if: success() && github.ref != 'refs/heads/main'
# run: |
# git config user.name "GitHub Actions"
# git config user.email "[email protected]"
# git add src
# git diff --cached --quiet || (git commit -m "Update src from PHP Codesniffer" && git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash && git push)
- name: Run phpcs
run: phpcs -q --report=checkstyle src | cs2pr
continue-on-error: ${{ github.ref != 'refs/heads/main' }}
- name: Run phpmd
run: phpmd src xml phpmd.xml --not-strict
continue-on-error: ${{ github.ref != 'refs/heads/main' }}
- name: List files in repository root
run: ls -alh
- name: List files in tests directory
run: ls -alh ./tests
- name: List files in vendor directory
run: ls -alh ./vendor
- name: Run PHPUnit tests
env:
XDEBUG_MODE: coverage
run: |
phpunit --bootstrap ./tests/bootstrap.php --configuration phpunit.xml --coverage-html ./coverage --coverage-text | tee coverage.txt
continue-on-error: ${{ github.ref != 'refs/heads/main' }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install remark presets
run: npm install remark-cli remark-preset-lint-consistent remark-preset-lint-recommended remark-lint-list-item-indent
- name: Run remark
run: npx remark . --output --use remark-preset-lint-consistent --use remark-preset-lint-recommended --use remark-lint-list-item-indent
- name: Check for linting errors
run: |
npx remark . --use remark-preset-lint-consistent --use remark-preset-lint-recommended --use remark-lint-list-item-indent
continue-on-error: ${{ github.ref != 'refs/heads/main' }}
- name: Git commit
if: success() && github.ref != 'refs/heads/main'
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add .
git add package.json package-lock.json
git diff --cached --quiet || (git commit -m "Update src from remark-lint" && git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash && git push)
checks:
needs: [build, lint]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP (for checks)
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, zip, xml, curl, intl, sqlite, gd, pdo_mysql
tools: cs2pr, phpcs, phpmd, phpunit
- name: Run Checks
run: |
if ! command -v phpcs &> /dev/null; then
echo "phpcs could not be found. Please ensure it's installed."
exit 1
fi
if ! command -v phpmd &> /dev/null; then
echo "phpmd could not be found. Please ensure it's installed."
exit 1
fi
if phpcs -q --report=checkstyle src | grep -q "ERROR"; then
echo "PHP CodeSniffer found issues. Please fix them before merging."
exit 1
fi
if phpmd src xml phpmd.xml --strict | grep -q "ERROR"; then
echo "PHP Mess Detector found issues. Please fix them before merging."
exit 1
fi
# if ! phpunit --bootstrap ./tests/bootstrap.php --configuration phpunit.xml; then
# echo "PHPUnit tests failed. Please fix them before merging."
# exit 1
#fi
if ! npx remark . --use remark-preset-lint-consistent --use remark-preset-lint-recommended --use remark-lint-list-item-indent; then
echo "Markdown linting failed. Please fix them before merging."
exit 1
fi
continue-on-error: false