Skip to content

Commit 35bb03e

Browse files
authored
Add CI and release workflows to project (#8)
Resolves #1
1 parent 9bc7baf commit 35bb03e

File tree

9 files changed

+301
-44
lines changed

9 files changed

+301
-44
lines changed

.ci-java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11

.github/workflows/check.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Check project
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
run-on:
7+
type: string
8+
required: true
9+
description: "runner to check the project"
10+
task:
11+
type: string
12+
required: true
13+
description: "task to check the platform targets"
14+
15+
jobs:
16+
check:
17+
runs-on: ${{ inputs.run-on }}
18+
steps:
19+
- name: 'Checkout Repository'
20+
uses: actions/checkout@v3
21+
- uses: actions/setup-java@v3
22+
with:
23+
distribution: temurin
24+
java-version-file: .ci-java-version
25+
- name: Validate Gradle Wrapper
26+
uses: gradle/wrapper-validation-action@v1.0.6
27+
- name: Cache konan
28+
uses: actions/cache@v3.3.1
29+
with:
30+
path: ~/.konan
31+
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
32+
restore-keys: |
33+
${{ runner.os }}-gradle-
34+
- name: Build with Gradle
35+
uses: gradle/gradle-build-action@v2.6.0
36+
with:
37+
gradle-version: wrapper
38+
arguments: |
39+
${{ inputs.task }}
40+
detektAll
41+
ktlintCheck
42+
apiCheck

.github/workflows/dependencies.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
- uses: actions/setup-java@v3
1717
with:
1818
distribution: temurin
19-
java-version: 11
19+
java-version-file: .ci-java-version
2020
- name: Validate Gradle Wrapper
2121
uses: gradle/wrapper-validation-action@v1
2222
- name: Setup Gradle
23-
uses: gradle/gradle-build-action@v2
23+
uses: gradle/gradle-build-action@v2.6.0
2424
- name: Root Gradle Dependency Submission
2525
uses: mikepenz/gradle-dependency-submission@v0.8.6
2626
with:

.github/workflows/pull_request.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Check the PR"
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
check-linux:
12+
uses: ./.github/workflows/check.yml
13+
with:
14+
run-on: ubuntu-latest
15+
task: linuxAllTest
16+
check-macos:
17+
uses: ./.github/workflows/check.yml
18+
with:
19+
run-on: macos-latest
20+
task: macOsAllTest
21+
check-windows:
22+
uses: ./.github/workflows/check.yml
23+
with:
24+
run-on: windows-latest
25+
task: windowsAllTest

.github/workflows/release.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: "Create release"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
VERSION_FILE: gradle.properties
8+
VERSION_PATTERN: '(?<=version=).+'
9+
10+
jobs:
11+
version:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
CURRENT_VERSION: ${{ steps.versions.outputs.CURRENT_VERSION }}
15+
NEXT_VERSION: ${{ steps.versions.outputs.NEXT_VERSION }}
16+
RELEASE_VERSION: ${{ steps.versions.outputs.RELEASE_VERSION }}
17+
steps:
18+
- name: 'Checkout Repository'
19+
uses: actions/checkout@v3
20+
- name: Get version
21+
id: versions
22+
uses: HardNorth/github-version-generate@v1.3.0
23+
with:
24+
version-source: file
25+
version-file: ${{ env.VERSION_FILE }}
26+
version-file-extraction-pattern: ${{ env.VERSION_PATTERN }}
27+
publish_artifacts:
28+
needs:
29+
- version
30+
runs-on: macos-latest
31+
steps:
32+
- name: 'Checkout Repository'
33+
uses: actions/checkout@v3
34+
- uses: actions/setup-java@v3
35+
with:
36+
distribution: temurin
37+
java-version-file: .ci-java-version
38+
- name: Validate Gradle Wrapper
39+
uses: gradle/wrapper-validation-action@v1.0.6
40+
- name: Cache konan
41+
uses: actions/cache@v3.3.1
42+
with:
43+
path: ~/.konan
44+
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
45+
restore-keys: |
46+
${{ runner.os }}-gradle-
47+
- name: Build with Gradle
48+
uses: gradle/gradle-build-action@v2.6.0
49+
env:
50+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
51+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
52+
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
53+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
54+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
55+
with:
56+
gradle-version: wrapper
57+
arguments: |
58+
--no-daemon
59+
build
60+
publish
61+
closeAndReleaseStagingRepository
62+
-Pversion=${{ needs.version.outputs.RELEASE_VERSION }}
63+
create_release:
64+
runs-on: ubuntu-latest
65+
needs:
66+
- publish_artifacts
67+
- version
68+
steps:
69+
- name: 'Checkout Repository'
70+
uses: actions/checkout@v3
71+
- name: Store SHA of HEAD commit on ENV
72+
run: echo "GIT_HEAD=$(git rev-parse HEAD)" >> $GITHUB_ENV
73+
74+
- name: Create tag
75+
id: create_tag
76+
uses: actions/github-script@v6
77+
with:
78+
github-token: ${{ secrets.PUSH_PAT }}
79+
script: |
80+
const {GIT_HEAD} = process.env
81+
github.rest.git.createRef({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
ref: "refs/tags/${{ needs.version.outputs.RELEASE_VERSION }}",
85+
sha: `${GIT_HEAD}`
86+
})
87+
88+
- name: Build changelog
89+
id: build_changelog
90+
uses: mikepenz/release-changelog-builder-action@v4
91+
with:
92+
configuration: changelog_config.json
93+
toTag: ${{ needs.version.outputs.RELEASE_VERSION }}
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
- name: Create release
97+
id: create_release
98+
uses: ncipollo/release-action@v1.12.0
99+
with:
100+
body: ${{ steps.build_changelog.outputs.changelog }}
101+
name: Release ${{ needs.version.outputs.RELEASE_VERSION }}
102+
tag: ${{ needs.version.outputs.RELEASE_VERSION }}
103+
token: ${{ secrets.PUSH_PAT }}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish snapshot
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: macos-latest
11+
steps:
12+
- name: 'Checkout Repository'
13+
uses: actions/checkout@v3
14+
- uses: actions/setup-java@v3
15+
with:
16+
distribution: temurin
17+
java-version-file: .ci-java-version
18+
- name: Validate Gradle Wrapper
19+
uses: gradle/wrapper-validation-action@v1.0.6
20+
- name: Cache konan
21+
uses: actions/cache@v3.3.1
22+
with:
23+
path: ~/.konan
24+
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
25+
restore-keys: |
26+
${{ runner.os }}-gradle-
27+
- name: Build with Gradle
28+
uses: gradle/gradle-build-action@v2.6.0
29+
env:
30+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
31+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
32+
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
33+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
34+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
35+
with:
36+
gradle-version: wrapper
37+
arguments: |
38+
--no-daemon
39+
build
40+
publish

build.gradle.kts

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import io.gitlab.arturbosch.detekt.Detekt
2+
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
3+
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
24
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
35

46
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove when migrate to Gradle 8
@@ -19,11 +21,16 @@ repositories {
1921
mavenCentral()
2022
}
2123

24+
val mainHost: String by project
25+
2226
kotlin {
2327
explicitApi()
2428
jvm {
2529
jvmToolchain(11)
2630
withJava()
31+
testRuns["test"].executionTask.configure {
32+
useJUnitPlatform()
33+
}
2734
}
2835
js(IR) {
2936
browser {
@@ -36,34 +43,29 @@ kotlin {
3643
generateTypeScriptDefinitions()
3744
nodejs()
3845
}
39-
40-
val hostOs = System.getProperty("os.name")
41-
val isMingwX64 = hostOs.startsWith("Windows")
42-
when {
43-
hostOs == "Mac OS X" -> {
44-
macosX64()
45-
macosArm64()
46-
47-
ios()
48-
iosArm64()
49-
iosSimulatorArm64()
50-
51-
watchos()
52-
watchosArm32()
53-
watchosSimulatorArm64()
54-
55-
tvos()
56-
tvosArm64()
57-
tvosX64()
58-
}
59-
60-
hostOs == "Linux" -> {
61-
linuxX64()
62-
linuxArm64()
63-
}
64-
isMingwX64 -> mingwX64()
65-
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
66-
}
46+
ios()
47+
tvos()
48+
watchos()
49+
50+
val macOsTargets = listOf<KotlinTarget>(
51+
macosX64(),
52+
macosArm64(),
53+
iosArm64(),
54+
iosSimulatorArm64(),
55+
watchosArm32(),
56+
watchosSimulatorArm64(),
57+
tvosArm64(),
58+
tvosX64(),
59+
)
60+
61+
val linuxTargets = listOf<KotlinTarget>(
62+
linuxX64(),
63+
linuxArm64(),
64+
)
65+
66+
val windowsTargets = listOf<KotlinTarget>(
67+
mingwX64(),
68+
)
6769

6870
sourceSets {
6971
val commonMain by getting {
@@ -86,24 +88,34 @@ kotlin {
8688
}
8789
}
8890

89-
val publicationsFromMainHost =
90-
listOf(jvm(), js()).map { it.name } + "kotlinMultiplatform"
91-
publishing {
92-
publications {
93-
matching { it.name in publicationsFromMainHost }.all {
94-
val targetPublication = this@all
95-
tasks.withType<AbstractPublishToMaven>()
96-
.matching { it.publication == targetPublication }
97-
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
91+
afterEvaluate {
92+
fun Task.dependsOnTargetTests(targets: List<KotlinTarget>) {
93+
targets.forEach {
94+
if (it is KotlinTargetWithTests<*, *>) {
95+
dependsOn(tasks.getByName("${it.name}Test"))
96+
}
9897
}
9998
}
99+
tasks.register("macOsAllTest") {
100+
group = "verification"
101+
description = "runs all tests for MacOS and IOS targets"
102+
dependsOnTargetTests(macOsTargets)
103+
}
104+
tasks.register("windowsAllTest") {
105+
group = "verification"
106+
description = "runs all tests for Windows targets"
107+
dependsOnTargetTests(windowsTargets)
108+
}
109+
tasks.register("linuxAllTest") {
110+
group = "verification"
111+
description = "runs all tests for Linux targets"
112+
dependsOnTargetTests(linuxTargets)
113+
dependsOn(tasks.getByName("jvmTest"))
114+
dependsOn(tasks.getByName("jsTest"))
115+
}
100116
}
101117
}
102118

103-
tasks.named<Test>("jvmTest") {
104-
useJUnitPlatform()
105-
}
106-
107119
ktlint {
108120
version.set(libs.versions.ktlint)
109121
reporters {

changelog_config.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"categories": [
3+
{
4+
"title": "## 🚀 Features",
5+
"labels": ["enhancement"],
6+
"empty_content": "No new features today 😢"
7+
},
8+
{
9+
"title": "## 🐛 Fixes",
10+
"labels": ["fix"],
11+
"empty_content": "🤔 No bugs at all?"
12+
},
13+
{
14+
"title": "## 🧰 CI/CD",
15+
"labels": ["ci/cd"]
16+
}
17+
18+
],
19+
"ignore_labels": [
20+
"ignore"
21+
],
22+
"sort": {
23+
"order": "ASC",
24+
"on_property": "mergedAt"
25+
},
26+
"template": "#{{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n#{{UNCATEGORIZED}}\n</details>\n\n<details>\n<summary>Also merged but not included in notes</summary>\n\n#{{IGNORED}}\n</details>",
27+
"pr_template": "- #{{TITLE}} (PR: ##{{NUMBER}})",
28+
"empty_template": "Nothing here today",
29+
"trim_values": true,
30+
"max_tags_to_fetch": 200,
31+
"max_pull_requests": 200,
32+
"max_back_track_time_days": 365,
33+
"base_branches": [ "main" ]
34+
}

0 commit comments

Comments
 (0)