fix release publishing #3
This file contains hidden or 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: Release on Modrinth | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build ShadowJars and Create Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: main | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'adopt' | |
| java-version: '21' | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| gradle-${{ runner.os }} | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Build ShadowJars | |
| run: ./gradlew clean build shadowJar | |
| - name: Get Gradle Version | |
| id: gradle_version | |
| run: echo "GRADLE_VERSION=$(./gradlew properties -q | grep "version:" | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Get Commit Hash | |
| id: commit_hash | |
| run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
| - name: Publish to Modrinth | |
| run: ./gradlew modrinth && ./gradlew modrinthSyncBody | |
| env: | |
| COMMIT_HASH: ${{ env.COMMIT_HASH }} | |
| MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| with: | |
| tag_name: v${{ env.GRADLE_VERSION }}-dev.${{ env.COMMIT_HASH }} | |
| release_name: v${{ env.GRADLE_VERSION }}-dev.${{ env.COMMIT_HASH }} | |
| draft: false | |
| prerelease: true | |
| commitish: main | |
| body: | | |
| This release contains dev builds for all Gradle modules. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload ShadowJars to Release | |
| run: | | |
| # Find JAR files in any submodule's build/libs directory | |
| for jar in $(find . -type f -name "*.jar" -path "*/build/libs/*.jar" -not -path "./build/libs/*"); do | |
| # Check if the filename contains a version number (e.g., a dash followed by numbers) | |
| if [[ $(basename "$jar") =~ -[0-9]+\.[0-9]+ ]]; then | |
| echo "Skipping $jar due to version number" | |
| else | |
| echo "Uploading $jar" | |
| gh release upload v${{ env.GRADLE_VERSION }}-dev.${{ env.COMMIT_HASH }} "$jar" | |
| fi | |
| done | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |