Skip to content

Commit

Permalink
Merge pull request #12 from simple-robot/dev/optimize-build
Browse files Browse the repository at this point in the history
优化构建和CI配置
  • Loading branch information
ForteScarlet authored Jul 17, 2024
2 parents 4247100 + 20c61a4 commit 013f55d
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 227 deletions.
107 changes: 43 additions & 64 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- v**

env:
JAVA_VERSION: 21
JAVA_DISTRIBUTION: zulu
GRADLE_VERSION: 8.5
IS_CI: true
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
Expand All @@ -14,57 +17,71 @@ env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GRADLE_OPTS: "-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"

SIMBOT_IS_SNAPSHOT: false
SIMBOT_RELEASES_ONLY: true

jobs:
run-test-and-publish:
name: Run test and publish
run-test:
name: Run all tests
strategy:
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
# 检出仓库代码
- name: Check Out Repo
uses: actions/checkout@v4

- uses: actions/checkout@v4
# setup Java
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

# setup Gradle
- name: Gradle Run Test
# https://github.com/gradle/actions/blob/main/docs/setup-gradle.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.5
arguments: assemble test -Porg.gradle.daemon=false
gradle-version: ${{ env.GRADLE_VERSION }}

- name: Run all tests
run: gradle assemble allTests --stacktrace --warning-mode all

publish-release:
name: Publish release
needs: run-test
runs-on: macos-latest
steps:
# 检出仓库代码
- uses: actions/checkout@v4
# setup Java
- uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

# setup Gradle
- name: Publish Release
- name: Publish releases
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.5
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: |
publishToSonatype
closeAndReleaseStagingRepositories
publishToSonatype
closeAndReleaseStagingRepositories
--info
--warning-mode all
-x test
--build-cache
--warning-mode all
-x test
--build-cache
-Porg.gradle.jvmargs="-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"
env:
SIMBOT_IS_SNAPSHOT: false
SIMBOT_RELEASES_ONLY: true

create-release:
name: Create release
runs-on: ubuntu-latest
needs: run-test-and-publish
needs: publish-release
permissions:
contents: write
steps:
Expand All @@ -82,49 +99,10 @@ jobs:
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, 'preview') || contains(github.ref_name, 'alpha') }}

# || contains(github.ref_name, 'beta')

publish-snapshot:
name: Publish snapshot
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
needs: run-test-and-publish
steps:
# 检出仓库代码
- name: Check out repo
uses: actions/checkout@v4

# setup Java
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21

# setup Gradle
- name: Gradle publish snapshot
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.5
arguments: |
publishToSonatype
closeAndReleaseStagingRepositories
--info
--warning-mode all
-x test
--build-cache
-Porg.gradle.jvmargs="-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8"
-Porg.gradle.daemon=false
env:
SIMBOT_IS_SNAPSHOT: true
SIMBOT_SNAPSHOT_ONLY: true

deploy-doc:
name: Deploy-doc
runs-on: ubuntu-latest
needs: run-test-and-publish
needs: publish-release
steps:
# 检出仓库代码
- name: Check out repo
Expand All @@ -136,14 +114,15 @@ jobs:
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

# setup Gradle
- name: Gradle generate documentation
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.5
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: |
dokkaHtmlMultiModule
--info
Expand Down
51 changes: 42 additions & 9 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ on:
workflow_dispatch:

env:
JAVA_VERSION: 21
JAVA_DISTRIBUTION: zulu
GRADLE_VERSION: 8.5
IS_CI: true
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
Expand All @@ -35,12 +38,36 @@ env:


jobs:
publish-snapshot:
name: Publish snapshot
run-test:
name: Run all tests
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [ macos-latest, ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
# 检出仓库代码
- uses: actions/checkout@v4
# setup Java
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
# setup Gradle
# https://github.com/gradle/actions/blob/main/docs/setup-gradle.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}

- name: Run all tests
run: gradle assemble allTests --stacktrace --warning-mode all

publish-snapshot:
name: Publish snapshot
needs: run-test
runs-on: macos-latest
steps:
# 检出仓库代码
- name: Check out repo
Expand All @@ -50,14 +77,17 @@ jobs:
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

# setup Gradle
- uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}

- name: Gradle test and publish snapshot
run: gradle allTests publishToSonatype closeAndReleaseStagingRepositories --info --warning-mode all "-Porg.gradle.daemon=false" "-Porg.gradle.jvmargs='-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8'"
- name: Publish snapshots
run: gradle publishToSonatype closeAndReleaseStagingRepositories --info --warning-mode all -x test "-Porg.gradle.jvmargs='-Xmx8g -Xms2g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8'"

- name: Upload test reports
uses: actions/upload-artifact@v4
Expand All @@ -82,11 +112,14 @@ jobs:
- name: Setup java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'

# setup Gradle
- uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}

- run: gradle dokkaHtmlMultiModule "-Porg.gradle.jvmargs='-Xmx4g -Xms4g -XX:MaxMetaspaceSize=2g -Dfile.encoding=UTF-8'" "-Porg.gradle.daemon=false" "-DisSnapshot=false" --info --warning-mode all -x test --build-cache

Expand Down
11 changes: 4 additions & 7 deletions buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/

import love.forte.gradle.common.core.project.ProjectDetail
import love.forte.gradle.common.core.project.Version
import love.forte.gradle.common.core.project.minus
import love.forte.gradle.common.core.property.systemProp
import love.forte.gradle.common.core.project.version as v


/**
Expand All @@ -43,11 +40,11 @@ object P {
override val description: String get() = DESCRIPTION
override val homepage: String get() = HOMEPAGE

const val VERSION = "0.0.5"
const val NEXT_VERSION = "0.0.6"

private val baseVersion = v(0, 1, 0)

val snapshotVersion = baseVersion - Version.SNAPSHOT
override val version = if (isSnapshot()) snapshotVersion else baseVersion
override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
override val version = if (isSnapshot()) snapshotVersion else VERSION

override val developers: List<Developer> = developers {
developer {
Expand Down
88 changes: 0 additions & 88 deletions buildSrc/src/main/kotlin/simbot-telegram-maven-publish.gradle.kts

This file was deleted.

Loading

0 comments on commit 013f55d

Please sign in to comment.