chore: harmonize lint/format rules and auto-fix #4
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: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to release (e.g., 1.2.0)' | |
| required: true | |
| type: string | |
| create_tag: | |
| description: 'Create git tag' | |
| required: true | |
| type: boolean | |
| default: true | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| validate: | |
| name: Validate | |
| runs-on: macos-15 | |
| if: | | |
| github.event_name == 'workflow_dispatch' || | |
| startsWith(github.ref, 'refs/tags/v') || | |
| (github.event_name == 'push' && !contains(github.event.head_commit.message, '[skip release]') && !contains(github.event.head_commit.author.name, 'github-actions')) | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| previous_tag: ${{ steps.previous.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine Version | |
| id: version | |
| run: | | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| VERSION="${{ inputs.version }}" | |
| elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| else | |
| # Auto-increment: get latest tag and bump patch version | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| LATEST_VERSION="${LATEST_TAG#v}" | |
| # Parse semver | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION" | |
| PATCH=$((PATCH + 1)) | |
| VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| echo "Auto-incrementing from $LATEST_VERSION to $VERSION" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Releasing version: $VERSION" | |
| - name: Get Previous Tag | |
| id: previous | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT | |
| echo "Previous tag: $PREV_TAG" | |
| - name: Select Xcode | |
| run: sudo xcode-select -s /Applications/Xcode_26.1.1.app | |
| - name: Build | |
| run: swift build -c release | |
| - name: Run Tests | |
| run: swift test --parallel | |
| benchmarks: | |
| name: Run Benchmarks | |
| runs-on: macos-15 | |
| needs: validate | |
| outputs: | |
| benchmark_summary: ${{ steps.run.outputs.summary }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Select Xcode | |
| run: sudo xcode-select -s /Applications/Xcode_26.1.1.app | |
| - name: Run Benchmarks | |
| id: run | |
| run: | | |
| # Run benchmarks and capture output | |
| swift run -c release CSVCoderBenchmarks --iterations 3 2>&1 | tee benchmark_output.txt | |
| # Extract key metrics for release notes (first 100 lines of output) | |
| { | |
| echo 'summary<<EOF' | |
| head -100 benchmark_output.txt | |
| echo 'EOF' | |
| } >> $GITHUB_OUTPUT | |
| - name: Upload Benchmark Results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: benchmark-results | |
| path: benchmark_output.txt | |
| retention-days: 90 | |
| changelog: | |
| name: Generate Changelog | |
| runs-on: ubuntu-latest | |
| needs: validate | |
| outputs: | |
| changelog: ${{ steps.generate.outputs.changelog }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate Changelog | |
| id: generate | |
| run: | | |
| PREV_TAG="${{ needs.validate.outputs.previous_tag }}" | |
| VERSION="${{ needs.validate.outputs.version }}" | |
| echo "Generating changelog from $PREV_TAG to HEAD" | |
| # Generate changelog | |
| { | |
| echo 'changelog<<EOF' | |
| echo "## What's Changed in v$VERSION" | |
| echo "" | |
| if [[ -n "$PREV_TAG" ]]; then | |
| # Categorize commits | |
| echo "### Features" | |
| git log $PREV_TAG..HEAD --pretty=format:"- %s" --grep="^feat" --grep="^add" --extended-regexp -i | head -20 || true | |
| echo "" | |
| echo "### Bug Fixes" | |
| git log $PREV_TAG..HEAD --pretty=format:"- %s" --grep="^fix" -i | head -20 || true | |
| echo "" | |
| echo "### Performance" | |
| git log $PREV_TAG..HEAD --pretty=format:"- %s" --grep="^perf" --grep="benchmark" -i | head -20 || true | |
| echo "" | |
| echo "### Other Changes" | |
| git log $PREV_TAG..HEAD --pretty=format:"- %s" | grep -v -i -E "^- (feat|fix|perf)" | head -20 || true | |
| echo "" | |
| echo "### Commits" | |
| echo "" | |
| git log $PREV_TAG..HEAD --pretty=format:"- %h %s (%an)" | head -50 | |
| else | |
| echo "Initial release" | |
| echo "" | |
| git log --pretty=format:"- %h %s (%an)" | head -50 | |
| fi | |
| echo "" | |
| echo 'EOF' | |
| } >> $GITHUB_OUTPUT | |
| create-release: | |
| name: Create Release | |
| runs-on: macos-15 | |
| needs: [validate, benchmarks, changelog] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download Benchmark Results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: benchmark-results | |
| - name: Create Tag | |
| if: | | |
| (github.event_name == 'workflow_dispatch' && inputs.create_tag) || | |
| (github.event_name == 'push' && github.ref == 'refs/heads/main') | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "v${{ needs.validate.outputs.version }}" -m "Release v${{ needs.validate.outputs.version }}" | |
| git push origin "v${{ needs.validate.outputs.version }}" | |
| - name: Prepare Release Notes | |
| id: notes | |
| run: | | |
| VERSION="${{ needs.validate.outputs.version }}" | |
| cat > release_notes.md << 'RELEASE_EOF' | |
| # CSVCoder v${{ needs.validate.outputs.version }} | |
| ${{ needs.changelog.outputs.changelog }} | |
| --- | |
| ## Benchmark Results | |
| <details> | |
| <summary>Click to expand benchmark results</summary> | |
| ``` | |
| RELEASE_EOF | |
| cat benchmark_output.txt >> release_notes.md | |
| cat >> release_notes.md << 'RELEASE_EOF' | |
| ``` | |
| </details> | |
| --- | |
| ## Installation | |
| ### Swift Package Manager | |
| ```swift | |
| dependencies: [ | |
| .package(url: "https://github.com/g-cqd/CSVCoder.git", from: "${{ needs.validate.outputs.version }}") | |
| ] | |
| ``` | |
| RELEASE_EOF | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.validate.outputs.version }} | |
| name: CSVCoder v${{ needs.validate.outputs.version }} | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: ${{ contains(needs.validate.outputs.version, 'alpha') || contains(needs.validate.outputs.version, 'beta') || contains(needs.validate.outputs.version, 'rc') }} | |
| files: | | |
| benchmark_output.txt | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |