This file contains 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: Build and Realease | |
on: | |
push: | |
branches: | |
- master # Trigger workflow on pushes to the master branch | |
paths: | |
- 'build.gradle.kts' # Trigger workflow if build.gradle.kts is modified | |
jobs: | |
build-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Set up JDK 21 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
# Cache Gradle dependencies | |
- name: Cache Gradle | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# Verify if the version has changed | |
- name: Extract Version | |
id: extract_version | |
run: | | |
VERSION=$(grep -E 'version = "(.*)"' build.gradle.kts | sed -E 's/version = "(.*)"/\1/') | |
echo "Version: $VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Check if Version Changed | |
id: check_version | |
run: | | |
echo "Comparing version..." | |
echo "VERSION=${{ env.VERSION }}" | |
if [[ "${{ github.event.before }}" != "${{ github.sha }}" && "${{ env.VERSION }}" != *SNAPSHOT* ]]; then | |
echo "Version has changed. Proceeding to build and release." | |
else | |
echo "No version change or is a SNAPSHOT version. Skipping." | |
exit 1 | |
fi | |
# Build the plugin | |
- name: Build Plugin | |
run: ./gradlew clean build | |
# Upload build artifact for debugging | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: QuickSort-Build | |
path: build/libs/*.jar | |
# Create GitHub release | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: QuickSort ${{ env.VERSION }} | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Upload the compiled JAR to the release | |
- name: Upload JAR to Release | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: build/libs/QuickSort-${{ env.VERSION }}.jar | |
asset_name: QuickSort-${{ env.VERSION }}.jar | |
asset_content_type: application/java-archive |