name: ๐Ÿท๏ธ Release Workflow on: push: tags: - 'v*' workflow_dispatch: inputs: version: description: 'Release version (e.g., 1.0.0)' required: true type: string env: PHP_VERSION: '8.1' jobs: # ๐Ÿท๏ธ Create Release create-release: name: ๐Ÿท๏ธ Create Release Package runs-on: ubuntu-latest outputs: version: ${{ steps.version.outputs.version }} upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - name: ๐Ÿ“ฅ Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: ๐Ÿท๏ธ Get version id: version run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then VERSION="${{ github.event.inputs.version }}" else VERSION=${GITHUB_REF#refs/tags/v} fi echo "version=$VERSION" >> $GITHUB_OUTPUT echo "Version: $VERSION" - name: ๐Ÿ˜ Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} - name: ๐Ÿ”ง Install Composer dependencies run: composer install --prefer-dist --no-dev --no-progress --no-interaction --optimize-autoloader - name: ๐Ÿ“ Update version in plugin file run: | VERSION="${{ steps.version.outputs.version }}" sed -i "s/Version: .*/Version: $VERSION/" src/care-api.php sed -i "s/\* Version:.*/\* Version: $VERSION/" src/care-api.php - name: ๐Ÿ“ฆ Create release package run: | VERSION="${{ steps.version.outputs.version }}" # Create build directory mkdir -p release # Copy plugin files (production only) rsync -av \ --exclude='.git*' \ --exclude='node_modules' \ --exclude='tests' \ --exclude='coverage-html' \ --exclude='release' \ --exclude='*.log' \ --exclude='.github' \ --exclude='composer.json' \ --exclude='composer.lock' \ --exclude='phpunit.xml' \ --exclude='phpcs.xml' \ --exclude='.editorconfig' \ --exclude='bin/' \ --exclude='scripts/' \ --exclude='TESTING_SETUP.md' \ --exclude='*test*.php' \ . release/kivicare-api/ # Create version info file cat > release/kivicare-api/VERSION << EOF Version: $VERSION Build Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC") Commit: $(git rev-parse HEAD) Branch: $(git branch --show-current) Repository: ${{ github.repository }} EOF # Create ZIP package cd release zip -r "kivicare-api-v$VERSION.zip" kivicare-api/ # Generate checksums sha256sum "kivicare-api-v$VERSION.zip" > "kivicare-api-v$VERSION.zip.sha256" # Create plugin info JSON cat > "kivicare-api-v$VERSION.json" << EOF { "name": "KiviCare REST API", "version": "$VERSION", "description": "REST API extension for KiviCare WordPress plugin - Healthcare management system", "author": "Descomplicarยฎ Crescimento Digital", "homepage": "https://descomplicar.pt", "download_url": "https://github.com/${{ github.repository }}/releases/download/v$VERSION/kivicare-api-v$VERSION.zip", "requires_wp": "6.0", "requires_php": "8.1", "tested_wp": "6.4", "size": $(stat -c%s "kivicare-api-v$VERSION.zip"), "checksum": "$(cat kivicare-api-v$VERSION.zip.sha256 | cut -d' ' -f1)" } EOF cd .. - name: ๐Ÿ“‹ Generate changelog id: changelog run: | VERSION="${{ steps.version.outputs.version }}" # Extract changelog for this version if [ -f "CHANGELOG.md" ]; then awk -v version="$VERSION" ' /^## \[/ { if ($0 ~ version) { printing=1; next } else if (printing) { exit } } printing && /^## \[/ { exit } printing { print } ' CHANGELOG.md > release_notes.md # If no specific version found, get latest changes if [ ! -s release_notes.md ]; then head -n 20 CHANGELOG.md > release_notes.md fi else echo "๐Ÿš€ KiviCare REST API v$VERSION Release" > release_notes.md echo "" >> release_notes.md echo "### Changes in this release:" >> release_notes.md git log --oneline --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD >> release_notes.md fi - name: ๐Ÿท๏ธ Create GitHub Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: v${{ steps.version.outputs.version }} release_name: KiviCare REST API v${{ steps.version.outputs.version }} body_path: release_notes.md draft: false prerelease: false - name: ๐Ÿ“ค Upload ZIP package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: release/kivicare-api-v${{ steps.version.outputs.version }}.zip asset_name: kivicare-api-v${{ steps.version.outputs.version }}.zip asset_content_type: application/zip - name: ๐Ÿ“ค Upload checksum uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: release/kivicare-api-v${{ steps.version.outputs.version }}.zip.sha256 asset_name: kivicare-api-v${{ steps.version.outputs.version }}.zip.sha256 asset_content_type: text/plain - name: ๐Ÿ“ค Upload plugin info uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: release/kivicare-api-v${{ steps.version.outputs.version }}.json asset_name: kivicare-api-v${{ steps.version.outputs.version }}.json asset_content_type: application/json # ๐Ÿš€ Deploy to WordPress.org (se aplicรกvel) deploy-wporg: name: ๐Ÿš€ Deploy to WordPress.org runs-on: ubuntu-latest needs: create-release if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta') && !contains(github.ref, 'alpha') environment: production steps: - name: ๐Ÿ“ฅ Checkout code uses: actions/checkout@v4 - name: ๐Ÿš€ Deploy to WordPress.org SVN run: | echo "๐Ÿš€ Deploying to WordPress.org repository..." echo "Version: ${{ needs.create-release.outputs.version }}" # SVN deployment script would go here # This is a placeholder for actual WordPress.org deployment # ๐Ÿ“ง Notify stakeholders notify: name: ๐Ÿ“ง Notify Release runs-on: ubuntu-latest needs: [create-release, deploy-wporg] if: always() steps: - name: ๐Ÿ“ง Send release notification run: | VERSION="${{ needs.create-release.outputs.version }}" echo "๐Ÿ“ง Sending release notification..." echo "๐Ÿท๏ธ Released KiviCare REST API v$VERSION" echo "๐Ÿ“ฆ Package: kivicare-api-v$VERSION.zip" echo "๐Ÿ”— URL: https://github.com/${{ github.repository }}/releases/tag/v$VERSION" # Webhook/email notification would go here - name: ๐Ÿ“Š Update release metrics run: | echo "๐Ÿ“Š Updating release metrics..." # Metrics collection would go here