|
| 1 | +name: Create GitHub Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Tag to release (for example: v0.8.5)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: release-${{ github.ref }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + create-release: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + env: |
| 25 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v5 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Resolve tag and version |
| 32 | + id: meta |
| 33 | + shell: bash |
| 34 | + run: | |
| 35 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 36 | + TAG_NAME="${{ inputs.tag }}" |
| 37 | + else |
| 38 | + TAG_NAME="${GITHUB_REF_NAME}" |
| 39 | + fi |
| 40 | +
|
| 41 | + if [ -z "$TAG_NAME" ]; then |
| 42 | + echo "Tag name is empty" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + VERSION="${TAG_NAME#v}" |
| 47 | + echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT" |
| 48 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 49 | +
|
| 50 | + - name: Extract release notes from changelog |
| 51 | + id: notes |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + VERSION="${{ steps.meta.outputs.version }}" |
| 55 | +
|
| 56 | + awk -v ver="$VERSION" ' |
| 57 | + index($0, "## " ver) == 1 { in_section = 1; next } |
| 58 | + in_section && /^## / { exit } |
| 59 | + in_section { print } |
| 60 | + ' CHANGELOG.md > RELEASE_NOTES.md |
| 61 | +
|
| 62 | + if grep -q '[^[:space:]]' RELEASE_NOTES.md; then |
| 63 | + echo "has_notes=true" >> "$GITHUB_OUTPUT" |
| 64 | + else |
| 65 | + echo "No changelog section for version $VERSION, fallback to autogenerated notes" |
| 66 | + echo "has_notes=false" >> "$GITHUB_OUTPUT" |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Create release from changelog notes |
| 70 | + if: steps.notes.outputs.has_notes == 'true' |
| 71 | + uses: softprops/action-gh-release@v2 |
| 72 | + with: |
| 73 | + tag_name: ${{ steps.meta.outputs.tag }} |
| 74 | + name: OpenIso ${{ steps.meta.outputs.version }} |
| 75 | + body_path: RELEASE_NOTES.md |
| 76 | + draft: false |
| 77 | + prerelease: false |
| 78 | + |
| 79 | + - name: Create release with autogenerated notes |
| 80 | + if: steps.notes.outputs.has_notes != 'true' |
| 81 | + uses: softprops/action-gh-release@v2 |
| 82 | + with: |
| 83 | + tag_name: ${{ steps.meta.outputs.tag }} |
| 84 | + name: OpenIso ${{ steps.meta.outputs.version }} |
| 85 | + generate_release_notes: true |
| 86 | + draft: false |
| 87 | + prerelease: false |
0 commit comments