Files
Shiroha/.github/workflows/build.yml
T
Bacteria ac5e37415a [ci skip]Skip workflows on pull_request events
Add job-level condition in build.yml and publish-api.yml to skip running the build and publish jobs when the GitHub event is a pull_request. This ensures these jobs only run for non-PR events (e.g., push, workflow_dispatch) and avoids executing them for pull request events.
2026-07-09 18:29:27 +08:00

221 lines
7.9 KiB
YAML

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:
if: github.event_name != 'pull_request'
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 }}
```
---
<div align="center">
<sub>Automated release by <a href="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}">Camellia CI</a></sub>
</div>
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 }}
```
---
<div align="center">
<sub>Automated release by <a href="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}">Camellia CI</a></sub>
</div>
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 }}