Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
name: Build MCExtension
name: Build & Publish MCExtension

on:
push:
branches: [ "master" ]
tags: [ "v*" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
# 1. Check out the code
- name: Checkout Code
uses: actions/checkout@v4

# 2. Set up Java 21
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

# 3. Grant execute permission & Fix Windows line endings
- name: Fix Gradlew Permissions
run: |
chmod +x gradlew
sed -i 's/\r$//' gradlew

# 4. Build with Gradle
- name: Build with Gradle
# 4a. Build (Test Only)
# Run this ONLY for Pull Requests.
- name: Build (Test Only)
if: ${{ github.event_name == 'pull_request' }}
run: ./gradlew clean build
env:
BUILD_NUMBER: ${{ github.run_number }}

# 5. Save the JARs
# 4b. Build & Publish (DEV)
# Run this for 'push to master' (creates -DEV builds)
- name: Publish Dev Build
if: ${{ (github.event_name == 'push' || github.event_name == 'pull_request') && !startsWith(github.ref, 'refs/tags/') }}
run: ./gradlew clean build publish
env:
BUILD_NUMBER: ${{ github.run_number }}
USER_GITHUB_NAME: ${{ github.actor }}
USER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# 4c. Build & Publish (RELEASE)
# Run this ONLY when a tag (v*) is pushed.
- name: Publish Release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./gradlew clean build publish
env:
# We pass the tag name (e.g., v2026.0.0) to Gradle
RELEASE_VERSION: ${{ github.ref_name }}
USER_GITHUB_NAME: ${{ github.actor }}
USER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/build_monthly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Monthly Version Update & Publish

on:
schedule:
- cron: '0 0 1 * *' # Run at 00:00 UTC on the 1st of every month
workflow_dispatch: # Allows manual testing

jobs:
monthly-release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Optional: Use the token here too if you want the checkout
# to be authenticated as the agent (helps with branch protection)
token: ${{ secrets.AGENT_TOKEN }}

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Fix Gradlew Permissions
run: |
chmod +x gradlew
sed -i 's/\r$//' gradlew

- name: Calculate New Version
id: versioning
run: |
YEAR=$(date +'%Y')
MONTH=$(date +'%m')
MONTH=$((10#$MONTH))
MAJOR=$((MONTH / 10))
MINOR=$((MONTH % 10))
NEW_VERSION="$YEAR.$MAJOR.$MINOR"

echo "Calculated Version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT

- name: Create Release Branch
run: |
VERSION=${{ steps.versioning.outputs.new_version }}
git checkout -b "release/$VERSION"
echo "Created branch release/$VERSION"

- name: Update gradle.properties
run: |
NEW_VERSION=${{ steps.versioning.outputs.new_version }}

# 1. Update Version (e.g., 2026.0.2)
sed -i "s/^project-version=.*/project-version=$NEW_VERSION/" gradle.properties

# 2. Reset Iteration to 1 (So next dev build starts at 1)
sed -i "s/^project-iteration=.*/project-iteration=1/" gradle.properties

# Verify
grep "project-version" gradle.properties
grep "project-iteration" gradle.properties

- name: Build and Publish Package
run: ./gradlew clean build publish
env:
RELEASE_VERSION: ${{ steps.versioning.outputs.new_version }}
# Force the uploader to be agent-mcengine
USER_GITHUB_NAME: "agent-mcengine"
USER_GITHUB_TOKEN: ${{ secrets.AGENT_TOKEN }}

- name: Push Branch
run: |
VERSION=${{ steps.versioning.outputs.new_version }}

# This sets the visible commit author
git config --global user.name "agent-mcengine"
git config --global user.email "mcengine.official.agt@outlook.com"

git add gradle.properties
git commit -m "chore: Release version $VERSION"

# Push using the authenticated user (from Checkout step or default)
git push origin "release/$VERSION"
21 changes: 14 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ plugins {
// --- DYNAMIC VERSIONING LOGIC ---
// 1. Detect Build Environment
String buildNum = System.getenv("BUILD_NUMBER")
String releaseTag = System.getenv("RELEASE_VERSION") // Passed from GitHub Actions
boolean isDevBuild = (buildNum != null && !buildNum.isEmpty())

// 2. Calculate the Version String IMMEDIATELY
String calculatedVersion = "unspecified"

// Check for the property defined in gradle.properties
if (project.hasProperty('project-version')) {
if (releaseTag != null && !releaseTag.isEmpty()) {
// RELEASE STRATEGY:
// If a tag exists (e.g., "v2026.0.0" or "v2026.0.0-1"), use it directly but strip the "v".
// Result: "2026.0.0" or "2026.0.0-1"
calculatedVersion = releaseTag.replace("v", "")
} else if (project.hasProperty('project-version')) {
// DEV STRATEGY:
def baseVersion = project.property('project-version')
def iteration = project.hasProperty('project-iteration') ? project.property('project-iteration') : "1"

if (isDevBuild) {
// CI Strategy: "2026.0.0-9-DEV"
calculatedVersion = "${baseVersion}-${buildNum}-DEV"
// CI Dev Build: "2026.0.0-1-9-DEV"
// Format: {Version}-{Iteration}-{BuildNum}-DEV
calculatedVersion = "${baseVersion}-${iteration}-${buildNum}-DEV"
} else {
// Local Strategy: "2026.0.0-SNAPSHOT"
// Appends SNAPSHOT locally to distinguish from release builds
calculatedVersion = "${baseVersion}-SNAPSHOT"
// Local Build: "2026.0.0-1-SNAPSHOT"
calculatedVersion = "${baseVersion}-${iteration}-SNAPSHOT"
}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ git-org-name=MCEngine
git-org-repository=mcextension

# --- Artifact Identity ---
project-version=2026.0.0
project-version=2026.0.2
project-iteration=1
project-group=io.github.mcengine
project-artifact-id=mcextension
project-artifact-name=MCExtension
Expand Down