Skip to content

Improve fabric dependency specificity #123

Improve fabric dependency specificity

Improve fabric dependency specificity #123

Workflow file for this run

name: Build and Version Update
permissions:
contents: write
on:
push:
branches:
- main
- merge
- dev
- fabric-experimental-gradle
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout main repository
uses: actions/checkout@v2
# 2. Install JDK 21 – NO Gradle cache here
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: '' # ← disable Maven/Gradle cache
# 3. Set up Gradle + dependency cache
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v5
- name: Generate build number
id: buildnumber
uses: einaregilsson/build-number@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update version in build.gradle.kts
id: update_version
run: |
# Read current fullVersion from build.gradle.kts
FULL_VERSION=$(grep 'val fullVersion =' build.gradle.kts | awk -F '"' '{print $2}')
IFS='.' read -ra VERSION_PARTS <<< "$FULL_VERSION"
PATCH=$((VERSION_PARTS[2] + 1))
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$PATCH-dev-b${{ steps.buildnumber.outputs.build_number }}"
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
# Update fullVersion in build.gradle
sed -i "s/val fullVersion = \".*\"/val fullVersion = \"$NEW_VERSION\"/" build.gradle.kts
# Ensure snapshot is set to false
sed -i "s/val snapshot = .*/val snapshot = false/" build.gradle.kts
- name: Build without PE shaded
run: ./gradlew build -PshadePE=false -x test
env:
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Build with PE shaded Gradle
run: ./gradlew build -PshadePE=true -x test
env:
GITHUB_REPOSITORY: ${{ github.repository }}
# Get the Hashes of the Original and Lite JARs
- name: Calculate Hashes
run: |
# Calculate hash for the original JAR
BUKKIT_HASH=$(sha256sum bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar | awk '{print $1}')
echo "BUKKIT_HASH=$BUKKIT_HASH" >> $GITHUB_ENV
# Calculate hash for the lite JAR
BUKKIT_LITE_HASH=$(sha256sum bukkit/build/libs/knockbacksync-bukkit-lite-${{ env.NEW_VERSION }}.jar | awk '{print $1}')
echo "BUKKIT_LITE_HASH=$BUKKIT_LITE_HASH" >> $GITHUB_ENV
# Calculate hash for the lite JAR
FABRIC_HASH=$(sha256sum fabric/build/libs/knockbacksync-fabric-${{ env.NEW_VERSION }}.jar | awk '{print $1}')
echo "FABRIC_HASH=$FABRIC_HASH" >> $GITHUB_ENV
# Download, update, and re-upload dev-builds.txt
- name: Update dev-builds.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Download the current dev-builds.txt
curl -L -o dev-builds.txt https://github.com/${{ github.repository }}/releases/latest/download/dev-builds.txt
# Create a copy of the original file
cp dev-builds.txt dev-builds.txt.original
# Ensure the file ends with a newline
sed -i -e '$a\' dev-builds.txt
# Function to add hash if it doesn't exist
add_hash_if_new() {
if ! grep -q "$1" dev-builds.txt; then
echo "$1" >> dev-builds.txt
fi
}
# Add new hashes if they don't exist
add_hash_if_new "${{ env.BUKKIT_HASH }}"
add_hash_if_new "${{ env.BUKKIT_LITE_HASH }}"
add_hash_if_new "${{ env.FABRIC_HASH }}"
# Check if the file has changed
if cmp -s dev-builds.txt dev-builds.txt.original; then
echo "No changes to dev-builds.txt, skipping upload."
else
echo "Changes detected in dev-builds.txt, uploading new version."
# Get the latest release ID
RELEASE_ID=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r .id)
# Delete the old dev-builds.txt asset
ASSET_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets" | \
jq -r '.[] | select(.name == "dev-builds.txt") | .id')
if [ ! -z "$ASSET_ID" ]; then
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/assets/$ASSET_ID"
fi
# Upload the new dev-builds.txt
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @dev-builds.txt \
"https://uploads.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=dev-builds.txt"
fi
# Clean up
rm dev-builds.txt.original
- name: Upload Bukkit Artifact
uses: actions/upload-artifact@v4
with:
name: knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar
path: bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar
retention-days: 90
- name: Upload Bukkit Lite Artifact
uses: actions/upload-artifact@v4
with:
name: knockbacksync-bukkit-lite-${{ env.NEW_VERSION }}.jar
path: bukkit/build/libs/knockbacksync-bukkit-lite-${{ env.NEW_VERSION }}.jar
retention-days: 90
- name: Upload Fabric Artifact
uses: actions/upload-artifact@v4
with:
name: knockbacksync-fabric-${{ env.NEW_VERSION }}.jar
path: fabric/build/libs/knockbacksync-fabric-${{ env.NEW_VERSION }}.jar
retention-days: 90
- uses: Kir-Antipov/[email protected]
with:
modrinth-id: ${{ vars.MODRINTH_ID }}
modrinth-featured: true
modrinth-unfeature-mode: subset
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
files: |
bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar
bukkit/build/libs/knockbacksync-bukkit-lite-${{ env.NEW_VERSION }}.jar
name: KnockbackSync-${{ env.NEW_VERSION }}
version: ${{ env.NEW_VERSION }}
version-type: alpha
loaders: |
bukkit
spigot
paper
folia
purpur
game-versions: |
>=1.12.2
retry-attempts: 2
retry-delay: 10000
fail-mode: fail
- uses: Kir-Antipov/[email protected]
with:
modrinth-id: ${{ vars.MODRINTH_ID }}
modrinth-featured: true
modrinth-unfeature-mode: subset
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
files: |
fabric/build/libs/knockbacksync-fabric-${{ env.NEW_VERSION }}.jar
name: KnockbackSync-${{ env.NEW_VERSION }}
version: ${{ env.NEW_VERSION }}
version-type: alpha
loaders: |
fabric
game-versions: |
1.21.5
1.21.6
1.21.7
1.21.8
1.21.9
1.21.10
dependencies: |
fabric-api
retry-attempts: 2
retry-delay: 10000
fail-mode: fail