Merge branch 'main' of https://github.com/sinanisler/github-to-wordpr… #25
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: Plugin Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: '0' | |
| - name: Get current version | |
| id: get_version | |
| run: | | |
| version=$(grep -oP 'Version:\s*\K[0-9.]+' github-to-wordpress-sync.php) | |
| echo "Current version: $version" | |
| echo "version=$version" >> $GITHUB_ENV | |
| - name: Bump version if release | |
| if: contains(github.event.head_commit.message, 'release') | |
| run: | | |
| current_version=$(grep -oP 'Version:\s*\K[0-9.]+' github-to-wordpress-sync.php) | |
| next_version=$(awk -F. '{print $1 "." ($2+1)}' <<< "$current_version") | |
| sed -i "s/Version: $current_version/Version: $next_version/" github-to-wordpress-sync.php | |
| echo "new_version=$next_version" >> $GITHUB_ENV | |
| - name: Commit version bump | |
| if: contains(github.event.head_commit.message, 'release') | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add github-to-wordpress-sync.php | |
| git commit -m "Bump version to ${{ env.new_version }}" | |
| git push | |
| - name: Create zip file | |
| run: | | |
| mkdir -p github-to-wordpress-sync | |
| rsync -av --exclude='.git' --exclude='.github' --exclude='github-to-wordpress-sync' ./ github-to-wordpress-sync/ | |
| zip -r github-to-wordpress-sync.zip github-to-wordpress-sync | |
| rm -rf github-to-wordpress-sync | |
| - name: Generate changelog | |
| if: contains(github.event.head_commit.message, 'release') | |
| id: changelog | |
| run: | | |
| # Get the previous release tag | |
| previous_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$previous_tag" ]; then | |
| # If no previous tag, get all commits | |
| changelog=$(git log --pretty=format:"- %s (%h)") | |
| else | |
| # Get commits since previous tag | |
| changelog=$(git log ${previous_tag}..HEAD --pretty=format:"- %s (%h)") | |
| fi | |
| # Create the release body | |
| { | |
| echo "## What's Changed" | |
| echo "" | |
| echo "$changelog" | |
| echo "" | |
| if [ -n "$previous_tag" ]; then | |
| echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${previous_tag}...v${{ env.new_version }}" | |
| fi | |
| } > release_notes.md | |
| # Set output for use in next step | |
| echo "previous_tag=$previous_tag" >> $GITHUB_ENV | |
| - name: Create GitHub Release | |
| if: contains(github.event.head_commit.message, 'release') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: github-to-wordpress-sync.zip | |
| tag_name: "v${{ env.new_version }}" | |
| name: "Release v${{ env.new_version }}" | |
| body_path: release_notes.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate pre-release changelog | |
| if: contains(github.event.head_commit.message, 'alphatag') | |
| run: | | |
| # Get the previous tag | |
| previous_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$previous_tag" ]; then | |
| changelog=$(git log --pretty=format:"- %s (%h)") | |
| else | |
| changelog=$(git log ${previous_tag}..HEAD --pretty=format:"- %s (%h)") | |
| fi | |
| { | |
| echo "## What's Changed (Pre-release)" | |
| echo "" | |
| echo "$changelog" | |
| echo "" | |
| if [ -n "$previous_tag" ]; then | |
| echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${previous_tag}...pre-v${{ env.version }}" | |
| fi | |
| } > prerelease_notes.md | |
| - name: Create GitHub Pre-release | |
| if: contains(github.event.head_commit.message, 'alphatag') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| prerelease: true | |
| files: github-to-wordpress-sync.zip | |
| tag_name: "pre-v${{ env.version }}" | |
| name: "Pre-release v${{ env.version }}" | |
| body_path: prerelease_notes.md | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |