diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..baa5b67 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: Create Release and Publish Artifacts + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v2 + + - name: Set up Java 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adoptopenjdk' + + - name: Cache Maven dependencies + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build with Maven + run: mvn clean install -DskipTests + + - name: Extract version from pom.xml + id: version + run: | + VERSION=$(xmlstarlet sel -t -m "/project/version" -v . pom.xml) + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Check if the version already exists + id: check_release + run: | + RELEASE_EXISTS=$(gh release view ${{ env.VERSION }} --json tagName --jq '.tagName' || echo "") + echo "Release exists: $RELEASE_EXISTS" + if [[ -n "$RELEASE_EXISTS" ]]; then + echo "Release already exists. Skipping..." + exit 0 + fi + + - name: Create GitHub Release + id: create_release + run: | + gh release create ${{ env.VERSION }} target/*.jar --title "Release ${{ env.VERSION }}" --notes "Release created automatically from GitHub Actions" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload JARs as artifacts + uses: actions/upload-artifact@v2 + with: + name: keycloak-admin-events-logger-artifacts + path: target/*.jar \ No newline at end of file