Release snapshot fix/flatten-pom by @bplessis-swi #8
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 Library | |
| run-name: Release ${{ github.ref_name != github.event.repository.default_branch && 'snapshot ' || '' }}${{ github.ref_name }} by @${{ github.actor }} | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_bump: | |
| description: 'Version bump type - only for main branch' | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| default: patch | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| release: | |
| name: Build and Release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # required to get all tags | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Determine version | |
| id: version | |
| env: | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| CURRENT_BRANCH: ${{ github.ref_name }} | |
| run: | | |
| # Get the latest tag | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| echo "Latest tag: $LATEST_TAG" | |
| # Remove 'v' prefix if present | |
| LATEST_VERSION=${LATEST_TAG#v} | |
| echo "Latest version: $LATEST_VERSION" | |
| # Parse version components | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION" | |
| # Determine if we're on the default branch | |
| if [ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ]; then | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| BUMP_TYPE="${{ inputs.version_bump }}" | |
| else | |
| BUMP_TYPE="patch" | |
| fi | |
| case $BUMP_TYPE in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| ;; | |
| patch) | |
| PATCH=$((PATCH + 1)) | |
| ;; | |
| esac | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| IS_RELEASE=true | |
| else | |
| # Snapshot build - increment patch and add -SNAPSHOT | |
| PATCH=$((PATCH + 1)) | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-SNAPSHOT" | |
| IS_RELEASE=false | |
| fi | |
| echo "New version: $NEW_VERSION" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT | |
| echo "bump_type=${BUMP_TYPE:-none}" >> $GITHUB_OUTPUT | |
| - name: "Build and test (version: ${{ steps.version.outputs.version }})" | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| mvn clean verify -B -Drevision=$VERSION | |
| - name: Publish to GitHub Packages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_ACTOR: ${{ github.actor }} | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| mvn deploy -DskipTests -B -Drevision=$VERSION | |
| - name: Create and push tag (release only) | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| if: steps.version.outputs.is_release == 'true' | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| git tag -a "v$VERSION" -m "Release version $VERSION" | |
| git push origin "v$VERSION" | |
| - name: Create GitHub Release (release only) | |
| if: steps.version.outputs.is_release == 'true' | |
| uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0 | |
| with: | |
| tag: v${{ steps.version.outputs.version }} | |
| name: Release ${{ steps.version.outputs.version }} | |
| body: | | |
| ## Release ${{ steps.version.outputs.version }} | |
| ### Changes | |
| This release was automatically generated. | |
| ### Maven Dependency | |
| ```xml | |
| <dependency> | |
| <groupId>net.airvantage</groupId> | |
| <artifactId>proxy-socket-core</artifactId> | |
| <version>${{ steps.version.outputs.version }}</version> | |
| </dependency> | |
| ``` | |
| ### GitHub Packages | |
| To use this library from GitHub Packages, add the following repository to your `pom.xml`: | |
| ```xml | |
| <repositories> | |
| <repository> | |
| <id>github</id> | |
| <url>https://maven.pkg.github.com/${{ github.repository }}</url> | |
| </repository> | |
| </repositories> | |
| ``` | |
| draft: false | |
| prerelease: false | |
| generateReleaseNotes: true | |
| - name: Summary | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| if: always() | |
| run: | | |
| echo "## Release Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version**: $VERSION" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Repository**: https://github.com/${{ github.repository }}/packages" >> $GITHUB_STEP_SUMMARY |