|
| 1 | +name: Publish to Maven |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, main, develop ] |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +jobs: |
| 10 | + publish: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Set up JDK 21 |
| 20 | + uses: actions/setup-java@v4 |
| 21 | + with: |
| 22 | + java-version: '21' |
| 23 | + distribution: 'temurin' |
| 24 | + cache: gradle |
| 25 | + |
| 26 | + - name: Grant execute permission for gradlew |
| 27 | + run: chmod +x gradlew |
| 28 | + |
| 29 | + - name: Determine version and repository |
| 30 | + id: version |
| 31 | + run: | |
| 32 | + if [ "${{ github.event_name }}" == "release" ]; then |
| 33 | + # This is a GitHub release - publish as release version |
| 34 | + VERSION="${{ github.event.release.tag_name }}" |
| 35 | + # Remove 'v' prefix if present |
| 36 | + VERSION="${VERSION#v}" |
| 37 | + REPO_TYPE="releases" |
| 38 | + echo "is_snapshot=false" >> $GITHUB_OUTPUT |
| 39 | + echo "Publishing release version: $VERSION" |
| 40 | + else |
| 41 | + # This is a regular commit - publish as snapshot |
| 42 | + # Get base version from gradle.properties |
| 43 | + BASE_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d ' ') |
| 44 | + # Remove -SNAPSHOT suffix if present |
| 45 | + BASE_VERSION="${BASE_VERSION%-SNAPSHOT}" |
| 46 | +
|
| 47 | + # Get current Minecraft version from gradle.properties |
| 48 | + MC_VERSION=$(grep "minecraft_version" gradle.properties | cut -d'=' -f2 | tr -d ' ') |
| 49 | +
|
| 50 | + # Get short commit hash |
| 51 | + COMMIT_HASH=$(git rev-parse --short HEAD) |
| 52 | +
|
| 53 | + # Get commit count for this branch |
| 54 | + COMMIT_COUNT=$(git rev-list --count HEAD) |
| 55 | +
|
| 56 | + # Build snapshot version: base+mcVersion-SNAPSHOT |
| 57 | + VERSION="${BASE_VERSION}+${MC_VERSION}-SNAPSHOT" |
| 58 | + REPO_TYPE="snapshots" |
| 59 | + echo "is_snapshot=true" >> $GITHUB_OUTPUT |
| 60 | + echo "Publishing snapshot version: $VERSION (commit: $COMMIT_HASH, build: $COMMIT_COUNT)" |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 64 | + echo "repo_type=$REPO_TYPE" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Update version in gradle.properties |
| 67 | + run: | |
| 68 | + sed -i "s/mod_version = .*/mod_version = ${{ steps.version.outputs.version }}/" gradle.properties |
| 69 | +
|
| 70 | + - name: Build with Gradle |
| 71 | + run: ./gradlew build |
| 72 | + |
| 73 | + - name: Publish to Maven Repository |
| 74 | + env: |
| 75 | + MAVEN_URL: ${{ secrets.MAVEN_URL }} |
| 76 | + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} |
| 77 | + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
| 78 | + run: | |
| 79 | + # Append repository type to maven URL if not already present |
| 80 | + if [[ ! "$MAVEN_URL" == */${{ steps.version.outputs.repo_type }} ]]; then |
| 81 | + export MAVEN_URL="${MAVEN_URL}/${{ steps.version.outputs.repo_type }}" |
| 82 | + fi |
| 83 | +
|
| 84 | + echo "Publishing to ${{ steps.version.outputs.repo_type }} repository: $MAVEN_URL" |
| 85 | + ./gradlew publish |
| 86 | +
|
| 87 | + - name: Upload build artifacts |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: Lambda-Loader-${{ steps.version.outputs.version }} |
| 91 | + path: build/libs/*.jar |
| 92 | + if-no-files-found: error |
0 commit comments