1- name : Create Release
1+ name : Create Release from CHANGELOG
22
33on :
4- push :
4+ push :
55 branches : [ main ]
6- # Uncomment below if you want to trigger on tags instead
7- # tags:
8- # - "v*" # Trigger on tags starting with 'v' (e.g., v1.0.0)
6+ paths :
7+ - ' CHANGELOG.md' # Only trigger when CHANGELOG.md is updated
98
109jobs :
11- create- release :
10+ release :
1211 runs-on : ubuntu-latest
1312 permissions :
14- contents : write # Required to create releases
13+ contents : write
1514
1615 steps :
17- - name : Checkout Repository
16+ - name : Checkout code
1817 uses : actions/checkout@v4
19- with :
20- fetch-depth : 0 # This fetches all history for proper versioning
2118
22- - name : Generate Tag
23- id : tag
24- # Create a tag based on the date and run number if we're not triggered by a tag
19+ - name : Extract latest version and notes
20+ id : changelog
21+ run : |
22+ # Extract the first version number from CHANGELOG.md
23+ VERSION=$(grep -m 1 '^## v' CHANGELOG.md | sed 's/^## \(v[0-9.]*[0-9]\(-[a-zA-Z0-9]*\)*\).*/\1/')
24+ echo "version=$VERSION" >> $GITHUB_OUTPUT
25+
26+ # Extract notes for this version (everything between this version header and the next version header)
27+ NOTES=$(awk -v ver="$VERSION" '
28+ BEGIN { found=0; capture=0; notes=""; }
29+ $0 ~ "^## " ver { found=1; capture=1; next; }
30+ $0 ~ /^## v/ && capture==1 { capture=0; }
31+ capture==1 { notes = notes $0 "\n"; }
32+ END { print notes; }
33+ ' CHANGELOG.md)
34+
35+ # Save notes to output with correct GitHub multiline syntax
36+ EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
37+ echo "notes<<$EOF" >> $GITHUB_OUTPUT
38+ echo "$NOTES" >> $GITHUB_OUTPUT
39+ echo "$EOF" >> $GITHUB_OUTPUT
40+
41+ # For debugging
42+ echo "Found version: $VERSION"
43+ echo "Release notes excerpt: $(echo "$NOTES" | head -3)..."
44+
45+ - name : Check for existing release
46+ id : check_release
2547 run : |
26- if [[ "${{ github.ref_type }}" == "tag" ]]; then
27- echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
48+ VERSION=${{ steps.changelog.outputs.version }}
49+ if gh release view $VERSION &>/dev/null; then
50+ echo "Release already exists: $VERSION"
51+ echo "exists=true" >> $GITHUB_OUTPUT
2852 else
29- echo "tag=v$(date +'%Y.%m.%d')-build.${{ github.run_number }}" >> $GITHUB_OUTPUT
53+ echo "No existing release found for: $VERSION"
54+ echo "exists=false" >> $GITHUB_OUTPUT
3055 fi
31-
32- - name : Zip Entire Repository
33- run : zip -r fedora-setup.zip ./ -x "*.git*" ".github/*"
34-
35- - name : Create Release
36- id : create-release
37- uses : actions/create-release@v1
3856 env :
3957 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
58+
59+ - name : Create zip archive
60+ if : steps.check_release.outputs.exists == 'false'
61+ run : zip -r fedora-setup-${{ steps.changelog.outputs.version }}.zip ./ -x "*.git*" ".github/*"
62+
63+ - name : Create GitHub Release
64+ if : steps.check_release.outputs.exists == 'false'
65+ uses : softprops/action-gh-release@v1
4066 with :
41- tag_name : ${{ steps.tag.outputs.tag }}
42- release_name : " Release ${{ steps.tag.outputs.tag }}"
67+ tag_name : ${{ steps.changelog.outputs.version }}
68+ name : " Release ${{ steps.changelog.outputs.version }}"
69+ body : ${{ steps.changelog.outputs.notes }}
4370 draft : false
44- prerelease : false
45-
46- - name : Upload Release Asset
47- uses : actions/upload-release-asset@v1
71+ prerelease : ${{ contains(steps.changelog.outputs.version, '-') }}
72+ files : fedora-setup-${{ steps.changelog.outputs.version }}.zip
4873 env :
49- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
50- with :
51- upload_url : ${{ steps.create-release.outputs.upload_url }}
52- asset_path : ./fedora-setup.zip
53- asset_name : fedora-setup.zip
54- asset_content_type : application/zip
74+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments