Enhance GitHub release workflow with automatic release creation #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| jobs: | |
| create-release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.version.outputs.VERSION }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Swift | |
| uses: swift-actions/setup-swift@v2 | |
| with: | |
| swift-version: '6.1.2' | |
| - name: Run tests | |
| run: swift test | |
| - name: Build | |
| run: swift build -c release | |
| - name: Extract version from tag | |
| id: version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| - name: Extract changelog for this version | |
| id: changelog | |
| run: | | |
| VERSION="${{ steps.version.outputs.VERSION }}" | |
| # Extract changelog section for this version | |
| sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d' > release_notes.md | |
| # If empty, use a default message | |
| if [ ! -s release_notes.md ]; then | |
| echo "Release $VERSION" > release_notes.md | |
| echo "" >> release_notes.md | |
| echo "See [CHANGELOG.md](https://github.com/PinkQween/Math/blob/main/CHANGELOG.md) for details." >> release_notes.md | |
| fi | |
| # Add documentation link | |
| echo "" >> release_notes.md | |
| echo "---" >> release_notes.md | |
| echo "" >> release_notes.md | |
| echo "📚 **Documentation:** https://math.hannaskairipa.com" >> release_notes.md | |
| echo "" >> release_notes.md | |
| echo "## Installation" >> release_notes.md | |
| echo "" >> release_notes.md | |
| echo '```swift' >> release_notes.md | |
| echo 'dependencies: [' >> release_notes.md | |
| echo " .package(url: \"https://github.com/PinkQween/Math.git\", from: \"$VERSION\")" >> release_notes.md | |
| echo ']' >> release_notes.md | |
| echo '```' >> release_notes.md | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: "Math v${{ steps.version.outputs.VERSION }}" | |
| body_path: release_notes.md | |
| prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }} | |
| draft: false | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| test-installation: | |
| name: Test Installation | |
| needs: create-release | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - name: Setup Swift | |
| uses: swift-actions/setup-swift@v2 | |
| with: | |
| swift-version: '6.1.2' | |
| - name: Create test package | |
| run: | | |
| mkdir test-install | |
| cd test-install | |
| swift package init --type executable | |
| - name: Add Math dependency | |
| run: | | |
| cd test-install | |
| cat > Package.swift << 'EOF' | |
| // swift-tools-version: 6.1 | |
| import PackageDescription | |
| let package = Package( | |
| name: "test-install", | |
| dependencies: [ | |
| .package(url: "https://github.com/PinkQween/Math.git", from: "${{ needs.create-release.outputs.version }}") | |
| ], | |
| targets: [ | |
| .executableTarget(name: "test-install", dependencies: ["Math"]) | |
| ] | |
| ) | |
| EOF | |
| - name: Update and build | |
| run: | | |
| cd test-install | |
| swift package update | |
| swift build | |
| - name: Test basic functionality | |
| run: | | |
| cd test-install | |
| cat > Sources/main.swift << 'EOF' | |
| import Math | |
| let a: Math = 42 | |
| let b: Math = 17 | |
| print("42 + 17 = \(a + b)") | |
| print("42 is prime: \(a.isPrime)") | |
| print("17 is prime: \(b.isPrime)") | |
| EOF | |
| swift run |