|
| 1 | +name: Build and Release ShadowJar |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-and-release: |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Set up Java 11 |
| 19 | + uses: actions/setup-java@v3 |
| 20 | + with: |
| 21 | + distribution: 'temurin' |
| 22 | + java-version: '11' |
| 23 | + |
| 24 | + - name: Extract version |
| 25 | + id: get_version |
| 26 | + run: | |
| 27 | + VERSION=$(grep -E "^version\s+['\"]" build.gradle | head -n 1 | sed -E "s/version\s+['\"]([^'\"]+)['\"]/\1/") |
| 28 | + echo "Found version: $VERSION" |
| 29 | + echo "::set-output name=VERSION::$VERSION" |
| 30 | +
|
| 31 | + - name: Check if version is new |
| 32 | + id: version_check |
| 33 | + run: | |
| 34 | + CURRENT_VERSION=${{ steps.get_version.outputs.VERSION }} |
| 35 | + echo "Current version: $CURRENT_VERSION" |
| 36 | + if git rev-parse "refs/tags/${CURRENT_VERSION}" >/dev/null 2>&1; then |
| 37 | + echo "Tag ${CURRENT_VERSION} already exists. Skipping release." |
| 38 | + echo "::set-output name=new_version::false" |
| 39 | + else |
| 40 | + echo "Tag ${CURRENT_VERSION} does not exist. Proceeding with release." |
| 41 | + echo "::set-output name=new_version::true" |
| 42 | + fi |
| 43 | + - name: Grant execute permission for Gradle wrapper |
| 44 | + run: chmod +x gradlew |
| 45 | + |
| 46 | + - name: Build shadowJar |
| 47 | + if: steps.version_check.outputs.new_version == 'true' |
| 48 | + run: ./gradlew shadowJar |
| 49 | + |
| 50 | + - name: Create Release |
| 51 | + if: steps.version_check.outputs.new_version == 'true' |
| 52 | + id: create_release |
| 53 | + uses: ncipollo/release-action@v1 |
| 54 | + with: |
| 55 | + tag: ${{ steps.get_version.outputs.VERSION }} |
| 56 | + name: Release ${{ steps.get_version.outputs.VERSION }} |
| 57 | + generateReleaseNotes: true |
| 58 | + |
| 59 | + - name: Upload artifact to release |
| 60 | + if: steps.version_check.outputs.new_version == 'true' |
| 61 | + uses: softprops/action-gh-release@v1 |
| 62 | + with: |
| 63 | + tag_name: ${{ steps.get_version.outputs.VERSION }} |
| 64 | + files: build/libs/*-all.jar |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments