|
| 1 | +name: Release and Downgrade to PHP 7.4 |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + verify-php82: |
| 12 | + name: Verify PHP 8.2 Release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Check out source |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Ensure release tag starts with v2. |
| 21 | + run: | |
| 22 | + TAG="${{ github.event.release.tag_name }}" |
| 23 | + echo "Release tag: $TAG" |
| 24 | + if [[ ! "$TAG" =~ ^v2\.[0-9]+\.[0-9]+$ ]]; then |
| 25 | + echo "This workflow only runs for v2.x.y release tags. Got: $TAG" >&2 |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +
|
| 29 | + - name: Setup PHP 8.2 |
| 30 | + uses: shivammathur/setup-php@v2 |
| 31 | + with: |
| 32 | + php-version: '8.2' |
| 33 | + coverage: none |
| 34 | + tools: composer:v2 |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: composer install --no-interaction --prefer-dist --no-progress |
| 38 | + |
| 39 | + - name: Run checks (cs, psalm, tests, type, coverage, mutate) |
| 40 | + env: |
| 41 | + XDEBUG_MODE: coverage |
| 42 | + run: | |
| 43 | + composer validate --strict |
| 44 | + composer cs |
| 45 | + composer sca |
| 46 | + composer test |
| 47 | + composer type |
| 48 | + composer coverage |
| 49 | + composer mutate |
| 50 | +
|
| 51 | + downgrade-and-tag: |
| 52 | + name: Downgrade to PHP 7.4 and Tag v1.x |
| 53 | + needs: verify-php82 |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - name: Check out php7.4 branch |
| 57 | + uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + ref: php7.4 |
| 60 | + fetch-depth: 0 |
| 61 | + |
| 62 | + - name: Setup PHP 8.2 |
| 63 | + uses: shivammathur/setup-php@v2 |
| 64 | + with: |
| 65 | + php-version: '8.2' |
| 66 | + coverage: none |
| 67 | + tools: composer:v2 |
| 68 | + |
| 69 | + - name: Install dependencies (ignore platform reqs to allow downgrade tools) |
| 70 | + run: composer install --no-interaction --prefer-dist --no-progress --ignore-platform-reqs |
| 71 | + |
| 72 | + - name: Run Rector downgrade to PHP 7.4 |
| 73 | + run: ./vendor/bin/rector process --config rector/toPhp7.4.php |
| 74 | + |
| 75 | + - name: Update composer.json PHP constraint to ">=7.4,<=8.0" |
| 76 | + run: | |
| 77 | + php -r ' |
| 78 | + $f = "composer.json"; |
| 79 | + $j = json_decode(file_get_contents($f), true, 512, JSON_THROW_ON_ERROR); |
| 80 | + if (!isset($j["require"])) { $j["require"] = []; } |
| 81 | + $j["require"]["php"] = ">=7.4,<=8.0"; |
| 82 | + file_put_contents($f, json_encode($j, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . "\n"); |
| 83 | + ' |
| 84 | +
|
| 85 | + - name: Commit changes |
| 86 | + run: | |
| 87 | + git config user.name "github-actions[bot]" |
| 88 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 89 | + git add -A |
| 90 | + if ! git diff --cached --quiet; then |
| 91 | + git commit -m "chore(downgrade): apply Rector PHP 7.4 and set composer PHP constraint" |
| 92 | + else |
| 93 | + echo "No changes to commit." |
| 94 | + fi |
| 95 | +
|
| 96 | + - name: Compute new v1.x.y tag from release tag v2.x.y |
| 97 | + id: tag |
| 98 | + run: | |
| 99 | + SRC_TAG="${{ github.event.release.tag_name }}" |
| 100 | + # Convert v2.M.N -> v1.M.N |
| 101 | + NEW_TAG="${SRC_TAG/v2./v1.}" |
| 102 | + echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT" |
| 103 | + echo "New tag: $NEW_TAG" |
| 104 | +
|
| 105 | + - name: Push branch and tag |
| 106 | + env: |
| 107 | + NEW_TAG: ${{ steps.tag.outputs.new_tag }} |
| 108 | + run: | |
| 109 | + git push origin php7.4 |
| 110 | + # Create or move tag to latest commit on php7.4 |
| 111 | + if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then |
| 112 | + git tag -d "$NEW_TAG" |
| 113 | + fi |
| 114 | + git tag "$NEW_TAG" |
| 115 | + git push origin "$NEW_TAG" |
0 commit comments