|
1 | 1 | name: Deploy to WordPress.org |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | 5 | tags: |
5 | | - - "*" |
| 6 | + - "*" |
| 7 | + |
6 | 8 | jobs: |
7 | 9 | tag: |
8 | 10 | name: New tag |
9 | 11 | runs-on: ubuntu-latest |
10 | 12 | steps: |
11 | | - - uses: actions/checkout@master |
12 | | - #- name: Build # Remove or modify this step as needed |
13 | | - # run: | |
14 | | - # npm install |
15 | | - # npm run build |
16 | | - - name: Install SVN ( Subversion ) |
17 | | - run: | |
18 | | - sudo apt-get update |
19 | | - sudo apt-get install subversion |
20 | | - - name: WordPress Plugin Deploy |
21 | | - id: deploy |
22 | | - uses: 10up/action-wordpress-plugin-deploy@stable |
23 | | - with: |
24 | | - generate-zip: true |
25 | | - env: |
26 | | - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} |
27 | | - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} |
28 | | - #SLUG: my-super-cool-plugin # optional, remove if GitHub repo name matches SVN slug, including capitalization |
29 | | - - name: Create GitHub release |
30 | | - uses: softprops/action-gh-release@v1 |
31 | | - with: |
32 | | - files: ${{github.workspace}}/${{ github.event.repository.name }}.zip |
33 | | - env: |
34 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 13 | + - uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Debug File List |
| 16 | + run: ls -R |
| 17 | + |
| 18 | + - name: Install SVN (Subversion) |
| 19 | + run: | |
| 20 | + sudo apt-get update |
| 21 | + sudo apt-get install subversion |
| 22 | +
|
| 23 | + - name: Find Readme File |
| 24 | + id: find_readme |
| 25 | + run: | |
| 26 | + for file in readme.txt Readme.txt README.txt README.md Readme.md readme.md; do |
| 27 | + if [ -f "$file" ]; then |
| 28 | + echo "Readme file found: $file" |
| 29 | + echo "readme_file=$file" >> $GITHUB_ENV |
| 30 | + break |
| 31 | + fi |
| 32 | + done |
| 33 | +
|
| 34 | + # Ensure the variable is available within the current step |
| 35 | + source $GITHUB_ENV |
| 36 | +
|
| 37 | + if [ -z "$readme_file" ]; then |
| 38 | + echo "::error::Readme file not found." |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Extract Release Notes |
| 43 | + id: release_notes |
| 44 | + run: | |
| 45 | + changelog_section_start="== Changelog ==" |
| 46 | + readme_file="$readme_file" |
| 47 | +
|
| 48 | + # Extract the tag name from GITHUB_REF (plugin_version) |
| 49 | + if [[ "$GITHUB_REF" == refs/tags/* ]]; then |
| 50 | + plugin_version="${GITHUB_REF#refs/tags/}" |
| 51 | + echo "DEBUG: Plugin latest version found: $plugin_version." |
| 52 | + else |
| 53 | + echo "::error::This workflow must be triggered by a tag push." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + in_changelog=0 |
| 58 | + found_version=0 |
| 59 | + release_notes="" |
| 60 | +
|
| 61 | + echo "DEBUG: Starting to extract release notes from $readme_file for version $plugin_version." |
| 62 | +
|
| 63 | + while IFS= read -r line; do |
| 64 | + echo "DEBUG: Processing line: $line" |
| 65 | +
|
| 66 | + # Start processing after the changelog header |
| 67 | + if [[ "$line" == "$changelog_section_start" ]]; then |
| 68 | + in_changelog=1 |
| 69 | + echo "DEBUG: Found changelog section header." |
| 70 | + continue |
| 71 | + fi |
| 72 | +
|
| 73 | + # Skip if not in changelog section |
| 74 | + if [[ $in_changelog -eq 0 ]]; then |
| 75 | + echo "DEBUG: Skipping line (not in changelog section)." |
| 76 | + continue |
| 77 | + fi |
| 78 | +
|
| 79 | + # Check for the current version header |
| 80 | + if [[ "$line" == "= ${plugin_version} =" ]]; then |
| 81 | + found_version=1 |
| 82 | + echo "DEBUG: Found version header for $plugin_version." |
| 83 | + continue |
| 84 | + fi |
| 85 | +
|
| 86 | + # Break if a new version header is found after the current version |
| 87 | + if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^= [0-9]+\.[0-9]+\.[0-9]+ =$'; then |
| 88 | + echo "DEBUG: Found a new version header. Stopping collection." |
| 89 | + break |
| 90 | + fi |
| 91 | +
|
| 92 | + # Collect lines starting with '*' if we are in the current version section |
| 93 | + if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^\*'; then |
| 94 | + echo "DEBUG: Found changelog entry: $line" |
| 95 | + release_notes+="${line}\n" |
| 96 | + continue |
| 97 | + fi |
| 98 | +
|
| 99 | + # Log skipped lines in the current version section |
| 100 | + if [[ $found_version -eq 1 ]]; then |
| 101 | + echo "DEBUG: Skipping line (not a changelog entry): $line" |
| 102 | + fi |
| 103 | + done < "$readme_file" |
| 104 | +
|
| 105 | + if [[ -z "$release_notes" ]]; then |
| 106 | + echo "::error::Failed to extract release notes for version ${plugin_version}." |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | +
|
| 110 | + echo "DEBUG: Successfully extracted release notes." |
| 111 | + echo "DEBUG: Release notes content:" |
| 112 | + echo -e "$release_notes" |
| 113 | +
|
| 114 | + # Write the release notes with actual line breaks |
| 115 | + echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV |
| 116 | + echo -e "$release_notes" >> $GITHUB_ENV |
| 117 | + echo "EOF" >> $GITHUB_ENV |
| 118 | +
|
| 119 | + - name: WordPress Plugin Deploy |
| 120 | + id: deploy |
| 121 | + uses: 10up/action-wordpress-plugin-deploy@stable |
| 122 | + with: |
| 123 | + generate-zip: true |
| 124 | + |
| 125 | + - name: Create GitHub Release |
| 126 | + uses: softprops/action-gh-release@v2 |
| 127 | + with: |
| 128 | + tag_name: ${{ github.ref_name }} |
| 129 | + body: ${{ env.RELEASE_NOTES }} |
| 130 | + files: ${{github.workspace}}/${{ github.event.repository.name }}.zip |
| 131 | + |
| 132 | +env: |
| 133 | + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} |
| 134 | + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} |
| 135 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments