workflow updated #12
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: Deploy to WordPress.org | ||
| on: | ||
| push: | ||
| tags: | ||
| - "*" | ||
| env: | ||
| SVN_USERNAME: ${{ secrets.SVN_USERNAME }} | ||
| SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| jobs: | ||
| extract-release-notes: | ||
| name: Extract Release Notes | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| release_notes: ${{ steps.release_notes.outputs.release_notes }} | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Find Readme File | ||
| id: find_readme | ||
| run: | | ||
| for file in readme.txt Readme.txt README.txt README.md Readme.md readme.md; do | ||
| if [ -f "$file" ]; then | ||
| echo "readme_file=$file" >> $GITHUB_ENV | ||
| break | ||
| fi | ||
| done | ||
| source $GITHUB_ENV | ||
| if [ -z "$readme_file" ]; then | ||
| echo "::error::Readme file not found." | ||
| exit 1 | ||
| fi | ||
| - name: Extract Release Notes | ||
| id: release_notes | ||
| run: | | ||
| changelog_section_start="== Changelog ==" | ||
| readme_file="$readme_file" | ||
| plugin_version="${GITHUB_REF#refs/tags/}" | ||
| in_changelog=0 | ||
| found_version=0 | ||
| release_notes="" | ||
| while IFS= read -r line; do | ||
| if [[ "$line" == "$changelog_section_start" ]]; then | ||
| in_changelog=1 | ||
| continue | ||
| fi | ||
| if [[ $in_changelog -eq 0 ]]; then | ||
| continue | ||
| fi | ||
| if [[ "$line" == "= ${plugin_version} =" ]]; then | ||
| found_version=1 | ||
| continue | ||
| fi | ||
| if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^= [0-9]+\.[0-9]+\.[0-9]+ =$'; then | ||
| break | ||
| fi | ||
| if [[ $found_version -eq 1 ]]; then | ||
| release_notes+="${line}\n" | ||
| fi | ||
| done < "$readme_file" | ||
| if [[ -z "$release_notes" ]]; then | ||
| echo "::error::Failed to extract release notes for version ${plugin_version}." | ||
| exit 1 | ||
| fi | ||
| # Output for GitHub environment | ||
| release_notes="${release_notes//'%'/'%25'}" | ||
| release_notes="${release_notes//$'\n'/'%0A'}" | ||
| release_notes="${release_notes//$'\r'/'%0D'}" | ||
| echo "release_notes=$release_notes" >> $GITHUB_OUTPUT | ||
| update-trunk: | ||
| name: Upload to trunk | ||
| runs-on: ubuntu-latest | ||
| needs: extract-release-notes | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Install SVN | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y subversion | ||
| - name: Deploy trunk manually | ||
| run: | | ||
| PLUGIN_SLUG="${{ github.event.repository.name }}" | ||
| VERSION="${GITHUB_REF#refs/tags/}" | ||
| SVN_URL="https://plugins.svn.wordpress.org/${PLUGIN_SLUG}" | ||
| SVN_DIR="$HOME/svn-${PLUGIN_SLUG}" | ||
| echo "Checking out SVN..." | ||
| svn checkout "$SVN_URL" "$SVN_DIR" --depth immediates | ||
| svn update "$SVN_DIR/trunk" --set-depth infinity | ||
| echo "Copying plugin files..." | ||
| rsync -a --exclude='.git*' --exclude='.github' --exclude='svn-*' ./ "$SVN_DIR/trunk/" | ||
| cd "$SVN_DIR/trunk" | ||
| echo "Adding all new files to SVN..." | ||
| svn add . --force --quiet | ||
| echo "Committing to trunk..." | ||
| svn commit -m "Update trunk for version ${VERSION}" \ | ||
| --username "${SVN_USERNAME}" \ | ||
| --password "${SVN_PASSWORD}" \ | ||
| --non-interactive | ||
| tag-release: | ||
| name: Tag release in SVN | ||
| runs-on: ubuntu-latest | ||
| needs: update-trunk | ||
| steps: | ||
| - name: Install SVN | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y subversion | ||
| - name: Tag from trunk | ||
| run: | | ||
| PLUGIN_SLUG="${{ github.event.repository.name }}" | ||
| VERSION="${GITHUB_REF#refs/tags/}" | ||
| SVN_URL="https://plugins.svn.wordpress.org/${PLUGIN_SLUG}" | ||
| SVN_DIR="$HOME/svn-${PLUGIN_SLUG}" | ||
| svn checkout "$SVN_URL" "$SVN_DIR" --depth immediates | ||
| svn update "$SVN_DIR/trunk" --set-depth infinity | ||
| echo "Tagging version ${VERSION}..." | ||
| svn copy "$SVN_DIR/trunk" "$SVN_DIR/tags/${VERSION}" \ | ||
| -m "Tagging version ${VERSION}" \ | ||
| --username "${SVN_USERNAME}" \ | ||
| --password "${SVN_PASSWORD}" \ | ||
| --non-interactive | ||
| github-release: | ||
| name: Create GitHub Release | ||
| runs-on: ubuntu-latest | ||
| needs: [tag-release, extract-release-notes] | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Extract Version | ||
| id: version | ||
| run: | | ||
| echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | ||
| - name: Create ZIP | ||
| run: | | ||
| zip -r "${{ github.event.repository.name }}.zip" . -x ".git/*" ".github/*" | ||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ steps.version.outputs.version }} | ||
| name: ${{ steps.version.outputs.version }} | ||
| body: ${{ needs.extract-release-notes.outputs.release_notes }} | ||
| files: ${{ github.event.repository.name }}.zip | ||