Skip to content

Commit 5a4cc84

Browse files
author
Orzo Cogorzo
authored
Merge pull request #1 from codeccoop/feat/php-setup
php unit testing wordpress coding standards project directory refactor http bridge refactor
2 parents 7e60053 + cdd40ad commit 5a4cc84

File tree

520 files changed

+59614
-43771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

520 files changed

+59614
-43771
lines changed

.github/workflows/release.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
8+
permissions:
9+
contents: "write"
10+
11+
jobs:
12+
tests:
13+
name: Release tests
14+
uses: ./.github/workflows/tests.yml
15+
16+
build:
17+
name: Build client
18+
runs-on: ubuntu-latest
19+
needs: tests
20+
steps:
21+
- name: Setup node
22+
uses: actions/setup-node@v6
23+
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
submodules: true
28+
29+
- name: Cache node modules
30+
uses: actions/cache@v4
31+
with:
32+
path: node_modules
33+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
34+
restore-keys: |
35+
${{ runner.os }}-build-${{ env.cache-name }}-
36+
${{ runner.os }}-build-
37+
${{ runner.os }}-
38+
39+
- name: Install dependencies
40+
run: npm ci
41+
42+
- name: Replace textdomains
43+
run: find src -exec sed -i "s/http-bridge/forms-bridge/g" {} \;
44+
45+
- name: Build
46+
run: npm run build
47+
48+
- name: Upload artifact
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: build
52+
path: forms-bridge/assets/plugin.bundle.js
53+
54+
package:
55+
name: Prepare package
56+
runs-on: ubuntu-latest
57+
container:
58+
image: codeccoop/wp-cli
59+
env:
60+
ZIP: "${{ github.ref_name }}.zip"
61+
needs: build
62+
steps:
63+
- name: Setup node
64+
uses: actions/setup-node@v6
65+
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
with:
69+
submodules: true
70+
71+
- name: Download build artifact
72+
uses: actions/download-artifact@v4
73+
with:
74+
name: build
75+
path: forms-bridge/assets
76+
77+
- name: Install dist archive
78+
run: wp package install wp-cli/dist-archive-command:@stable
79+
80+
- name: Replace textdomains
81+
run: |
82+
find forms-bridge/deps/plugin -name '*.php' -exec sed -i "s/wpct-plugin/forms-bridge/g" {} \;
83+
find forms-bridge -name '*.php' -exec sed -i "s/wpct_plugin_/forms_bridge_plugin_/g" {} \;
84+
find forms-bridge -name "*.php" -exec sed -i 's/WPCT_PLUGIN/FORMS_BRIDGE\\Plugin/g' {} \;
85+
find forms-bridge/deps/http -name '*.php' -exec sed -i "s/http-bridge/forms-bridge/g" {} \;
86+
find forms-bridge -name '*.php' -exec sed -i "s/http_bridge_/forms_bridge_http_/g" {} \;
87+
find forms-bridge -name "*.php" -exec sed -i 's/HTTP_BRIDGE_/FORMS_BRIDGE_HTTP_/g' {} \;
88+
find forms-bridge -name '*.php' -exec sed -i 's/HTTP_BRIDGE/FORMS_BRIDGE\\Http/g' {} \;
89+
90+
- name: Archive
91+
run: wp dist-archive forms-bridge ./"$ZIP"
92+
93+
- name: Upload artifact
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: plugin-archive
97+
path: ${{ env.ZIP }}
98+
99+
release:
100+
name: Release pushed tag
101+
runs-on: ubuntu-latest
102+
needs: package
103+
env:
104+
ZIP: "${{ github.ref_name }}.zip"
105+
steps:
106+
- name: Download build artifact
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: plugin-archive
110+
111+
- name: Create release
112+
env:
113+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
TAG: ${{ github.ref_name }}
115+
run: |
116+
mv $ZIP forms-bridge.zip
117+
gh release create "$TAG" \
118+
--repo="$GITHUB_REPOSITORY" \
119+
--title="$TAG" \
120+
--generate-notes \
121+
"forms-bridge.zip"

.github/workflows/tests.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
workflow_call:
8+
9+
jobs:
10+
lint:
11+
name: WordPress Coding Standards
12+
runs-on: ubuntu-latest
13+
container:
14+
image: codeccoop/wp-test
15+
steps:
16+
- uses: actions/checkout@v5
17+
18+
- name: Composer install
19+
run: composer -q install
20+
21+
- name: Lint and format
22+
run: vendor/bin/phpcbf
23+
24+
phpunit:
25+
name: PHP Unit Testing
26+
runs-on: ubuntu-latest
27+
container:
28+
image: codeccoop/wp-test
29+
steps:
30+
- name: Start MariaDB
31+
run: nohup docker-entrypoint.sh mariadbd 2>&1 >/dev/null &
32+
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
with:
36+
submodules: true
37+
38+
- name: Cache composer
39+
uses: actions/cache@v4
40+
with:
41+
path: vendor
42+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('composer.lock') }}
43+
44+
- name: Cache plugins
45+
uses: actions/cache@v4
46+
with:
47+
path: /tmp/*.zip
48+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('bin/download-test-deps.sh') }}
49+
50+
- name: Composer install
51+
run: composer -q install
52+
53+
- name: Wait for MariaDB
54+
run: sleep 10
55+
56+
- name: Executable mode
57+
run: chmod a+x bin/*
58+
59+
- name: Install tests suite
60+
run: bin/install-wp-tests.sh
61+
62+
- name: Download deps
63+
run: bin/download-test-deps.sh
64+
65+
- name: Unit testing
66+
run: vendor/bin/phpunit -c phpunit.xml.dist

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.DS_Store
22
phpcs.xml
33
phpunit.xml
4+
.phpunit.result.cache
5+
.php-cs-fixer.cache
46
Thumbs.db
57
wp-cli.local.yml
68
node_modules/

.gitlab-ci.yml

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
workflow:
2-
rules:
3-
- if: $CI_COMMIT_BRANCH
4-
changes:
5-
- README.md
6-
- .gitlab-ci.yml
7-
when:
8-
never
9-
# Do no allow manually triggered pipelines to prevent duplicates!
10-
# Instead rerun the pipeline created with the last push
11-
- if: $CI_PIPELINE_SOURCE != "push"
12-
when: never
13-
# Only execute when a valid version tag like 1.0, 2.3-dev or similar is given
14-
# Required is always one point like 1.0
15-
- if: $CI_COMMIT_TAG =~ /^[0-9]+[.][0-9]+([.][0-9]+)?([-a-z])*$/
16-
17-
stages: # List of stages for jobs, and their order of execution
1+
# List of stages for jobs, and their order of execution
2+
stages:
3+
- test
184
- build
195
- package
206
- upload
@@ -32,49 +18,113 @@ variables:
3218
GIT_SUBMODULE_STRATEGY: normal
3319
GIT_SUBMODULE_FORCE_HTTPS: "true"
3420

21+
.release_job:
22+
rules:
23+
# Only execute when a valid version tag like 1.0, 2.3-dev or similar is given
24+
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^[0-9]+[.][0-9]+([.][0-9]+)?([-a-z])*$/
25+
26+
.test_job:
27+
stage: test
28+
image: codeccoop/wp-test
29+
cache:
30+
- key:
31+
files:
32+
- bin/download-test-deps.sh
33+
paths:
34+
- /tmp/*.zip
35+
36+
- key:
37+
files:
38+
- composer.lock
39+
paths:
40+
- vendor
41+
rules:
42+
# Only execute when a valid version tag like 1.0, 2.3-dev or similar is given
43+
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^[0-9]+[.][0-9]+([.][0-9]+)?([-a-z])*$/
44+
# Run always on MR pointing to master
45+
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
46+
47+
lint:
48+
extends: .test_job
49+
before_script:
50+
- composer -q install
51+
script:
52+
- vendor/bin/phpcbf
53+
54+
phpunit:
55+
extends: .test_job
56+
before_script:
57+
- nohup docker-entrypoint.sh mariadbd 2>&1 >/dev/null &
58+
- composer -q install
59+
- sleep 10
60+
- chmod a+x bin/*
61+
- bin/install-wp-tests.sh
62+
- bin/download-test-deps.sh
63+
script:
64+
- vendor/bin/phpunit -c phpunit.xml.dist
65+
3566
build:
67+
extends: .release_job
3668
stage: build
3769
image: node:latest
70+
cache:
71+
- key:
72+
files:
73+
- package-lock.json
74+
paths:
75+
- node_modules
3876
script:
3977
- find src -exec sed -i "s/http-bridge/forms-bridge/g" {} \;
4078
- npm install && npm run build
41-
- rm -rf node_modules
4279
artifacts:
4380
paths:
44-
- assets/plugin.bundle.js
81+
- forms-bridge/assets/plugin.bundle.js
4582

4683
package:
84+
extends: .release_job
4785
image: codeccoop/wp-cli:latest
4886
stage: package
87+
dependencies: [build]
4988
script:
50-
- find common -name '*.php' -exec sed -i "s/wpct-plugin/forms-bridge/g" {} \;
51-
- find . -name '*.php' -exec sed -i "s/wpct_plugin_/forms_bridge_plugin_/g" {} \;
52-
- find . -name "*.php" -exec sed -i 's/WPCT_PLUGIN/FORMS_BRIDGE\\Common/g' {} \;
53-
- find deps/http -name '*.php' -exec sed -i "s/http-bridge/forms-bridge/g" {} \;
54-
- find . -name '*.php' -exec sed -i "s/http_bridge_/forms_bridge_http_/g" {} \;
55-
- find . -name "*.php" -exec sed -i 's/HTTP_BRIDGE_/FORMS_BRIDGE_HTTP_/g' {} \;
56-
- find . -name '*.php' -exec sed -i 's/HTTP_BRIDGE/FORMS_BRIDGE\\Http/g' {} \;
57-
- find deps/i18n -name '*.php' -exec sed -i "s/wpct-i18n/forms-bridge/g" {} \;
58-
- find . -name '*.php' -exec sed -i "s/wpct_i18n_/forms_bridge_i18n_/g" {} \;
59-
- find . -name '*.php' -exec sed -i 's/WPCT_I18N/FORMS_BRIDGE\\I18n/g' {} \;
60-
- wp dist-archive . ./$ZIP
89+
- find forms-bridge/deps/plugin -name '*.php' -exec sed -i "s/wpct-plugin/forms-bridge/g" {} \;
90+
- find forms-bridge -name '*.php' -exec sed -i "s/wpct_plugin_/forms_bridge_plugin_/g" {} \;
91+
- find forms-bridge -name "*.php" -exec sed -i 's/WPCT_PLUGIN/FORMS_BRIDGE\\Plugin/g' {} \;
92+
- find forms-bridge/deps/http -name '*.php' -exec sed -i "s/http-bridge/forms-bridge/g" {} \;
93+
- find forms-bridge -name '*.php' -exec sed -i "s/http_bridge_/forms_bridge_http_/g" {} \;
94+
- find forms-bridge -name "*.php" -exec sed -i 's/HTTP_BRIDGE_/FORMS_BRIDGE_HTTP_/g' {} \;
95+
- find forms-bridge -name '*.php' -exec sed -i 's/HTTP_BRIDGE/FORMS_BRIDGE\\Http/g' {} \;
96+
- wp dist-archive forms-bridge ./$ZIP
6197
artifacts:
6298
paths:
6399
- $ZIP
64100

65101
upload:
102+
extends: .release_job
66103
stage: upload
67104
image: curlimages/curl:latest
105+
dependencies: [package]
68106
script:
69107
- |
70-
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${ZIP} ${PACKAGE_REGISTRY_URL}/${ZIP}
108+
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
109+
--upload-file ${ZIP} \
110+
${PACKAGE_REGISTRY_URL}/${ZIP}
71111
72112
release:
73113
# Caution, as of 2021-02-02 these assets links require a login, see:
74114
# https://gitlab.com/gitlab-org/gitlab/-/issues/299384
115+
extends: .release_job
75116
stage: release
76-
image: registry.gitlab.com/gitlab-org/release-cli:latest
117+
image: gitlab/glab:latest
118+
dependencies: [package]
119+
variables:
120+
GITLAB_HOST: "$CI_SERVER_URL"
77121
script:
78122
- |
79-
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
80-
--assets-link "{\"name\":\"${ZIP}\",\"url\":\"${PACKAGE_REGISTRY_URL}\/${ZIP}\",\"link_type\":\"package\",\"filepath\":\"\/plugins\/bridges\/${ZIP}\"}"
123+
glab auth login \
124+
--job-token $CI_JOB_TOKEN \
125+
--hostname $CI_SERVER_HOST \
126+
--api-protocol $CI_SERVER_PROTOCOL
127+
- |
128+
glab release create $CI_COMMIT_TAG\
129+
--name "Release $CI_COMMIT_TAG" \
130+
--assets-links "[{\"name\":\"${ZIP}\",\"url\":\"${PACKAGE_REGISTRY_URL}\/${ZIP}\",\"link_type\":\"package\",\"direct_asset_path\":\"\/plugins\/bridges\/${ZIP}\"}]"

.gitmodules

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
[submodule "common"]
2-
path = common
3-
url = https://git.coopdevs.org/codeccoop/wp/plugins/wpct-plugin-common.git
4-
[submodule "deps/http"]
5-
path = deps/http
6-
url = https://git.coopdevs.org/codeccoop/wp/plugins/bridges/http-bridge.git
7-
[submodule "deps/i18n"]
8-
path = deps/i18n
9-
url = https://git.coopdevs.org/codeccoop/wp/plugins/wpct-i18n.git
1+
[submodule "forms-bridge/plugin"]
2+
path = forms-bridge/deps/plugin
3+
url = https://gitlab.com/codeccoop/wp/plugins/wpct-plugin.git
4+
[submodule "forms-bridge/deps/http"]
5+
path = forms-bridge/deps/http
6+
url = https://gitlab.com/codeccoop/wp/plugins/http-bridge.git

.lintstagedrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const buildPrettierCommand = (filenames) =>
88
.map((f) => path.relative(process.cwd(), f))
99
.join(" ")}`;
1010

11-
const buildPrettierPhpCommand = (filenames) =>
12-
`prettier --write --ignore-unknown --config .prettierrc-php ${filenames
11+
const buildPhpCbfCommand = (filenames) =>
12+
`vendor/bin/phpcbf -n ${filenames
1313
.map((f) => path.relative(process.cwd(), f))
1414
.join(" ")}`;
1515

1616
module.exports = {
17-
// "src/**/*.{js,jsx,ts,tsx}": [buildEslintCommand],
18-
"*.{json,js,ts,jsx,tsx,html,css}": [buildPrettierCommand],
19-
"*.php": [buildPrettierPhpCommand],
17+
"src/**/*.{js,jsx}": [buildEslintCommand],
18+
"*.{json,js,jsx,html,css}": [buildPrettierCommand],
19+
"*.php": [buildPhpCbfCommand],
2020
};

0 commit comments

Comments
 (0)