Skip to content

Commit 4a17c15

Browse files
committed
Setup CI
1 parent 0c5b771 commit 4a17c15

File tree

5 files changed

+121
-121
lines changed

5 files changed

+121
-121
lines changed

.github/workflows/CI.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- 'nyan-work/dev'
6+
7+
jobs:
8+
build:
9+
if: ${{ github.event_name == 'push' && !startsWith(github.event.ref, 'refs/tags/') && contains(github.event.head_commit.message, '[build skip]') == false }}
10+
strategy:
11+
matrix:
12+
java: [ 17 ]
13+
os: [ ubuntu-latest ]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- name: Checkout the sources
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up JDK ${{ matrix.java }}
22+
uses: actions/setup-java@v3
23+
with:
24+
distribution: 'adopt'
25+
java-version: ${{ matrix.java }}
26+
27+
- name: Cache Gradle packages
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.gradle/caches
32+
./.gradle/loom-caches
33+
~/.gradle/wrapper
34+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
35+
36+
- name: Get short commit sha
37+
id: get_short_sha
38+
run: |
39+
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
40+
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
41+
42+
- name: Get commit count
43+
id: get_commit_count
44+
run: |
45+
commit_count=$(git log | grep -e 'commit [a-zA-Z0-9]*' | wc -l)
46+
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
47+
48+
- name: Read Properties mod info
49+
id: mod_info
50+
uses: christian-draeger/[email protected]
51+
with:
52+
path: gradle.properties
53+
properties: 'mod_name mod_version'
54+
55+
- name: Grant execute permission for gradlew
56+
run: chmod +x gradlew
57+
58+
- name: Preprocess sources
59+
env:
60+
BUILD_TYPE: "BETA"
61+
run: ./gradlew preprocessResources --stacktrace
62+
63+
- name: Publish Maven with Gradle
64+
env:
65+
BUILD_TYPE: "BETA"
66+
run: ./gradlew build --stacktrace
67+
68+
- name: Upload assets to GitHub Action
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: "${{ steps.mod_info.outputs.mod_name }} ${{ steps.mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_short_sha.outputs.short_sha }}"
72+
path: |
73+
LICENSE
74+
fabricWrapper/build/libs/*.jar
75+
fabricWrapper/build/tmp/submods/META-INF/jars/*.jar
76+
77+
- name: Create Github release
78+
if: contains(github.event.head_commit.message, '[publish skip]') == false && contains(github.event.ref, 'refs/heads/exp') == false
79+
uses: softprops/action-gh-release@v1
80+
with:
81+
prerelease: true
82+
files: |
83+
LICENSE
84+
fabricWrapper/build/libs/*.jar
85+
fabricWrapper/build/tmp/submods/META-INF/jars/*.jar
86+
name: "[CI#${{ github.run_number }}]${{ steps.mod_info.outputs.mod_name }} ${{ steps.mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_short_sha.outputs.short_sha }}"
87+
tag_name: "${{ github.ref_name }}.${{ github.run_number }}"
88+
target_commitish: ${{ github.event.ref }}
89+
generate_release_notes: true

.github/workflows/build.yml

-44
This file was deleted.

.github/workflows/publish.yml

-65
This file was deleted.

build.gradle

+32-11
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,41 @@ preprocess {
2222
mc118.link(mc119, file("versions/mapping-1.18.2-1.19.2.txt"))
2323
}
2424

25-
String realVersion = "${project.mod_version}"
26-
27-
if (project.pre_release != "") {
28-
realVersion += "-${project.pre_release}+"
29-
realVersion += grgit.head().abbreviatedId
30-
}
31-
32-
version = realVersion
33-
34-
task cleanPreprocessSources {
25+
tasks.register('cleanPreprocessSources') {
3526
doFirst {
3627
subprojects {
3728
def path = project.projectDir.toPath().resolve('build/preprocessed')
3829
path.toFile().deleteDir()
3930
}
4031
}
41-
}
32+
}
33+
34+
String getVersionGit(List paths) {
35+
if (grgit == null) {
36+
return "nogit"
37+
}
38+
List latestCommits = paths.isEmpty() ? grgit.log(maxCommits: 1) : grgit.log(paths: paths, maxCommits: 1)
39+
return latestCommits.isEmpty() ? "uncommited" : "${latestCommits.get(0).id.substring(0, 7)}"
40+
}
41+
42+
String getVersionType() {
43+
Map<String, String> ENV = System.getenv()
44+
switch (ENV.BUILD_TYPE) {
45+
case "RELEASE":
46+
return "stable"
47+
case "BETA":
48+
return "beta"
49+
default:
50+
return "dev"
51+
}
52+
}
53+
54+
int getVersionPatch(List paths) {
55+
if (grgit == null) {
56+
return 0
57+
}
58+
List latestCommits = paths.isEmpty() ? grgit.log() : grgit.log(paths: paths)
59+
return latestCommits.size()
60+
}
61+
62+
setVersion("${project.mod_version}.${getVersionPatch([])}+${getVersionGit([])}-${getVersionType()}")

gradle.properties

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod_homepage=https://blog.plusls.com/
77
mod_sources=https://github.com/plusls/oh-my-minecraft-client
88
mod_version=0.5
99
mod_license=LGPL-3
10-
pre_release=alpha
1110
maven_group=com.plusls
1211
archives_base_name=oh-my-minecraft-client
1312
# Deps

0 commit comments

Comments
 (0)