diff --git a/.github/workflows/blockchain_sdk_release.yml b/.github/workflows/blockchain_sdk_release.yml new file mode 100644 index 0000000..a876c7e --- /dev/null +++ b/.github/workflows/blockchain_sdk_release.yml @@ -0,0 +1,89 @@ +name: Build and Upload JAR to GitHub Releases + +on: + pull_request: + branches: + - main + types: [closed] + +jobs: + build: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/QA-') + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + repository-projects: write + + defaults: + run: + working-directory: source/did-blockchain-sdk-server + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build JAR + run: | + gradle build + echo "JAR file generated at:" + find ./build/libs -name "*.jar" + + - name: Set release title + id: set_release_title + run: | + release_tag=${GITHUB_HEAD_REF#release/QA-} + echo "Release tag: $release_tag" + echo "::set-output name=release_tag::$release_tag" + + - name: Get commit messages + id: get_commit_messages + run: | + commits=$(git log ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} --pretty=format:"* %s") + echo "$commits" > commit_messages.txt + echo "::set-output name=commits::$commits" + + - name: Find JAR file + id: find_jar + run: | + jar_path=$(find ./build/libs -name "*.jar" | head -n 1) + echo "JAR path found: $jar_path" + echo "::set-output name=jar_path::$jar_path" + + - name: Calculate SHA-256 + id: calculate_sha + run: | + sha256=$(sha256sum ${{ env.jar_path }} | awk '{ print $1 }') + echo "SHA-256: $sha256" + echo "::set-output name=jar_sha256::$sha256" + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.set_release_title.outputs.release_tag }} + release_name: ${{ steps.set_release_title.outputs.release_tag }} + body: | + ## Changes: + ${{ steps.get_commit_messages.outputs.commits }} + ## Checksum: + SHA-256: ${{ steps.calculate_sha.outputs.jar_sha256 }} + + - name: Upload JAR + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: source/did-blockchain-sdk-server/${{ steps.find_jar.outputs.jar_path }} + asset_name: did-blockchain-sdk-server-${{ steps.set_release_title.outputs.release_tag }}.jar + asset_content_type: application/java-archive