|
| 1 | +name: GitHub Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + name: Build & Release |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v3 |
| 16 | + |
| 17 | + - name: Debug File List |
| 18 | + run: ls -R |
| 19 | + |
| 20 | + - name: Find Readme File |
| 21 | + id: find_readme |
| 22 | + run: | |
| 23 | + for file in readme.txt Readme.txt README.txt README.md Readme.md readme.md; do |
| 24 | + if [ -f "$file" ]; then |
| 25 | + echo "Readme file found: $file" |
| 26 | + echo "readme_file=$file" >> $GITHUB_ENV |
| 27 | + break |
| 28 | + fi |
| 29 | + done |
| 30 | +
|
| 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 | +
|
| 44 | + if [[ "$GITHUB_REF" == refs/tags/* ]]; then |
| 45 | + plugin_version="${GITHUB_REF#refs/tags/}" |
| 46 | + echo "Detected tag version: $plugin_version" |
| 47 | + else |
| 48 | + echo "::error::Workflow must be triggered by a tag push." |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + in_changelog=0 |
| 53 | + found_version=0 |
| 54 | + release_notes="" |
| 55 | +
|
| 56 | + while IFS= read -r line; do |
| 57 | +
|
| 58 | + if [[ "$line" == "$changelog_section_start" ]]; then |
| 59 | + in_changelog=1 |
| 60 | + continue |
| 61 | + fi |
| 62 | +
|
| 63 | + if [[ $in_changelog -eq 0 ]]; then |
| 64 | + continue |
| 65 | + fi |
| 66 | +
|
| 67 | + if [[ "$line" == "= ${plugin_version} =" ]]; then |
| 68 | + found_version=1 |
| 69 | + continue |
| 70 | + fi |
| 71 | +
|
| 72 | + if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^= [0-9]+\.[0-9]+\.[0-9]+ =$'; then |
| 73 | + break |
| 74 | + fi |
| 75 | +
|
| 76 | + if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^\*'; then |
| 77 | + release_notes+="${line}\n" |
| 78 | + continue |
| 79 | + fi |
| 80 | +
|
| 81 | + done < "$readme_file" |
| 82 | +
|
| 83 | + if [[ -z "$release_notes" ]]; then |
| 84 | + echo "::error::Failed to extract release notes for version ${plugin_version}." |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +
|
| 88 | + echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV |
| 89 | + echo -e "$release_notes" >> $GITHUB_ENV |
| 90 | + echo "EOF" >> $GITHUB_ENV |
| 91 | +
|
| 92 | + - name: Create ZIP Archive |
| 93 | + run: | |
| 94 | + repo_name="${{ github.event.repository.name }}" |
| 95 | + zip_name="${repo_name}.zip" |
| 96 | +
|
| 97 | + zip -r "$zip_name" . \ |
| 98 | + -x "*.git*" \ |
| 99 | + ".github/*" |
| 100 | +
|
| 101 | + echo "ZIP_FILE=$zip_name" >> $GITHUB_ENV |
| 102 | +
|
| 103 | + - name: Create GitHub Release |
| 104 | + uses: softprops/action-gh-release@v2 |
| 105 | + with: |
| 106 | + tag_name: ${{ github.ref_name }} |
| 107 | + body: ${{ env.RELEASE_NOTES }} |
| 108 | + files: ${{ env.ZIP_FILE }} |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments