Create and Publish Release #14
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: Create and Publish Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "The version to release (e.g., 1.0.0)" | |
| required: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| # We need the full history to properly create commits and tags | |
| fetch-depth: 0 | |
| # Add token for authentication | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Configure the remote URL with the token | |
| git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "21" | |
| distribution: "temurin" | |
| cache: maven | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Install conventional-changelog | |
| run: yarn global add conventional-changelog-cli | |
| - name: Update version in pom.xml files | |
| run: mvn versions:set -DnewVersion=${{ github.event.inputs.version }} -DprocessAllModules=true | |
| - name: Build with Maven | |
| run: mvn -B package --file pom.xml | |
| - name: Commit version bump | |
| run: | | |
| git add . | |
| git commit -m "chore(release): prepare for release ${{ github.event.inputs.version }}" | |
| - name: Create and Push Tag | |
| run: | | |
| git tag "v${{ github.event.inputs.version }}" | |
| git push origin "v${{ github.event.inputs.version }}" | |
| - name: Push version bump commit | |
| run: git push | |
| - name: Generate changelog | |
| run: | | |
| # Get current date in YYYY-MM-DD format | |
| RELEASE_DATE=$(date +%Y-%m-%d) | |
| # Create a temporary file for the new changelog | |
| echo "# Changelog" > CHANGELOG.new.md | |
| echo "" >> CHANGELOG.new.md | |
| echo "All notable changes to this project will be documented in this file." >> CHANGELOG.new.md | |
| echo "" >> CHANGELOG.new.md | |
| echo "The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)," >> CHANGELOG.new.md | |
| echo "and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)." >> CHANGELOG.new.md | |
| echo "" >> CHANGELOG.new.md | |
| # Generate changelog for the latest release only | |
| conventional-changelog -p angular -i CHANGELOG.new.md -s -r 1 --output-unreleased=false | |
| # Extract the latest release section (everything between the first two ## headers) | |
| LATEST_RELEASE=$(sed -n '/^## /,/^## /p' CHANGELOG.new.md | sed '$d') | |
| # If CHANGELOG.md exists, prepend the new release to it | |
| if [ -f CHANGELOG.md ]; then | |
| # Create a new file with the latest release at the top | |
| echo "$LATEST_RELEASE" > CHANGELOG.md.new | |
| echo "" >> CHANGELOG.md.new | |
| # Append the rest of the existing changelog | |
| sed -n '/^## /,$p' CHANGELOG.md >> CHANGELOG.md.new | |
| # Replace the old changelog with the new one | |
| mv CHANGELOG.md.new CHANGELOG.md | |
| else | |
| # If no existing changelog, just use the new one | |
| mv CHANGELOG.new.md CHANGELOG.md | |
| fi | |
| # Commit the changes | |
| git add CHANGELOG.md | |
| git commit -m "chore: update changelog for ${{ github.event.inputs.version }}" | |
| git push | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: "v${{ github.event.inputs.version }}" | |
| name: "Release ${{ github.event.inputs.version }}" | |
| body_path: CHANGELOG.md | |
| fail_on_unmatched_files: true | |
| files: | | |
| pattern-tracker/target/PatternTracker.bwextension | |
| midi-splitter/target/MidiSplitter.bwextension | |
| step-recorder/target/StepRecorder.bwextension |