Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/update-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
name: Update Framework Versions

"on":
repository_dispatch:
types: [yii-release]

jobs:
update-versions:
runs-on: ubuntu-latest
if: github.event.client_payload.action == 'published'

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: Validate payload
run: |
if [[ -z "${{ github.event.client_payload.repository.name }}" ]]; then
echo "Error: Repository name is missing"
exit 1
fi

if [[ -z "${{ github.event.client_payload.release.tag_name }}" ]]
then
echo "Error: Release tag name is missing"
exit 1
fi

echo "✓ Payload validation passed"

- name: Extract release information
id: release_info
run: |
repo="${{ github.event.client_payload.repository.full_name }}"
release="${{ github.event.client_payload.release.tag_name }}"
url="${{ github.event.client_payload.release.html_url }}"

echo "Repository: $repo"
echo "Release: $release"
echo "Release URL: $url"

# Determine Yii version from repository
repo_name="${{ github.event.client_payload.repository.name }}"
if [[ "$repo_name" == "yii2" ]]; then
echo "yii_version=2.0" >> $GITHUB_OUTPUT
elif [[ "$repo_name" == "yii" ]]; then
echo "yii_version=1.1" >> $GITHUB_OUTPUT
else
echo "Unsupported repository: $repo_name"
echo "Supported repositories: yii2, yii"
exit 1
fi

echo "tag_name=$release" >> $GITHUB_OUTPUT
echo "release_date=$(date +'%b %d, %Y')" >> $GITHUB_OUTPUT

- name: Update versions.php
run: |
php scripts/update-versions.php \
"${{ steps.release_info.outputs.yii_version }}" \
"${{ steps.release_info.outputs.tag_name }}" \
"${{ steps.release_info.outputs.release_date }}"

- name: Verify changes
run: |
echo "Changes made to config/versions.php:"
git diff config/versions.php

- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add config/versions.php

if git diff --staged --quiet; then
echo "No changes to commit (version may already exist)"
else
tag="${{ steps.release_info.outputs.tag_name }}"
version="${{ steps.release_info.outputs.yii_version }}"
url="${{ github.event.client_payload.release.html_url }}"
repo="${{ github.event.client_payload.repository.full_name }}"

git commit -m "Auto-update: Add $tag to Yii $version versions

Release: $url
Triggered by: $repo"
git push
echo "✓ Successfully updated and committed version $tag"
fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ nbproject
# Mac DS_Store Files
**/.DS_Store

# Backup files
*.backup

# composer vendor dir
/vendor

Expand Down
79 changes: 79 additions & 0 deletions docs/automatic-version-updates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Automatic Version Updates

This repository includes a GitHub Action that automatically updates the framework versions when new releases are published to the Yii repositories.

## How it works

The workflow `.github/workflows/update-versions.yml` responds to `repository_dispatch` events with the type `yii-release`. When triggered, it:

1. Extracts release information from the webhook payload
2. Determines which Yii version (2.0 or 1.1) based on the repository name
3. Updates the `config/versions.php` file with the new version
4. Commits and pushes the changes

## Setting up webhooks

To enable automatic updates from Yii repositories, you need to configure webhooks in the source repositories that send `repository_dispatch` events to this repository.

### For repository maintainers

You can set up a webhook in the Yii repositories (yiisoft/yii2, yiisoft/yii) that triggers this workflow:

1. Go to the repository settings → Webhooks
2. Add a new webhook with:
- **Payload URL**: `https://api.github.com/repos/yiisoft-contrib/yiiframework.com/dispatches`
- **Content type**: `application/json`
- **Secret**: Configure a secret token
- **Events**: Choose "Releases" only

3. The webhook should send a POST request with this format:
```json
{
"event_type": "yii-release",
"client_payload": {
"action": "published",
"repository": {
"name": "yii2",
"full_name": "yiisoft/yii2"
},
"release": {
"tag_name": "2.0.54",
"html_url": "https://github.com/yiisoft/yii2/releases/tag/2.0.54"
}
}
}
```

### Manual triggering

You can also manually trigger the workflow using the GitHub API:

```bash
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token YOUR_TOKEN" \
https://api.github.com/repos/yiisoft-contrib/yiiframework.com/dispatches \
-d '{
"event_type": "yii-release",
"client_payload": {
"action": "published",
"repository": {
"name": "yii2",
"full_name": "yiisoft/yii2"
},
"release": {
"tag_name": "2.0.54",
"html_url": "https://github.com/yiisoft/yii2/releases/tag/2.0.54"
}
}
}'
```

## Supported repositories

- `yiisoft/yii2` → Updates Yii 2.0 versions
- `yiisoft/yii` → Updates Yii 1.1 versions

## Files modified

- `config/versions.php` - The main versions configuration file where new releases are added to the `minor-versions` array
83 changes: 83 additions & 0 deletions scripts/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Integration test for the GitHub Action workflow
# This simulates the workflow steps without actually running the GitHub Action

set -e

echo "=== Integration Test for Version Update Workflow ==="

# Test data
TEST_REPO_NAME="yii2"
TEST_VERSION="2.0.99"
TEST_DATE="$(date +'%b %d, %Y')"
TEST_RELEASE_URL="https://github.com/yiisoft/yii2/releases/tag/$TEST_VERSION"

echo "Testing with:"
echo " Repository: $TEST_REPO_NAME"
echo " Version: $TEST_VERSION"
echo " Date: $TEST_DATE"
echo " URL: $TEST_RELEASE_URL"

# Step 1: Validate payload (simulate)
echo "Step 1: Validating payload..."
if [[ -z "$TEST_REPO_NAME" || -z "$TEST_VERSION" ]]; then
echo "✗ Payload validation failed"
exit 1
fi
echo "✓ Payload validation passed"

# Step 2: Extract release information (simulate)
echo "Step 2: Extracting release information..."
if [[ "$TEST_REPO_NAME" == "yii2" ]]; then
YII_VERSION="2.0"
elif [[ "$TEST_REPO_NAME" == "yii" ]]; then
YII_VERSION="1.1"
else
echo "✗ Unsupported repository: $TEST_REPO_NAME"
exit 1
fi
echo "✓ Determined Yii version: $YII_VERSION"

# Step 3: Update versions.php
echo "Step 3: Updating versions.php..."
# Create backup
cp config/versions.php config/versions.php.integration-backup

# Run the update script
php scripts/update-versions.php "$YII_VERSION" "$TEST_VERSION" "$TEST_DATE"

# Step 4: Verify changes
echo "Step 4: Verifying changes..."
if grep -q "'$TEST_VERSION' => '$TEST_DATE'" config/versions.php; then
echo "✓ Version $TEST_VERSION successfully added"
else
echo "✗ Version $TEST_VERSION not found in file"
exit 1
fi

# Show the diff
echo "Changes made:"
diff config/versions.php.integration-backup config/versions.php || true

# Step 5: Simulate commit preparation
echo "Step 5: Simulating commit preparation..."
git add config/versions.php

if git diff --staged --quiet; then
echo "ℹ No staged changes (this shouldn't happen in this test)"
else
echo "✓ Changes staged for commit"

# Show what would be committed
echo "Staged changes:"
git diff --staged --name-only
fi

# Clean up - restore original file and unstage changes
cp config/versions.php.integration-backup config/versions.php
rm config/versions.php.integration-backup
git reset HEAD config/versions.php > /dev/null 2>&1

echo "✓ Integration test completed successfully!"
echo "The workflow would work correctly with these inputs."
71 changes: 71 additions & 0 deletions scripts/test-update-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

# Test script for update-versions.php
# This script tests the version update functionality

set -e

echo "=== Testing update-versions.php script ==="

# Create a backup of the original versions file
cp config/versions.php config/versions.php.test-backup

echo "✓ Created backup of versions.php"

# Test 1: Add a new version to Yii 2.0
echo "Test 1: Adding version 2.0.99 to Yii 2.0..."
php scripts/update-versions.php "2.0" "2.0.99" "Test Date 2025"

# Verify the version was added
if grep -q "'2.0.99' => 'Test Date 2025'" config/versions.php; then
echo "✓ Test 1 passed: Version 2.0.99 added successfully"
else
echo "✗ Test 1 failed: Version 2.0.99 not found"
exit 1
fi

# Test 2: Add a new version to Yii 1.1
echo "Test 2: Adding version 1.1.99 to Yii 1.1..."
php scripts/update-versions.php "1.1" "1.1.99" "Test Date 2025"

# Verify the version was added
if grep -q "'1.1.99' => 'Test Date 2025'" config/versions.php; then
echo "✓ Test 2 passed: Version 1.1.99 added successfully"
else
echo "✗ Test 2 failed: Version 1.1.99 not found"
exit 1
fi

# Test 3: Try to add the same version again (should not duplicate)
echo "Test 3: Attempting to add duplicate version 2.0.99..."
output=$(php scripts/update-versions.php "2.0" "2.0.99" "Test Date 2025" 2>&1)

if [[ "$output" == *"already exists"* ]]; then
echo "✓ Test 3 passed: Duplicate version handling works correctly"
else
echo "✗ Test 3 failed: Duplicate version not detected"
exit 1
fi

# Test 4: Verify versions are added at the beginning (most recent first)
echo "Test 4: Verifying version order..."
line_2099=$(grep -n "'2.0.99'" config/versions.php | head -1 | cut -d: -f1)
line_2053=$(grep -n "'2.0.53'" config/versions.php | head -1 | cut -d: -f1)

if [[ $line_2099 -lt $line_2053 ]]; then
echo "✓ Test 4 passed: New versions are added at the beginning"
else
echo "✗ Test 4 failed: Version order is incorrect"
exit 1
fi

# Show the diff to see what changed
echo "=== Changes made to versions.php ==="
diff config/versions.php.test-backup config/versions.php || true

# Restore the original file
cp config/versions.php.test-backup config/versions.php
rm config/versions.php.test-backup

echo "✓ Restored original versions.php"
echo "=== All tests passed! ==="
Loading