|
| 1 | +name: Create Release from CHANGELOG |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "CHANGELOG.md" # Only trigger when CHANGELOG.md is updated |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 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 |
| 47 | + run: | |
| 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 |
| 52 | + else |
| 53 | + echo "No existing release found for: $VERSION" |
| 54 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 55 | + fi |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Create zip archive |
| 60 | + if: steps.check_release.outputs.exists == 'false' |
| 61 | + run: zip -r AutoTarCompress-${{ 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 |
| 66 | + with: |
| 67 | + tag_name: ${{ steps.changelog.outputs.version }} |
| 68 | + name: "Release ${{ steps.changelog.outputs.version }}" |
| 69 | + body: ${{ steps.changelog.outputs.notes }} |
| 70 | + draft: false |
| 71 | + prerelease: ${{ contains(steps.changelog.outputs.version, '-') }} |
| 72 | + files: AutoTarCompress-${{ steps.changelog.outputs.version }}.zip |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments