diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..3cf4205 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions workflows + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "ci" + labels: + - "dependencies" + - "github-actions" + + # Maintain dependencies for Gradle (build.gradle.kts, libs.versions.toml) + - package-ecosystem: "gradle" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "build" + labels: + - "dependencies" + - "gradle" diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 0000000..21163ab --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,57 @@ +name: Build Pull Request + +on: + pull_request: + branches: + - "**" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Git Repository + uses: actions/checkout@v7 + + - name: Set Up JDK + uses: actions/setup-java@v5 + with: + distribution: zulu + java-version: 25 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + with: + add-job-summary: never + cache-read-only: true + + - name: Configure Git User Details + run: | + git config --global user.email "ci-test@monnairealms.moe" + git config --global user.name "Camellia Test CI" + + - name: Grant Execute Permission + run: chmod +x gradlew + + - name: Apply Patches + run: ./gradlew applyAllPatches --stacktrace + + - name: Build + run: ./gradlew createPaperclipJar --stacktrace + + - name: Rename Artifact + run: | + prop() { + awk -F= -v key="$1" '$1 == key { val = $2; sub(/[[:space:]]*#.*$/, "", val); gsub(/^[[:space:]]+|[[:space:]]+$/, "", val); print val }' gradle.properties + } + + jarName="camellia-$(prop mcVersion).jar" + mv camellia-server/build/libs/camellia-paperclip-"$(prop version)"*.jar "$jarName" 2>/dev/null || \ + mv camellia-server/build/libs/*-paperclip-*.jar "$jarName" 2>/dev/null || true + echo "jar=$jarName" >> "$GITHUB_ENV" + + - name: Upload Artifact + uses: actions/upload-artifact@v7 + with: + name: ${{ env.jar || 'camellia-pr' }} + path: ${{ env.jar || 'camellia-server/build/libs/*-paperclip-*.jar' }} + if-no-files-found: warn diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ad2e74b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,219 @@ +name: Camellia CI + +on: + push: + branches: + - "**" + workflow_dispatch: + inputs: + force-release: + description: "Force disable release if you enter false, force release if you enter true, default release if not released else skip release" + required: false + default: "" + force-push: + description: "Force disable push to repo if you enter false, force push to repo if you enter true, default push if not released else skip push repo" + required: false + default: "" + comments: + description: "Add comments to release" + required: false + default: "" + +permissions: write-all + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Git Repository + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Get Branch Build Number + run: | + BUILD_NUMBER=$(git rev-list --count HEAD) + echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV + echo "Branch: $GITHUB_REF_NAME — Build #$BUILD_NUMBER" + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v6 + + - name: Set Up JDK + uses: actions/setup-java@v5 + with: + distribution: zulu + java-version: 25 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + with: + add-job-summary: never + cache-read-only: false + + - name: Configure Git User Details + run: git config --global user.email "ci@monnairealms.moe" && git config --global user.name "Camellia CI" + + - name: Grant Execute Permission + run: chmod +x gradlew + + - name: Apply Patches + run: ./gradlew applyAllPatches --stacktrace + + - name: Build + run: ./gradlew createPaperclipJar --stacktrace + + - name: Set Environment + run: sh scripts/SetENV.sh + + - name: Get Build Info + id: build-info + run: | + BUILD_DATE=$(date -u +'%Y-%m-%d %H:%M:%S UTC') + echo "build_date=$BUILD_DATE" >> $GITHUB_ENV + + - name: Upload Artifact + uses: actions/upload-artifact@v7 + with: + name: ${{ env.project_id_b || 'Camellia' }} CI Artifacts + path: ${{ env.jar_dir }} + if-no-files-found: warn + + # ── Publish To Repo ── + - name: "[Publish] Publish To Repo" + if: | + ( env.flag_push_repo == 'true' + && !( inputs.force-push == 'false' ) + ) || inputs.force-push == 'true' + continue-on-error: true + run: ./gradlew generateDevelopmentBundle publish -PpublishDevBundle=true + env: + MAVEN_REPO_PASSWORD: ${{ secrets.MAVEN_REPO_PASSWORD }} + MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }} + + # ── Release ── + - name: Check If Release Exists + if: env.flag_release == 'true' + run: | + git fetch --tags + if [ -n "$(git tag -l "${{ env.tag }}")" ]; then + echo "Release already exists" + release_exists=true + else + echo "Release does not exist" + release_exists=false + fi + if [ "$release_exists" == "true" ]; then + counter=1 + while [ -n "$(git tag -l "${{ env.tag }}-${counter}")" ]; do + counter=$((counter + 1)) + done + echo "tag=${{ env.tag }}-${counter}" >> $GITHUB_ENV + echo "release_count= - ${counter}" >> $GITHUB_ENV + release_exists=false + fi + echo "release_exists=${release_exists}" >> $GITHUB_ENV + + - name: Check If Branch In Expectations + if: env.flag_release == 'true' + run: | + if [[ "$GITHUB_REF_NAME" == ver/* ]] || [[ "$GITHUB_REF_NAME" == exp/* ]] || [[ "$GITHUB_REF_NAME" == dev/* ]]; then + echo "Branch is in expected prefixes" + echo "unexpect=false" >> $GITHUB_ENV + else + echo "Branch is NOT in expected prefixes" + echo "unexpect=true" >> $GITHUB_ENV + fi + + - name: Create Release - Pre Process + if: | + ( !( env.unexpect == 'true' ) + && env.flag_release == 'true' + && env.release_exists != 'true' + && !(inputs.force-release == 'false') + ) || inputs.force-release == 'true' + run: | + if [ "${{ inputs.comments }}" == "" ]; then + echo "No comments provided" + echo "flag_comment=false" >> $GITHUB_ENV + else + echo "Comments provided: ${{ inputs.comments }}" + echo "flag_comment=true" >> $GITHUB_ENV + fi + + - name: Create Release - No Comment + if: env.flag_comment == 'false' + uses: ncipollo/release-action@v1 + with: + tag: ${{ env.tag }} + name: ${{ env.project_id_b }} ${{ env.mcversion }} - ${{ env.commit_id }}${{ env.release_count }} + body: | + # 🌸 Camellia `${{ env.mcversion }}` + + [![Download](https://img.shields.io/github/downloads/${{ github.repository }}/${{ env.tag }}/total?color=f472b6&style=for-the-badge&logo=github)](https://github.com/${{ github.repository }}/releases/download/${{ env.tag }}/${{ env.jar }}) + + ### 📝 Build Information + * **Build:** `#${{ env.BUILD_NUMBER }}` + * **Date:** `${{ env.build_date }}` + * **Branch:** [`${{ github.ref_name }}`](https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}) + * **Commit:** [`${{ env.commit_id }}`](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) + + ### ✨ Latest Changes + ```text + ${{ env.commit_msg }} + ``` + + --- +
+ Automated release by Camellia CI +
+ artifacts: ${{ env.jar_dir }} + generateReleaseNotes: true + prerelease: ${{ env.pre }} + makeLatest: ${{ env.make_latest }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release - With Comment + if: env.flag_comment == 'true' + uses: ncipollo/release-action@v1 + with: + tag: ${{ env.tag }} + name: ${{ env.project_id_b }} ${{ env.mcversion }} - ${{ env.commit_id }}${{ env.release_count }} + body: | + # 🌸 Camellia `${{ env.mcversion }}` + + [![Download](https://img.shields.io/github/downloads/${{ github.repository }}/${{ env.tag }}/total?color=f472b6&style=for-the-badge&logo=github)](https://github.com/${{ github.repository }}/releases/download/${{ env.tag }}/${{ env.jar }}) + + > **💡 Note:** ${{ inputs.comments }} + + ### 📝 Build Information + * **Build:** `#${{ env.BUILD_NUMBER }}` + * **Date:** `${{ env.build_date }}` + * **Branch:** [`${{ github.ref_name }}`](https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}) + * **Commit:** [`${{ env.commit_id }}`](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) + + ### ✨ Latest Changes + ```text + ${{ env.commit_msg }} + ``` + + --- +
+ Automated release by Camellia CI +
+ artifacts: ${{ env.jar_dir }} + generateReleaseNotes: true + prerelease: ${{ env.pre }} + makeLatest: ${{ env.make_latest }} + token: ${{ secrets.GITHUB_TOKEN }} + + event_file: + name: "Event File" + if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }} + runs-on: ubuntu-latest + steps: + - name: Upload + uses: actions/upload-artifact@v7 + with: + name: Event File + path: ${{ github.event_path }} diff --git a/.github/workflows/publish-api.yml b/.github/workflows/publish-api.yml new file mode 100644 index 0000000..ba59461 --- /dev/null +++ b/.github/workflows/publish-api.yml @@ -0,0 +1,50 @@ +name: Publish API + +on: + push: + branches: + - "**" + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout Git Repository + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Get Branch Build Number + run: | + BUILD_NUMBER=$(git rev-list --count HEAD) + echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV + + - name: Set Up JDK + uses: actions/setup-java@v5 + with: + distribution: zulu + java-version: 25 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Configure Git User Details + run: | + git config --global user.email "ci@monnairealms.moe" + git config --global user.name "Camellia CI" + + - name: Grant Execute Permission + run: chmod +x gradlew + + - name: Apply Patches + run: ./gradlew applyAllPatches --stacktrace + + - name: Publish API to Maven + continue-on-error: true + run: | + ./gradlew :camellia-api:publish + ./gradlew generateDevelopmentBundle publishDevBundlePublicationToBacteriawaRepository -PpublishDevBundle=true + env: + MAVEN_REPO_PASSWORD: ${{ secrets.MAVEN_REPO_PASSWORD }} + MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }} diff --git a/scripts/SetENV.sh b/scripts/SetENV.sh new file mode 100644 index 0000000..8c95c4d --- /dev/null +++ b/scripts/SetENV.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# Camellia CI - Environment Setup Script +# Reads gradle.properties and sets GitHub Actions environment variables + +prop() { + grep "^[[:space:]]*${1}" gradle.properties | cut -d'=' -f2 | sed 's/^[[:space:]]*//; s/\r//' +} + +project_id="camellia" +project_id_b="Camellia" + +commitid=$(git log --pretty='%h' -1) +mcversion=$(prop mcVersion) +release=$(prop release) +pushRepo=$(prop pushRepo) +release_tag="$mcversion-$commitid" +run_attempt="${GITHUB_RUN_ATTEMPT:-1}" +jarName="$project_id-$mcversion-$BUILD_NUMBER-$run_attempt.jar" +jarName_dir="camellia-server/build/libs/$jarName" + +flag_push_repo=false +flag_release=false +pre=false +make_latest=false + +if [ "$release" = "pre" ]; then + pre=true + flag_release=true + make_latest=true + flag_push_repo=true +elif [ "$release" = "true" ]; then + flag_release=true + make_latest=true + flag_push_repo=true +fi + +if [ "$pushRepo" = "true" ]; then + flag_push_repo=true +elif [ "$pushRepo" = "false" ]; then + flag_push_repo=false +fi + +# Rename the paperclip jar to a standardized name +actual_jar=$(ls camellia-server/build/libs/*-paperclip-*.jar 2>/dev/null | head -n 1) +if [ -n "$actual_jar" ]; then + mv "$actual_jar" "$jarName_dir" +else + echo "Warning: No paperclip jar found to rename" +fi + +echo "project_id=$project_id" >> $GITHUB_ENV +echo "project_id_b=$project_id_b" >> $GITHUB_ENV +echo "commit_id=$commitid" >> $GITHUB_ENV +echo "commit_msg=$(git log --pretty='> [%h] %s' -1)" >> $GITHUB_ENV +echo "mcversion=$mcversion" >> $GITHUB_ENV +echo "pre=$pre" >> $GITHUB_ENV +echo "tag=$release_tag" >> $GITHUB_ENV +echo "jar=$jarName" >> $GITHUB_ENV +echo "jar_dir=$jarName_dir" >> $GITHUB_ENV +echo "flag_push_repo=$flag_push_repo" >> $GITHUB_ENV +echo "flag_release=$flag_release" >> $GITHUB_ENV +echo "make_latest=$make_latest" >> $GITHUB_ENV