Update gradle.yml #33
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
# This workflow will build a Java project with Gradle | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | ||
name: Java CI with Gradle | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- early-adopter | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
if: !(github.event_name == 'pull_request' && github.head_ref == 'early-adopter' && github.base_ref == 'main') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 19 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'oracle' | ||
java-version: '19' | ||
cache: 'gradle' | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
- name: Build with Gradle | ||
run: ./gradlew build | ||
- name: Creating the jar file | ||
run: ./gradlew jar | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./releases/*.jar | ||
name: Downloadable Extension File | ||
- name: Get previous tag for the branch | ||
id: get_previous_tag | ||
run: | | ||
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | ||
PREFIX="main_" | ||
else | ||
PREFIX="early_adopter_" | ||
fi | ||
PREVIOUS_TAG=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
https://api.github.com/repos/${{ github.repository }}/git/refs/tags \ | ||
| jq -r ".[] | select(.ref | startswith(\"refs/tags/${PREFIX}\")) | .ref" \ | ||
| sort -V | tail -n 1 | sed "s|refs/tags/||") | ||
# Check if we found a tag | ||
if [[ -z "$PREVIOUS_TAG" ]]; then | ||
echo "No previous tag found for prefix ${PREFIX}." | ||
echo "PREVIOUS_TAG=" >> $GITHUB_ENV | ||
else | ||
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_ENV | ||
fi | ||
- name: Delete the previous tag | ||
if: env.PREVIOUS_TAG != '' | ||
run: | | ||
curl -X DELETE \ | ||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${{ env.PREVIOUS_TAG }}" | ||
- name: Extract new version | ||
id: get_version | ||
run: | | ||
VERSION=$(grep "^version=" src/main/resources/extension.properties | awk -F'=' '{print $2}') | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: Set release tag based on branch | ||
id: vars | ||
run: | | ||
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | ||
echo "RELEASE_TAG=main_${VERSION}" >> $GITHUB_ENV | ||
else | ||
echo "RELEASE_TAG=early_adopter_${VERSION}" >> $GITHUB_ENV | ||
fi | ||
- name: Release | ||
uses: irsdl/release-action@v1.13.0 | ||
with: | ||
tag: ${{ env.RELEASE_TAG }} | ||
body: "This jar file has been built by GitHub automatically." | ||
allowUpdates: true | ||
artifacts: "releases/*.jar" | ||
draft: false | ||
prerelease: false |