|
| 1 | +name: Single Test |
| 2 | +on: |
| 3 | + push: |
| 4 | + |
| 5 | +permissions: read-all |
| 6 | + |
| 7 | +env: |
| 8 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + parse-commit: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + skip_craft: ${{ steps.parse_commit.outputs.skip_craft }} |
| 15 | + craft: ${{ steps.parse_commit.outputs.craft }} |
| 16 | + skip_bash: ${{ steps.parse_commit.outputs.skip_bash }} |
| 17 | + bash: ${{ steps.parse_commit.outputs.bash }} |
| 18 | + build_os: ${{ steps.parse_commit.outputs.build_os }} |
| 19 | + spc_prefix: ${{ steps.parse_commit.outputs.spc_prefix }} |
| 20 | + steps: |
| 21 | + - name: "Parse commit message" |
| 22 | + id: parse_commit |
| 23 | + run: | |
| 24 | + # parse the commit message, see if it has {craft} and {/craft} tags |
| 25 | + COMMIT_MESSAGE=$(git log -1 --pretty=%B) |
| 26 | + # judge it, it it's not exist, then skip this test |
| 27 | + if [[ "$COMMIT_MESSAGE" != *"{craft}"* ]] || [[ "$COMMIT_MESSAGE" != *"{/craft}"* ]]; then |
| 28 | + echo "No {craft} tags found in commit message. Skipping test." |
| 29 | + echo "skip_craft=yes" >> $GITHUB_OUTPUT |
| 30 | + exit 0 |
| 31 | + else |
| 32 | + echo "\e[32mCraft tags found in commit message.\e[0m" |
| 33 | + # get the craft content |
| 34 | + CRAFT_CONTENT=$(echo "$COMMIT_MESSAGE" | sed -nz 's/.*{craft}\(.*\){\/craft}.*/\1/p') |
| 35 | + echo "Craft content: $CRAFT_CONTENT" |
| 36 | + # set the output variable |
| 37 | + echo "craft=$CRAFT_CONTENT" >> $GITHUB_OUTPUT |
| 38 | + fi |
| 39 | +
|
| 40 | + # parse the bash test script from the commit message |
| 41 | + if [[ "$COMMIT_MESSAGE" != *"{bash}"* ]] || [[ "$COMMIT_MESSAGE" != *"{/bash}"* ]]; then |
| 42 | + echo "No {bash} tags found in commit message. Skipping bash test." |
| 43 | + echo "skip_bash=yes" >> $GITHUB_OUTPUT |
| 44 | + else |
| 45 | + echo "\e[32mBash tags found in commit message.\e[0m" |
| 46 | + # get the bash content |
| 47 | + BASH_CONTENT=$(echo "$COMMIT_MESSAGE" | sed -nz 's/.*{bash}\(.*\){\/bash}.*/\1/p') |
| 48 | + echo "Bash content: $BASH_CONTENT" |
| 49 | + # set the output variable |
| 50 | + echo "bash=$BASH_CONTENT" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | +
|
| 53 | + # parse spc_prefix from commit message, e.g. [spc_prefix:bin/spc-gnu-docker], default: bin/spc |
| 54 | + if [[ "$COMMIT_MESSAGE" =~ \[spc_prefix:([^\]]+)\] ]]; then |
| 55 | + SPC_PREFIX=${BASH_REMATCH[1]} |
| 56 | + echo "SPC prefix found: $SPC_PREFIX" |
| 57 | + else |
| 58 | + SPC_PREFIX="bin/spc" |
| 59 | + echo "No SPC prefix found, using default: $SPC_PREFIX" |
| 60 | + fi |
| 61 | + echo "spc_prefix=$SPC_PREFIX" >> $GITHUB_OUTPUT |
| 62 | +
|
| 63 | + # parse build_os from commit message, e.g. [build_os:ubuntu-latest], default: ubuntu-latest |
| 64 | + if [[ "$COMMIT_MESSAGE" =~ \[build_os:([^\]]+)\] ]]; then |
| 65 | + BUILD_OS=${BASH_REMATCH[1]} |
| 66 | + echo "Build OS found: $BUILD_OS" |
| 67 | + else |
| 68 | + BUILD_OS="ubuntu-latest" |
| 69 | + echo "No Build OS found, using default: $BUILD_OS" |
| 70 | + fi |
| 71 | + echo "build_os=$BUILD_OS" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + craft-test: |
| 74 | + needs: parse-commit |
| 75 | + if: needs.parse-commit.outputs.skip_craft != 'yes' |
| 76 | + runs-on: ${{ needs.parse-commit.outputs.build_os }} |
| 77 | + steps: |
| 78 | + - name: "Checkout" |
| 79 | + uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: "Setup PHP" |
| 82 | + uses: shivammathur/setup-php@v2 |
| 83 | + with: |
| 84 | + php-version: '8.4' |
| 85 | + extensions: curl, openssl, mbstring |
| 86 | + ini-values: memory_limit=-1 |
| 87 | + tools: composer |
| 88 | + |
| 89 | + - name: "Install Dependencies" |
| 90 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist |
| 91 | + |
| 92 | + - name: "Doctor" |
| 93 | + run: ${{ needs.parse-commit.outputs.spc_prefix }} doctor --auto-fix --debug |
| 94 | + |
| 95 | + - name: "Run Craft Test" |
| 96 | + run: | |
| 97 | + echo "Running craft test with content:" |
| 98 | + echo "${{ needs.parse-commit.outputs.craft }}" |
| 99 | + echo "${{ needs.parse-commit.outputs.craft }}" > craft.yml |
| 100 | + ${{ needs.parse-commit.outputs.spc_prefix }} craft --debug |
| 101 | +
|
| 102 | + bash-test: |
| 103 | + needs: parse-commit |
| 104 | + if: needs.parse-commit.outputs.skip_bash != 'yes' |
| 105 | + runs-on: ${{ needs.parse-commit.outputs.build_os }} |
| 106 | + steps: |
| 107 | + - name: "Checkout" |
| 108 | + uses: actions/checkout@v4 |
| 109 | + |
| 110 | + - name: "Setup PHP" |
| 111 | + uses: shivammathur/setup-php@v2 |
| 112 | + with: |
| 113 | + php-version: '8.4' |
| 114 | + extensions: curl, openssl, mbstring |
| 115 | + ini-values: memory_limit=-1 |
| 116 | + tools: composer |
| 117 | + |
| 118 | + - name: "Install Dependencies" |
| 119 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist |
| 120 | + |
| 121 | + - name: "Doctor" |
| 122 | + run: ${{ needs.parse-commit.outputs.spc_prefix }} doctor --auto-fix --debug |
| 123 | + |
| 124 | + - name: "Run Bash Test" |
| 125 | + run: | |
| 126 | + echo "Running bash test with content:" |
| 127 | + echo "${{ needs.parse-commit.outputs.bash }}" |
| 128 | + echo "${{ needs.parse-commit.outputs.bash }}" | bash |
0 commit comments