|
| 1 | +name: Create Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*.*.*' |
| 7 | + branches: |
| 8 | + - master |
| 9 | + |
| 10 | +jobs: |
| 11 | + create_release: |
| 12 | + if: github.ref == 'refs/heads/master' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v3 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Find Readme File |
| 20 | + id: find_readme |
| 21 | + run: | |
| 22 | + for file in README.txt README.md Readme.txt Readme.md readme.txt readme.md; do |
| 23 | + if [ -f "$file" ]; then |
| 24 | + echo "Readme file found: $file" |
| 25 | + echo "readme_file=$file" >> $GITHUB_ENV |
| 26 | + break |
| 27 | + fi |
| 28 | + done |
| 29 | +
|
| 30 | + # Ensure the variable is available within the current step |
| 31 | + source $GITHUB_ENV |
| 32 | +
|
| 33 | + if [ -z "$readme_file" ]; then |
| 34 | + echo "::error::Readme file not found." |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Extract Release Notes |
| 39 | + id: release_notes |
| 40 | + run: | |
| 41 | + changelog_section_start="== Changelog ==" |
| 42 | + readme_file="$readme_file" |
| 43 | + #plugin_version="${{ github.ref_name }}" # Assuming the tag is the version |
| 44 | + plugin_version="${GITHUB_REF#refs/tags/}" |
| 45 | + |
| 46 | + echo "DEBUG: Plugin latest version found $plugin_version." |
| 47 | +
|
| 48 | + in_changelog=0 |
| 49 | + found_version=0 |
| 50 | + release_notes="" |
| 51 | +
|
| 52 | + echo "DEBUG: Starting to extract release notes from $readme_file for version $plugin_version." |
| 53 | +
|
| 54 | + while IFS= read -r line; do |
| 55 | + echo "DEBUG: Processing line: $line" |
| 56 | +
|
| 57 | + # Start processing after the changelog header |
| 58 | + if [[ "$line" == "$changelog_section_start" ]]; then |
| 59 | + in_changelog=1 |
| 60 | + echo "DEBUG: Found changelog section header." |
| 61 | + continue |
| 62 | + fi |
| 63 | +
|
| 64 | + # Skip if not in changelog section |
| 65 | + if [[ $in_changelog -eq 0 ]]; then |
| 66 | + echo "DEBUG: Skipping line (not in changelog section)." |
| 67 | + continue |
| 68 | + fi |
| 69 | +
|
| 70 | + # Check for the current version header |
| 71 | + if [[ "$line" == "= ${plugin_version} =" ]]; then |
| 72 | + found_version=1 |
| 73 | + echo "DEBUG: Found version header for $plugin_version." |
| 74 | + continue |
| 75 | + fi |
| 76 | +
|
| 77 | + # Break if a new version header is found after the current version |
| 78 | + if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^= [0-9]+\.[0-9]+\.[0-9]+ =$'; then |
| 79 | + echo "DEBUG: Found a new version header. Stopping collection." |
| 80 | + break |
| 81 | + fi |
| 82 | +
|
| 83 | + # Collect lines starting with '*' if we are in the current version section |
| 84 | + if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^\*'; then |
| 85 | + echo "DEBUG: Found changelog entry: $line" |
| 86 | + release_notes+="${line}\n" |
| 87 | + continue |
| 88 | + fi |
| 89 | +
|
| 90 | + # Log skipped lines in the current version section |
| 91 | + if [[ $found_version -eq 1 ]]; then |
| 92 | + echo "DEBUG: Skipping line (not a changelog entry): $line" |
| 93 | + fi |
| 94 | + done < "$readme_file" |
| 95 | +
|
| 96 | + if [[ -z "$release_notes" ]]; then |
| 97 | + echo "::error::Failed to extract release notes for version ${plugin_version}." |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + echo "DEBUG: Successfully extracted release notes." |
| 102 | + echo "DEBUG: Release notes content:" |
| 103 | + echo -e "$release_notes" |
| 104 | +
|
| 105 | + # Write the release notes with actual line breaks |
| 106 | + echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV |
| 107 | + echo -e "$release_notes" >> $GITHUB_ENV |
| 108 | + echo "EOF" >> $GITHUB_ENV |
| 109 | + |
| 110 | + |
| 111 | + - name: Create zip file |
| 112 | + run: | |
| 113 | + REPO_NAME=$(basename `git rev-parse --show-toplevel`) |
| 114 | + zip -r ${REPO_NAME}.zip . -x '*.git*' -x '.github/*' -x '*.distignore*' -x 'CHANGELOG.txt' |
| 115 | + echo "repo_name=${REPO_NAME}" >> $GITHUB_ENV |
| 116 | +
|
| 117 | + # Source to make repo_name available in subsequent steps |
| 118 | + source $GITHUB_ENV |
| 119 | +
|
| 120 | + - name: Create Release |
| 121 | + id: create_release |
| 122 | + uses: actions/create-release@v1 |
| 123 | + env: |
| 124 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + with: |
| 126 | + tag_name: ${{ github.ref_name }} |
| 127 | + release_name: "${{ github.ref_name }}" |
| 128 | + body: ${{ env.RELEASE_NOTES }} |
| 129 | + draft: false |
| 130 | + prerelease: false |
| 131 | + |
| 132 | + - name: Upload Release Asset |
| 133 | + uses: actions/upload-release-asset@v1 |
| 134 | + env: |
| 135 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 136 | + with: |
| 137 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 138 | + asset_path: ./${{ env.repo_name }}.zip |
| 139 | + asset_name: ${{ env.repo_name }}.zip |
| 140 | + asset_content_type: application/zip |
0 commit comments