Updates #72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create Release | |
| on: | |
| push: | |
| # Trigger on pushes to main or master branch | |
| branches: [ main, master ] | |
| # Allow manual triggering | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| discussions: write | |
| jobs: | |
| check-and-release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get latest version | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -oP "Version: \K[0-9]+\.[0-9]+\.[0-9]+" free-gift-bulk-coupon-generator.php) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Found version: $VERSION" | |
| - name: Check if release exists | |
| id: check_release | |
| run: | | |
| RELEASE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ steps.get_version.outputs.version }}) | |
| if [[ "$RELEASE_EXISTS" == "200" ]]; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Release v${{ steps.get_version.outputs.version }} already exists" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| echo "Release v${{ steps.get_version.outputs.version }} does not exist yet" | |
| fi | |
| - name: Create zip file | |
| if: steps.check_release.outputs.exists == 'false' | |
| run: | | |
| mkdir -p free-gift-bulk-coupon-generator | |
| cp free-gift-bulk-coupon-generator.php free-gift-bulk-coupon-generator/ | |
| cp README.md free-gift-bulk-coupon-generator/ | |
| cp CHANGELOG.md free-gift-bulk-coupon-generator/ || echo "No CHANGELOG.md found" | |
| cp LICENSE free-gift-bulk-coupon-generator/ || echo "No LICENSE file found" | |
| cp uninstall.php free-gift-bulk-coupon-generator/ || echo "No uninstall.php found" | |
| [ -d assets ] && cp -r assets free-gift-bulk-coupon-generator/ || echo "No assets directory found" | |
| [ -d languages ] && cp -r languages free-gift-bulk-coupon-generator/ || echo "No languages directory found" | |
| zip -r free-gift-bulk-coupon-generator-${{ steps.get_version.outputs.version }}.zip free-gift-bulk-coupon-generator | |
| - name: Get changelog entry | |
| if: steps.check_release.outputs.exists == 'false' | |
| id: get_changelog | |
| run: | | |
| if [ -f CHANGELOG.md ]; then | |
| CHANGELOG_ENTRY=$(awk -v ver="## ${{ steps.get_version.outputs.version }}" 'BEGIN{flag=0} $0~ver{flag=1; print; next} /^## [0-9]+\.[0-9]+\.[0-9]+/{flag=0} flag{print}' CHANGELOG.md | tail -n +2) | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG_ENTRY" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| else | |
| echo "changelog=Initial release of WooCommerce Free Gift Bulk Coupons Generator" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create Release | |
| if: steps.check_release.outputs.exists == 'false' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.get_version.outputs.version }} | |
| name: Release v${{ steps.get_version.outputs.version }} | |
| body: | | |
| ${{ steps.get_changelog.outputs.changelog }} | |
| ## Installation | |
| 1. Download the zip file | |
| 2. Upload to your WordPress site through the Plugins > Add New > Upload menu | |
| 3. Activate the plugin | |
| 4. Navigate to WooCommerce > Coupon Generator to start using the plugin | |
| ## Requirements | |
| - WordPress 6.5 or higher | |
| - WooCommerce 5.0 or higher | |
| - PHP 7.4 or higher | |
| [Full Documentation](https://github.com/${{ github.repository }}) | |
| files: free-gift-bulk-coupon-generator-${{ steps.get_version.outputs.version }}.zip | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: false | |
| - name: Update README version | |
| if: steps.check_release.outputs.exists == 'false' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ steps.get_version.outputs.version }} | |
| run: | | |
| README_FILE="README.md" | |
| TMP_FILE=$(mktemp) | |
| # Update the version badge with the new version and logo | |
| sed -E 's/\[\!Version\]\(https:\/\/img\.shields\.io\/badge\/Version-[0-9]+\.[0-9]+\.[0-9]+-orange\.svg\?logo=github\)\]\(https:\/\/github\.com\/EngineScript\/WooCommerce-Free-Gift-Bulk-Coupons-Generator\/releases\/latest\/download\/free-gift-bulk-coupon-generator-[0-9]+\.[0-9]+\.[0-9]+\.zip\)/\[\!Version\]\(https:\/\/img\.shields\.io\/badge\/Version-'"$VERSION"'-orange\.svg\?logo=github\)\]\(https:\/\/github\.com\/EngineScript\/WooCommerce-Free-Gift-Bulk-Coupons-Generator\/releases\/latest\/download\/free-gift-bulk-coupon-generator-'"$VERSION"'\.zip\)/g' "$README_FILE" > "$TMP_FILE" | |
| # Replace file if changes were made | |
| if ! cmp -s "$README_FILE" "$TMP_FILE"; then | |
| cp "$TMP_FILE" "$README_FILE" | |
| echo "Updated README.md with version $VERSION" | |
| # Configure git | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| # Commit and push the changes | |
| git add "$README_FILE" | |
| git commit -m "docs: update README.md version to $VERSION [skip ci]" | |
| git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git | |
| echo "::notice::README.md updated with latest version $VERSION" | |
| else | |
| echo "::notice::README.md already has the correct version" | |
| fi | |
| # Clean up temporary file | |
| rm "$TMP_FILE" |