Skip to content

Release and Downgrade to PHP 7.4 #37

Release and Downgrade to PHP 7.4

Release and Downgrade to PHP 7.4 #37

Workflow file for this run

name: Release and Downgrade to PHP 7.4
on:
release:
types: [ published ]
permissions:
contents: write
jobs:
verify-php82:
name: Verify PHP 8.2 Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure release tag starts with v2.
run: |
TAG="${{ github.event.release.tag_name }}"
echo "Release tag: $TAG"
if [[ ! "$TAG" =~ ^v2\.[0-9]+\.[0-9]+$ ]]; then
echo "This workflow only runs for v2.x.y release tags. Got: $TAG" >&2
exit 1
fi
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2.16'
extensions: mbstring, intl
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-reqs
- name: Run tests
run: composer run-script test
downgrade-and-tag:
name: Release PHP 7.4 with Tag v1.x
needs: verify-php82
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create/Switch to php7.4 branch from release tag
run: |
SRC_TAG="${{ github.event.release.tag_name }}"
echo "Source tag: $SRC_TAG"
# Ensure the tag exists locally (should be fetched by checkout with fetch-depth:0)
git fetch --tags
# Create or reset local branch php7.4 to the release tag commit
git checkout -B php7.4 "$SRC_TAG"
- name: Setup PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: xdebug
tools: composer:v2
- name: Install dependencies (ignore platform reqs to allow downgrade tools)
run: composer install --no-interaction --prefer-dist --no-progress --ignore-platform-reqs
- name: Run Rector downgrade to PHP 7.4
run: ./vendor/bin/rector process --config rector/toPhp7.4.php
- name: Update composer.json PHP constraint to ">=7.4,<8.2"
run: |
php -r '
$f = "composer.json";
$j = json_decode(file_get_contents($f), true, 512, JSON_THROW_ON_ERROR);
if (!isset($j["require"])) { $j["require"] = []; }
$j["require"]["php"] = ">=7.4,<8.2";
$j["description"] = $j["description"] . " (PHP 7.4 version)";
file_put_contents($f, json_encode($j, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . "\n");
'
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if ! git diff --cached --quiet; then
git commit -m "chore(downgrade): apply Rector PHP 7.4 and set composer PHP constraint"
else
echo "No changes to commit."
fi
- name: Compute new v1.x.y tag from release tag v2.x.y
id: tag
run: |
SRC_TAG="${{ github.event.release.tag_name }}"
# Convert v2.M.N -> v1.M.N
NEW_TAG="${SRC_TAG/v2./v1.}"
echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
echo "New tag: $NEW_TAG"
- name: Push branch and tag
env:
NEW_TAG: ${{ steps.tag.outputs.new_tag }}
run: |
# Push the php7.4 branch (create or update). Use force-with-lease to update if it already exists.
git push --force-with-lease origin php7.4
# Create or move tag to latest commit on php7.4
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
git tag -d "$NEW_TAG"
fi
git tag "$NEW_TAG"
git push origin "$NEW_TAG"