Skip to content

Commit 50d9b72

Browse files
refactor: unify release workflow and build script
- Replace create-release-zip.sh with unified build-release.sh - Standardize release.yml with PHP setup and quality gates - Remove composer.json from ZIP (not needed at runtime) - Add conditional PHPCS/PHPStan quality gates - Generate MD5 + SHA256 checksums
1 parent 0d4e40d commit 50d9b72

File tree

3 files changed

+297
-472
lines changed

3 files changed

+297
-472
lines changed

.github/workflows/release.yml

Lines changed: 88 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -1,227 +1,92 @@
1-
name: Create Release Package
2-
permissions:
3-
contents: write
1+
name: Release
42

53
on:
6-
push:
7-
tags:
8-
- "v*"
9-
workflow_dispatch:
10-
inputs:
11-
version:
12-
description: "Version number (e.g., 1.0.1)"
13-
required: true
14-
default: "1.0.0"
15-
16-
jobs:
17-
build-and-release:
18-
runs-on: ubuntu-latest
19-
20-
steps:
21-
- name: Checkout code
22-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
23-
24-
- name: Extract version from tag or input
25-
id: version
26-
run: |
27-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
28-
VERSION="${{ github.event.inputs.version }}"
29-
else
30-
VERSION=${GITHUB_REF#refs/tags/v}
31-
fi
32-
echo "version=$VERSION" >> $GITHUB_OUTPUT
33-
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
34-
35-
- name: Update version in plugin files
36-
run: |
37-
VERSION="${{ steps.version.outputs.version }}"
38-
39-
# Update main plugin file
40-
sed -i "s/Version: [0-9]\+\.[0-9]\+\.[0-9]\+/Version: $VERSION/" leadgen-app-form.php
41-
sed -i "s/@version [0-9]\+\.[0-9]\+\.[0-9]\+/@version $VERSION/" leadgen-app-form.php
42-
43-
# Update other PHP files with @version
44-
find includes/ -name "*.php" -exec sed -i "s/@version [0-9]\+\.[0-9]\+\.[0-9]\+/@version $VERSION/" {} \;
45-
46-
# Update CSS files
47-
find assets/css/ -name "*.css" -exec sed -i "s/@version [0-9]\+\.[0-9]\+\.[0-9]\+/@version $VERSION/" {} \;
48-
49-
# Update JS files
50-
find assets/js/ -name "*.js" -exec sed -i "s/@version [0-9]\+\.[0-9]\+\.[0-9]\+/@version $VERSION/" {} \;
51-
find blocks/ -name "*.js" -exec sed -i "s/@version [0-9]\+\.[0-9]\+\.[0-9]\+/@version $VERSION/" {} \;
52-
53-
- name: Create distribution package
54-
id: package
55-
run: |
56-
VERSION="${{ steps.version.outputs.version }}"
57-
58-
# Make the script executable
59-
chmod +x scripts/create-release-zip.sh
60-
61-
# Run the release ZIP creation script
62-
./scripts/create-release-zip.sh "$VERSION"
63-
64-
# The script outputs to GITHUB_OUTPUT automatically
65-
# Additional logging for GitHub Actions
66-
echo "📦 Package created using create-release-zip.sh script"
67-
echo "� Version: $VERSION"
68-
69-
- name: Update RELEASE-NOTES.md
70-
run: |
71-
VERSION="${{ steps.version.outputs.version }}"
72-
PACKAGE_SIZE="${{ steps.package.outputs.package_size_kb }}"
73-
DATE=$(date +"%B %d, %Y")
74-
75-
# Create updated RELEASE-NOTES.md
76-
cat > RELEASE-NOTES.md << EOF
77-
# LeadGen App Form Plugin - Release v$VERSION
78-
79-
## Package Information
80-
- **Plugin Name**: LeadGen App Form Plugin
81-
- **Version**: $VERSION
82-
- **File**: leadgen-app-form-v$VERSION.zip
83-
- **Size**: ~$PACKAGE_SIZE
84-
- **Release Date**: $DATE
85-
- **License**: Polyform Noncommercial License 1.0.0
86-
- **Repository**: https://github.com/SilverAssist/leadgen-app-form
87-
88-
## Installation Package Contents
89-
- Main plugin file (\`leadgen-app-form.php\`)
90-
- Gutenberg block integration (\`blocks/leadgen-form/\`)
91-
- Elementor widget support (\`includes/elementor/\`)
92-
- Frontend assets (\`assets/css/\`, \`assets/js/\`)
93-
- Documentation ([README.md](README.md), [CHANGELOG.md](CHANGELOG.md))
94-
- License file (\`LICENSE\`)
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version to release (e.g. 1.2.0). Leave empty to use plugin file version.'
11+
required: false
9512

96-
## Installation Methods
97-
1. **WordPress Admin Dashboard** (Recommended)
98-
2. **Manual FTP Upload**
99-
3. **WP-CLI Installation**
100-
101-
## Requirements
102-
- WordPress 5.0+
103-
- PHP 8.0+
104-
105-
## Features Included
106-
- ✅ Gutenberg Block Integration
107-
- ✅ Elementor Widget Support
108-
- ✅ Responsive Form Handling
109-
- ✅ Modern PHP 8.0+ Features
110-
- ✅ Translation Ready
111-
- ✅ Performance Optimized
112-
- ✅ Polyform Noncommercial Licensed
113-
114-
## Distribution Channels
115-
- **GitHub Releases**: Source code and compiled packages
116-
- **Direct Download**: From developer website
117-
118-
## Support & Documentation
119-
- **Installation Guide**: [README.md](README.md)
120-
- **Change History**: [CHANGELOG.md](CHANGELOG.md)
121-
- **Issues**: GitHub Issues tracker
122-
123-
## Installation Instructions
124-
See [README.md](README.md) for complete installation guide.
125-
EOF
126-
127-
- name: Generate release notes from CHANGELOG
128-
id: changelog
129-
run: |
130-
VERSION="${{ steps.version.outputs.version }}"
131-
132-
# Extract current version changes from CHANGELOG.md
133-
if [ -f "CHANGELOG.md" ]; then
134-
echo "Looking for version $VERSION in CHANGELOG.md"
135-
136-
# Debug: Show CHANGELOG structure
137-
echo "Debug: Lines containing version pattern:"
138-
grep -n "\[${VERSION}\]" CHANGELOG.md || echo "No direct match found"
139-
140-
# Method 1: Using sed with escaped brackets (most reliable)
141-
CHANGES=$(sed -n "/## \\[${VERSION}\\]/,/## \\[/p" CHANGELOG.md | sed '$d' | tail -n +2)
142-
143-
if [ -n "$CHANGES" ]; then
144-
echo "✅ Found changes with sed method"
145-
echo "## Changes in v$VERSION" > release_notes.md
146-
echo "$CHANGES" >> release_notes.md
147-
else
148-
echo "❌ Sed method failed, trying awk method"
149-
# Method 2: Using awk (more reliable across different systems)
150-
CHANGES_AWK=$(awk "/^## \\[${VERSION}\\]/{flag=1; next} /^## \\[/{flag=0} flag" CHANGELOG.md)
151-
152-
if [ -n "$CHANGES_AWK" ]; then
153-
echo "✅ Found changes with awk method"
154-
echo "## Changes in v$VERSION" > release_notes.md
155-
echo "$CHANGES_AWK" >> release_notes.md
156-
else
157-
echo "❌ Awk method failed, trying grep method"
158-
# Method 3: Using grep with line numbers (fallback)
159-
LINE_START=$(grep -n "## \\[${VERSION}\\]" CHANGELOG.md | cut -d: -f1)
160-
if [ -n "$LINE_START" ]; then
161-
echo "✅ Found version at line: $LINE_START"
162-
# Extract from start line to next version or end of file
163-
CHANGES_GREP=$(tail -n +$((LINE_START + 1)) CHANGELOG.md | sed '/^## \[/q' | sed '$d')
164-
if [ -n "$CHANGES_GREP" ]; then
165-
echo "✅ Found changes with grep method"
166-
echo "## Changes in v$VERSION" > release_notes.md
167-
echo "$CHANGES_GREP" >> release_notes.md
168-
else
169-
echo "❌ All methods failed"
170-
echo "## Changes in v$VERSION" > release_notes.md
171-
echo "See [CHANGELOG.md](CHANGELOG.md) for detailed changes." >> release_notes.md
172-
fi
173-
else
174-
echo "❌ Version not found in CHANGELOG"
175-
echo "## Changes in v$VERSION" > release_notes.md
176-
echo "See [CHANGELOG.md](CHANGELOG.md) for detailed changes." >> release_notes.md
177-
fi
178-
fi
179-
fi
180-
else
181-
echo "CHANGELOG.md not found"
182-
echo "## Release v$VERSION" > release_notes.md
183-
echo "New release of LeadGen App Form Plugin" >> release_notes.md
184-
fi # Add package information to release notes
185-
cat >> release_notes.md << EOF
186-
187-
## 📦 Package Information
188-
- **File**: leadgen-app-form-v$VERSION.zip
189-
- **Size**: ~${{ steps.package.outputs.package_size_kb }}
190-
- **License**: Polyform Noncommercial License 1.0.0
191-
192-
## 🚀 Installation
193-
1. Download the ZIP file below
194-
2. Go to WordPress Admin → Plugins → Add New → Upload Plugin
195-
3. Choose the downloaded ZIP file and click "Install Now"
196-
4. Activate the plugin
197-
198-
For detailed installation instructions, see the [README.md](README.md) file.
199-
EOF
200-
201-
- name: Create GitHub Release
202-
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v1.0.0
203-
with:
204-
tag_name: ${{ steps.version.outputs.tag }}
205-
name: "LeadGen App Form Plugin v${{ steps.version.outputs.version }}"
206-
body_path: release_notes.md
207-
files: |
208-
${{ steps.package.outputs.zip_path }}
209-
draft: false
210-
prerelease: false
211-
env:
212-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
213-
214-
- name: Upload package as artifact
215-
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.6.0
216-
with:
217-
name: leadgen-app-form-v${{ steps.version.outputs.version }}
218-
path: ${{ steps.package.outputs.zip_path }}
219-
retention-days: 90
13+
permissions:
14+
contents: write
22015

221-
- name: Summary
222-
run: |
223-
echo "## 🎉 Release Summary" >> $GITHUB_STEP_SUMMARY
224-
echo "- **Version**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
225-
echo "- **Package**: ${{ steps.package.outputs.package_name }}.zip" >> $GITHUB_STEP_SUMMARY
226-
echo "- **Size**: ~${{ steps.package.outputs.package_size_kb }}" >> $GITHUB_STEP_SUMMARY
227-
echo "- **Release**: [View Release](https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.tag }})" >> $GITHUB_STEP_SUMMARY
16+
jobs:
17+
release:
18+
name: Build & Release
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: '8.2'
29+
tools: composer
30+
31+
- name: Detect version
32+
id: version
33+
run: |
34+
if [[ "${{ github.event_name }}" == "push" ]]; then
35+
VERSION="${GITHUB_REF_NAME#v}"
36+
elif [[ -n "${{ github.event.inputs.version }}" ]]; then
37+
VERSION="${{ github.event.inputs.version }}"
38+
else
39+
VERSION=$(grep -o 'Version: [0-9]\+\.[0-9]\+\.[0-9]\+' *.php 2>/dev/null | head -1 | cut -d' ' -f2)
40+
fi
41+
echo "version=$VERSION" >> $GITHUB_OUTPUT
42+
echo "🏷️ Version: $VERSION"
43+
44+
- name: Install dependencies
45+
run: composer install --no-interaction
46+
47+
- name: Update version
48+
run: |
49+
VERSION="${{ steps.version.outputs.version }}"
50+
if [ -f "scripts/update-version.sh" ]; then
51+
chmod +x scripts/update-version.sh
52+
./scripts/update-version.sh "$VERSION" --no-confirm --force
53+
elif [ -f "scripts/update-version-simple.sh" ]; then
54+
chmod +x scripts/update-version-simple.sh
55+
./scripts/update-version-simple.sh "$VERSION" --no-confirm --force
56+
fi
57+
58+
- name: Code quality
59+
run: |
60+
HAS_CHECKS=false
61+
if [ -f phpcs.xml ] || [ -f .phpcs.xml.dist ] || [ -f phpcs.xml.dist ]; then
62+
echo "▶ PHPCS"
63+
vendor/bin/phpcs
64+
HAS_CHECKS=true
65+
fi
66+
if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then
67+
echo "▶ PHPStan"
68+
vendor/bin/phpstan analyse --no-progress
69+
HAS_CHECKS=true
70+
fi
71+
if [ "$HAS_CHECKS" = false ]; then
72+
echo "ℹ️ No quality tool configs found — skipping"
73+
fi
74+
75+
- name: Build release
76+
id: build
77+
run: |
78+
chmod +x scripts/build-release.sh
79+
./scripts/build-release.sh "${{ steps.version.outputs.version }}"
80+
81+
- name: Create GitHub Release
82+
uses: softprops/action-gh-release@v2
83+
with:
84+
tag_name: v${{ steps.version.outputs.version }}
85+
name: v${{ steps.version.outputs.version }}
86+
files: |
87+
build/*.zip
88+
build/*.md5
89+
build/*.sha256
90+
generate_release_notes: true
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)