mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
Change test strategy for commit tests
This commit is contained in:
parent
0e88cdb258
commit
3a64feefd0
12
.github/pull_request_template.md
vendored
12
.github/pull_request_template.md
vendored
@ -7,7 +7,11 @@
|
||||
> If your PR involves the changes mentioned below and completed the action, please tick the corresponding option.
|
||||
> If a modification is not involved, please skip it directly.
|
||||
|
||||
- [ ] If you modified `*.php`, run `composer cs-fix` at local machine.
|
||||
- [ ] If it's an extension or dependency update, make sure adding related extensions in `src/global/test-extensions.php`.
|
||||
- [ ] If you changed the behavior of static-php-cli, update docs in `./docs/`.
|
||||
- [ ] If you updated `config/xxx.json` content, run `bin/spc dev:sort-config xxx`.
|
||||
- If you modified `*.php` or `*.json`, run them locally to ensure your changes are valid:
|
||||
- [ ] `PHP_CS_FIXER_IGNORE_ENV=1 composer cs-fix`
|
||||
- [ ] `composer analyse`
|
||||
- [ ] `composer test`
|
||||
- [ ] `bin/spc dev:sort-config`
|
||||
- If it's an extension or dependency update, please ensure the following:
|
||||
- [ ] Add your test combination to `src/globals/test-extensions.php`.
|
||||
- [ ] If adding new or fixing bugs, add commit message containing `fix` or `test` to trigger full test suite.
|
||||
|
||||
137
.github/workflows/commit-tests.yml
vendored
137
.github/workflows/commit-tests.yml
vendored
@ -1,137 +0,0 @@
|
||||
name: Single Test
|
||||
on:
|
||||
push:
|
||||
|
||||
permissions: read-all
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobs:
|
||||
parse-commit:
|
||||
runs-on: ubuntu-latest
|
||||
# if the commit message does not contain {craft} or {bash} tags, then skip the craft-test and bash-test jobs
|
||||
if: github.event_name == 'push' && (contains(github.event.head_commit.message, '{craft}') || contains(github.event.head_commit.message, '{bash}'))
|
||||
outputs:
|
||||
skip_craft: ${{ steps.parse_commit.outputs.skip_craft }}
|
||||
craft: ${{ steps.parse_commit.outputs.craft }}
|
||||
skip_bash: ${{ steps.parse_commit.outputs.skip_bash }}
|
||||
bash: ${{ steps.parse_commit.outputs.bash }}
|
||||
build_os: ${{ steps.parse_commit.outputs.build_os }}
|
||||
spc_prefix: ${{ steps.parse_commit.outputs.spc_prefix }}
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Parse commit message"
|
||||
id: parse_commit
|
||||
run: |
|
||||
# parse the commit message, see if it has {craft} and {/craft} tags
|
||||
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
|
||||
# judge it, it it's not exist, then skip this test
|
||||
if [[ "$COMMIT_MESSAGE" != *"{craft}"* ]] || [[ "$COMMIT_MESSAGE" != *"{/craft}"* ]]; then
|
||||
echo "No {craft} tags found in commit message. Skipping test."
|
||||
echo "skip_craft=yes" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
else
|
||||
echo -e "\e[32mCraft tags found in commit message.\e[0m"
|
||||
# get the craft content
|
||||
CRAFT_CONTENT=$(echo "$COMMIT_MESSAGE" | sed -nz 's/.*{craft}\(.*\){\/craft}.*/\1/p')
|
||||
echo "Craft content: $CRAFT_CONTENT"
|
||||
# set the output variable
|
||||
echo "craft<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$CRAFT_CONTENT" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# parse the bash test script from the commit message
|
||||
if [[ "$COMMIT_MESSAGE" != *"{bash}"* ]] || [[ "$COMMIT_MESSAGE" != *"{/bash}"* ]]; then
|
||||
echo "No {bash} tags found in commit message. Skipping bash test."
|
||||
echo "skip_bash=yes" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo -e "\e[32mBash tags found in commit message.\e[0m"
|
||||
# get the bash content
|
||||
BASH_CONTENT=$(echo "$COMMIT_MESSAGE" | sed -nz 's/.*{bash}\(.*\){\/bash}.*/\1/p')
|
||||
echo "Bash content: $BASH_CONTENT"
|
||||
# set the output variable
|
||||
echo "bash<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$BASH_CONTENT" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# parse spc_prefix from commit message, e.g. [spc_prefix:bin/spc-gnu-docker], default: bin/spc
|
||||
if [[ "$COMMIT_MESSAGE" =~ \[spc_prefix:([^\]]+)\] ]]; then
|
||||
SPC_PREFIX=${BASH_REMATCH[1]}
|
||||
echo "SPC prefix found: $SPC_PREFIX"
|
||||
else
|
||||
SPC_PREFIX="bin/spc"
|
||||
echo "No SPC prefix found, using default: $SPC_PREFIX"
|
||||
fi
|
||||
echo "spc_prefix=$SPC_PREFIX" >> $GITHUB_OUTPUT
|
||||
|
||||
# parse build_os from commit message, e.g. [build_os:ubuntu-latest], default: ubuntu-latest
|
||||
if [[ "$COMMIT_MESSAGE" =~ \[build_os:([^\]]+)\] ]]; then
|
||||
BUILD_OS=${BASH_REMATCH[1]}
|
||||
echo "Build OS found: $BUILD_OS"
|
||||
else
|
||||
BUILD_OS="ubuntu-latest"
|
||||
echo "No Build OS found, using default: $BUILD_OS"
|
||||
fi
|
||||
echo "build_os=$BUILD_OS" >> $GITHUB_OUTPUT
|
||||
|
||||
craft-test:
|
||||
needs: parse-commit
|
||||
if: needs.parse-commit.outputs.skip_craft != 'yes'
|
||||
runs-on: ${{ needs.parse-commit.outputs.build_os }}
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
tools: composer
|
||||
|
||||
- name: "Install Dependencies"
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
|
||||
- name: "Doctor"
|
||||
run: ${{ needs.parse-commit.outputs.spc_prefix }} doctor --auto-fix --debug
|
||||
|
||||
- name: "Run Craft Test"
|
||||
run: |
|
||||
echo "Running craft test with content:"
|
||||
echo "${{ needs.parse-commit.outputs.craft }}"
|
||||
echo "${{ needs.parse-commit.outputs.craft }}" > craft.yml
|
||||
${{ needs.parse-commit.outputs.spc_prefix }} craft --debug
|
||||
|
||||
bash-test:
|
||||
needs: parse-commit
|
||||
if: needs.parse-commit.outputs.skip_bash != 'yes'
|
||||
runs-on: ${{ needs.parse-commit.outputs.build_os }}
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
tools: composer
|
||||
|
||||
- name: "Install Dependencies"
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
|
||||
- name: "Doctor"
|
||||
run: ${{ needs.parse-commit.outputs.spc_prefix }} doctor --auto-fix --debug
|
||||
|
||||
- name: "Run Bash Test"
|
||||
run: |
|
||||
echo "Running bash test with content:"
|
||||
echo "${{ needs.parse-commit.outputs.bash }}"
|
||||
echo "${{ needs.parse-commit.outputs.bash }}" | bash
|
||||
21
.github/workflows/ext-matrix-tests.yml
vendored
21
.github/workflows/ext-matrix-tests.yml
vendored
@ -1,16 +1,27 @@
|
||||
name: "Extension matrix tests"
|
||||
|
||||
|
||||
# Only run if:
|
||||
# - the workflow is manually triggered
|
||||
# - or a pull request is made to the main branch that modifies this workflow file or commit message contains "fix" or "test"
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
paths:
|
||||
- '.github/workflows/ext-matrix-tests.yml'
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
paths:
|
||||
- '.github/workflows/ext-matrix-tests.yml'
|
||||
- 'src/**'
|
||||
- 'config/**'
|
||||
- 'bin/**'
|
||||
- 'composer.json'
|
||||
- 'box.json'
|
||||
- '.php-cs-fixer.php'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})"
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
if: contains(github.event.head_commit.message, 'fix') || contains(github.event.head_commit.message, 'test')
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user