72 lines
2.0 KiB
YAML
72 lines
2.0 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "rebuild-develop" # develop分支
|
|
- "rebuild-release" # release 分支
|
|
tags:
|
|
- 'build-*' # 打 tag 时跑 build + release
|
|
workflow_dispatch: # 允许手动触发
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
distribution: temurin
|
|
java-version: 17
|
|
|
|
- name: Grant execute permission for Gradlew
|
|
run: chmod +x gradlew
|
|
|
|
- name: Build with Gradle
|
|
run: ./gradlew clean build
|
|
|
|
- name: Upload each jar separately
|
|
run: |
|
|
for file in $(find . -name "*.jar" -path "*/build/libs/*"); do
|
|
echo "Uploading $file"
|
|
artifact_name=$(basename "$file" .jar)
|
|
gh release upload "${GITHUB_REF_NAME}" "$file" --repo "${GITHUB_REPOSITORY}" --clobber
|
|
done
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
release:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
if: startsWith(github.ref, 'refs/tags/build-') # 只有打 tag 才执行 release
|
|
steps:
|
|
- name: Download build artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: my-build
|
|
path: ./build-artifacts
|
|
|
|
- name: Create GitHub Release
|
|
id: create_release
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
tag_name: ${{ github.ref_name }}
|
|
name: Release ${{ github.ref_name }}
|
|
body: |
|
|
自动发布所有子项目构建产物。
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Upload jars to Release separately
|
|
run: |
|
|
for file in ./build-artifacts/**/*.jar; do
|
|
echo "Uploading $file"
|
|
gh release upload "${GITHUB_REF_NAME}" "$file" --repo "${GITHUB_REPOSITORY}" --clobber
|
|
done
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|