[build] Fix check-publishing actions

This commit is contained in:
Him188 2022-11-23 12:53:55 +00:00
parent 76cee371a9
commit a6af7e82ea
6 changed files with 59 additions and 148 deletions

View File

@ -16,77 +16,10 @@ on:
- '**/gradle.properties'
- 'buildSrc/**'
# 从 build.yml 复制的
jobs:
jvm-and-macos:
name: "JVM+macOS"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-12
env:
enableLocalPublishingTest: 'true'
gradleArgs: --scan
isMac: ${{ startsWith(matrix.os, 'macos') }}
isWindows: ${{ startsWith(matrix.os, 'windows') }}
isUbuntu: ${{ startsWith(matrix.os, 'ubuntu') }}
isUnix: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Cache konan
uses: pat-s/always-upload-cache@v3.0.11
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-
- if: ${{ env.isUnix == 'true' }}
run: chmod -R 777 *
# Prepare environment for linking for macOS
- if: ${{ env.isMac == 'true' }}
name: Install OpenSSL
run: >
git clone https://github.com/openssl/openssl.git --recursive &&
cd openssl &&
git checkout tags/openssl-3.0.3 &&
./Configure --prefix=/opt/openssl --openssldir=/usr/local/ssl &&
make &&
sudo make install
- name: Clean and download dependencies
run: ./gradlew clean ${{ env.gradleArgs }}
- name: Build and Publish Local Artifacts
if: ${{ env.enableLocalPublishingTest == 'true' }}
run: ./gradlew :mirai-deps-test:publishMiraiLocalArtifacts ${{ env.gradleArgs }} "-Dmirai.build.project.version=2.99.0-deps-test" "-Porg.gradle.parallel=${{ matrix.parallelCompilation }}"
- name: Check Publication
if: ${{ env.enableLocalPublishingTest == 'true' }}
run: ./gradlew :mirai-deps-test:check ${{ env.gradleArgs }} "-Dmirai.build.project.version=2.99.0-deps-test" "-Dmirai.deps.test.must.run=true"
native-platforms:
name: "Native (${{ matrix.os }})"
check-publishing:
name: "Check Publishing (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
@ -94,6 +27,7 @@ jobs:
os:
- windows-2022
- ubuntu-20.04
- macos-12
include:
- os: windows-2022
targetName: mingwX64
@ -107,8 +41,7 @@ jobs:
env:
# FIXME there must be two or more targets, or we'll get error on `@OptionalExpectation`
# > Declaration annotated with '@OptionalExpectation' can only be used in common module sources
enableLocalPublishingTest: 'true'
gradleArgs: --scan "-Dmirai.target=jvm;${{ matrix.targetName }};!other" "-Pkotlin.compiler.execution.strategy=in-process" "-Dorg.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8"
gradleArgs: --scan "-Dmirai.target=jvm;${{ matrix.targetName }};~others" "-Pkotlin.compiler.execution.strategy=in-process" "-Dorg.gradle.jvmargs=-Xmx4096m" "-Dfile.encoding=UTF-8"
isMac: ${{ startsWith(matrix.os, 'macos') }}
isWindows: ${{ startsWith(matrix.os, 'windows') }}
isUbuntu: ${{ startsWith(matrix.os, 'ubuntu') }}
@ -189,22 +122,11 @@ jobs:
- name: Clean and download dependencies
run: ./gradlew clean ${{ env.gradleArgs }}
- run: >
./gradlew updateSnapshotVersion ${{ env.gradleArgs }}
if: github.event.pusher
env:
MIRAI_IS_SNAPSHOTS_PUBLISHING: true
SNAPSHOTS_PUBLISHING_USER: ${{ secrets.SNAPSHOTS_PUBLISHING_USER }}
SNAPSHOTS_PUBLISHING_KEY: ${{ secrets.SNAPSHOTS_PUBLISHING_KEY }}
SNAPSHOTS_PUBLISHING_URL: ${{ secrets.SNAPSHOTS_PUBLISHING_URL }}
CURRENT_BRANCH_NAME: dev # always use -dev for now
- name: Prepare deps test build
run: ./gradlew :mirai-deps-test:updateProjectVersionForLocalDepsTest ${{ env.gradleArgs }} "-Porg.gradle.parallel=${{ matrix.parallelCompilation }}"
- name: Build and Publish Local Artifacts
if: ${{ env.enableLocalPublishingTest == 'true' }}
run: ./gradlew :mirai-deps-test:publishMiraiLocalArtifacts ${{ env.gradleArgs }} "-Dmirai.build.project.version=2.99.0-deps-test" "-Porg.gradle.parallel=${{ matrix.parallelCompilation }}"
run: ./gradlew :mirai-deps-test:publishMiraiArtifactsToMavenLocal ${{ env.gradleArgs }} "-Porg.gradle.parallel=${{ matrix.parallelCompilation }}"
- name: Check Publication
if: ${{ env.enableLocalPublishingTest == 'true' }}
run: ./gradlew :mirai-deps-test:check ${{ env.gradleArgs }} "-Dmirai.build.project.version=2.99.0-deps-test" "-Dmirai.deps.test.must.run=true"
run: ./gradlew :mirai-deps-test:check ${{ env.gradleArgs }} "-Dmirai.deps.test.must.run=true"

View File

@ -24,11 +24,12 @@ object Versions {
val project = System.getenv("mirai.build.project.version")?.takeIf { it.isNotBlank() }
?: System.getProperty("mirai.build.project.version")?.takeIf { it.isNotBlank() }
?: /*PROJECT_VERSION_START*/"2.14.0-dev-shadow-6"/*PROJECT_VERSION_END*/
// DO NOT ADD SPACE BETWEEN!
val core = project
val console = project
val consoleIntellij = "221-$project-171-2" // idea-mirai-kotlin-patch
val consoleTerminal = project
val core get() = project
val console get() = project
val consoleIntellij get() = "221-$project-171-2" // idea-mirai-kotlin-patch
val consoleTerminal get() = project
const val kotlinCompiler = "1.7.10"
const val kotlinStdlib = kotlinCompiler
@ -264,3 +265,20 @@ const val `maven-resolver-connector-basic` =
const val `maven-resolver-transport-http` =
"org.apache.maven.resolver:maven-resolver-transport-http:${Versions.mavenArtifactResolver}"
const val `maven-resolver-provider` = "org.apache.maven:maven-resolver-provider:${Versions.mavenResolverProvider}"
const val DEPS_TEST_VERSION = "2.99.0-deps-test"
/**
* This does not work for this build! Changes apply only in future builds.
*/
fun setProjectVersionForFutureBuilds(newVersion: String) {
rootProject.file("buildSrc/src/main/kotlin/Versions.kt").run {
var text = readText()
val template = { version: Any? -> "/*PROJECT_VERSION_START*/\"${version}\"/*PROJECT_VERSION_END*/" }
check(text.indexOf(template(Versions.project)) != -1) { "Cannot find ${template(Versions.project)}" }
text = text.replace(template(Versions.project), template(newVersion))
writeText(text)
}
}

View File

@ -1,10 +1,10 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
import keys.SecretKeys
import java.io.ByteArrayOutputStream
@ -26,13 +26,7 @@ tasks.register("updateSnapshotVersion") {
group = "mirai"
doLast {
rootProject.file("buildSrc/src/main/kotlin/Versions.kt").run {
var text = readText()
val template = { version: Any? -> "/*PROJECT_VERSION_START*/\"${version}\"/*PROJECT_VERSION_END*/" }
check(text.indexOf(template(project.version)) != -1) { "Cannot find ${template(project.version)}" }
text = text.replace(template(project.version), template(snapshotVersion))
writeText(text)
}
setProjectVersionForFutureBuilds(snapshotVersion)
}
}

View File

@ -10,7 +10,6 @@
package net.mamoe.mirai.console.gradle
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.RegisterExtension
@ -39,9 +38,11 @@ abstract class AbstractTest {
.forwardOutput()
.withEnvironment(System.getenv())
.withArguments(buildList {
addAll(arguments)
add("--no-daemon")
add("-Pkotlin.compiler.execution.strategy=in-process")
add("-Dorg.gradle.jvmargs=-Xmx256m -Dfile.encoding=UTF-8")
add("-Dorg.gradle.jvmargs=-Xmx256m")
add("-Dfile.encoding=UTF-8")
addAll(arguments)
})
.build()
}

View File

@ -43,6 +43,11 @@ val publishMiraiArtifactsToMavenLocal by tasks.registering {
}
dependsOn(publishTasks)
doFirst {
// Always print this very important message
logger.warn("[publishMiraiArtifactsToMavenLocal] Project version is '${project.version}'.")
}
doLast {
// delete shadowed Jars, since Kotlin can't compile modules that depend on them.
rootProject.subprojects
@ -54,6 +59,13 @@ val publishMiraiArtifactsToMavenLocal by tasks.registering {
}
}
tasks.register("updateProjectVersionForLocalDepsTest") {
doLast {
setProjectVersionForFutureBuilds(DEPS_TEST_VERSION)
}
}
tasks.register("generateBuildConfig") {
group = "mirai"
@ -89,56 +101,18 @@ fun generateBuildConfig() {
// keep this property for Search Everywhere
val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Exec::class) {
group = "mirai"
description = "Starts a child process to publish v2.99.0-deps-test artifacts to MavenLocal"
description = "Starts a child process to publish v$DEPS_TEST_VERSION artifacts to MavenLocal"
workingDir(rootProject.projectDir)
// The following code configures the new Gradle instance to inheriting configuration.
// This is important especially for "mirai.target" settings
// — On CI machines we didn't configure them to cross-compilation.
// Note that IntelliJ listener is also inherited, so you will see normal execution feedbacks in your IDE 'Run' view.
environment(System.getenv())
environment("mirai.build.project.version", "2.99.0-deps-test")
environment("mirai.target", getMiraiTargetFromGradle())
val projectProperties =
// gradle.startParameter.projectProperties
mapOf<String, String>()
.toMutableMap().apply {
put("kotlin.compiler.execution.strategy", "in-process")
}
.map { "-P${it.key}=${it.value}" }
.toTypedArray()
val allowedProperties = arrayOf("org.gradle.parallel")
val systemProperties =
// gradle.startParameter.systemPropertiesArgs
gradle.startParameter.systemPropertiesArgs
.filter { it.key in allowedProperties }
.map { "-D${it.key}=${it.value}" }
.toTypedArray()
environment("mirai.build.project.version", DEPS_TEST_VERSION)
commandLine(
"./gradlew",
publishMiraiArtifactsToMavenLocal.name,
"--no-daemon",
"--stacktrace",
"--scan",
*projectProperties,
*systemProperties,
) // ignore other Gradle args
doFirst {
// TODO: 2022/11/22 fix tips
logger.info(
"[publishMiraiLocalArtifacts] Starting a Gradle daemon to run requested publishing tasks. " +
"Your system environment, JVM properties, and Gradle properties are inherited, " +
"but note that any other Gradle arguments are IGNORED!"
)
logger.info("[publishMiraiLocalArtifacts] Oh, and don't worry, the daemon will be stopped after the task finishes so it won't waste your memory!")
}
"-Pkotlin.compiler.execution.strategy=in-process"
)
standardOutput = System.out
errorOutput = System.err
}

View File

@ -100,10 +100,12 @@ abstract class AbstractTest {
.forwardOutput()
.withEnvironment(System.getenv())
.withArguments(buildList {
addAll(arguments)
add("--no-daemon")
add("-Pkotlin.compiler.execution.strategy=in-process")
add("-Dorg.gradle.jvmargs=-Xmx512m -Dfile.encoding=UTF-8")
add("-Dorg.gradle.jvmargs=-Xmx512m")
add("-Dfile.encoding=UTF-8")
add("--stacktrace")
addAll(arguments)
})
.build()
}