Skip to content

Commit

Permalink
ci: Setup version naming scheme & auto release CI (#18)
Browse files Browse the repository at this point in the history
* build: Change version number to git-based system

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Setup basic beta build and publish action

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Enable ` --stacktrace` for gradle build

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Fix mod info getter

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Remove pull_request dispatch for pre-release action

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Setup `REDEN_BUILD_TYPE` ENV

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Add build action for PRs

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Allow multiple artifacts for dev ci

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Enable Gradle Cache

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* build: Add a version suffix when building with GitHub Action

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Fix release condition

* ci: Add ci-build version suffix only when beta

* ci: Add more publish requirement

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Add ability to manually trigger beta release

* ci: Add stable release CI

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Fix

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

* ci: Fix auto stable release tag

* ci: Add publish to Modrinth & CurseForge

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>

---------

Signed-off-by: Qian Qian "Cubik"‎ <cubik65536@cubik65536.top>
  • Loading branch information
Cubik65536 authored Aug 31, 2023
1 parent 0fe3d76 commit e855ae2
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 35 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/build-and-publish-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Build Stable Release version and Publish

on:
release:
# It is recommended to set the release tag as "v.<major>.<minor>-patch.<patch>" (e.g. "v.1.0-patch.1") when creating a release.
types: [released]

jobs:
build-and-publish-pre-release:
strategy:
matrix:
# Use thses Java versions:
java: [17] # Only use the latest Java LTS
# Use these operating systems:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Show Java version
run: java -version
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Show Gradle version
run: gradle --version

- name: Build with Gradle
env:
REDEN_BUILD_TYPE: "RELEASE"
run: gradle build --stacktrace

- name: Get Mod Info
id: get_mod_info
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
properties: 'mod_name mod_version'
- name: Get commit SHA
id: get_commit_sha
run: |
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
- name: Get commit count
id: get_commit_count
run: |
commit_count=$(git log | grep -e '^commit [a-zA-Z0-9]*' | wc -l)
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
- name: Upload assets to GitHub Action
uses: actions/upload-artifact@v3
with:
name: "${{ steps.get_mod_info.outputs.mod_name }} ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
path: build/libs/*.jar

- name: Publish to GitHub Releases
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: build/libs/*.jar
body: "[RELEASE-CI#${{ github.run_number }}] ${{ steps.get_mod_info.outputs.mod_name }} Mod Stable Release ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
generateReleaseNotes: true
makeLatest: true
tag: ${{ github.event.ref }}

- name: Publish to Modrinth & CurseForge
uses: Kir-Antipov/mc-publish@v3.3
with:
# Publish to Modrinth
modrinth-id: xRu8OXEJ
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
# Publish to CurseForge
curseforge-id: 903236
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
# Universal Configurations
files: |
build/libs/!(*-@(dev|beta|sources|javadoc)).jar
build/libs/*-@(dev|beta|sources|javadocs).jar
name: "${{ steps.get_mod_info.outputs.mod_name }} ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
version: "${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
version-type: release

loaders: fabric
game-versions: 1.20.1
game-version-filter: any
java: |
17
18
19
20
retry-attempts: 2
retry-delay: 10000
119 changes: 119 additions & 0 deletions .github/workflows/build-and-publish-pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Build Pre-Release version and Publish

on:
workflow_dispatch:
inputs:
release-beta:
description: 'Publish a beta release?'
required: true
type: boolean
push:
branches:
- '**' # Pushes to any branch

jobs:
build-and-publish-pre-release:
strategy:
matrix:
# Use thses Java versions:
java: [17, 20] # Current Java LTS and current latest Java version
# Use these operating systems:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Store all lowercase commit message
run: |
echo "COMMIT_MESSAGE=$(echo ${github.event.head_commit.message} | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Detect if a beta release should be published
if: ${{ contains(env.COMMIT_MESSAGE, '[publish beta]') || inputs.release-beta }}
run: |
echo "PUBLISH_BETA=true" >> ${GITHUB_ENV}
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Show Java version
run: java -version
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Show Gradle version
run: gradle --version


- name: Build with Gradle (DEV)
if : ${{ env.PUBLISH_BETA != 'true' }}
run: gradle build --stacktrace
- name: Build with Gradle (BETA)
if : ${{ env.PUBLISH_BETA == 'true' }}
env:
REDEN_BUILD_TYPE: "BETA"
run: gradle build --stacktrace

- name: Get Mod Info
id: get_mod_info
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
properties: 'mod_name mod_version'
- name: Get commit SHA
id: get_commit_sha
run: |
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
- name: Get commit count
id: get_commit_count
run: |
commit_count=$(git log | grep -e '^commit [a-zA-Z0-9]*' | wc -l)
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
- name: Upload assets to GitHub Action
uses: actions/upload-artifact@v3
with:
name: "[DEV-CI#${{ github.run_number }}] ${{ steps.get_mod_info.outputs.mod_name }} ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }} - Java ${{ matrix.java }}"
path: build/libs/*.jar

- name: Publish to GitHub Pre-Releases
if: ${{ env.PUBLISH_BETA == 'true' && matrix.java == 17 }} # Only publish the version built with Java LTS
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: build/libs/*.jar
generateReleaseNotes: true
name: "[CI#${{ github.run_number }}] ${{ steps.get_mod_info.outputs.mod_name }} Mod Pre-Release ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
prerelease: true
tag: "beta/${{ steps.get_commit_sha.outputs.short_sha }}"

- name: Publish to Modrinth & CurseForge
if: ${{ env.PUBLISH_BETA == 'true' && matrix.java == 17 }} # Only publish the version built with Java LTS
uses: Kir-Antipov/mc-publish@v3.3
with:
# Publish to Modrinth
modrinth-id: xRu8OXEJ
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
# Publish to CurseForge
curseforge-id: 903236
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
# Universal Configurations
files: |
build/libs/!(*-@(dev|sources|javadoc)).jar
build/libs/*-@(dev|sources|javadocs).jar
name: "${{ steps.get_mod_info.outputs.mod_name }} Pre-Release ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
version: "beta/${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
version-type: beta

loaders: fabric
game-versions: 1.20.1
game-version-filter: any
java: |
17
18
19
20
retry-attempts: 2
retry-delay: 10000
55 changes: 55 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build from Pull Request

on: [pull_request]

jobs:
build-pr:
strategy:
matrix:
# Use thses Java versions:
java: [17, 20] # Current Java LTS and current latest Java version
# Use these operating systems:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Show Java version
run: java -version
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Show Gradle version
run: gradle --version


- name: Build with Gradle
run: gradle build --stacktrace

- name: Get Mod Info
id: get_mod_info
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
properties: 'mod_name mod_version'
- name: Get commit SHA
id: get_commit_sha
run: |
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
- name: Get commit count
id: get_commit_count
run: |
commit_count=$(git log | grep -e '^commit [a-zA-Z0-9]*' | wc -l)
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
- name: Upload assets to GitHub Action
uses: actions/upload-artifact@v3
with:
name: "[PR-CI#${{ github.run_number }}] ${{ steps.get_mod_info.outputs.mod_name }} ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }} - Java ${{ matrix.java }}"
path: build/libs/*.jar
30 changes: 0 additions & 30 deletions .github/workflows/build.yml

This file was deleted.

57 changes: 52 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,62 @@
import java.text.SimpleDateFormat

plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
id "org.ajoberstar.grgit" version "4.1.0"
id "org.ajoberstar.grgit" version "5.2.0"
id 'org.jetbrains.kotlin.jvm' version '1.8.10'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.10'
id 'me.fallenbreath.yamlang' version '1.3.0'
}

version = project.mod_version + "+" + new SimpleDateFormat("MMddHHmm").format(new Date())
ext {
Map<String, String> environmentMap = System.getenv()

isOnGithubActions = {
return environmentMap.GITHUB_ACTIONS == "true"
}

getGitHubActionID = {
return environmentMap.GITHUB_RUN_NUMBER
}

getVersionType = {
switch (environmentMap.REDEN_BUILD_TYPE) {
case "RELEASE":
return "stable"
case "BETA":
return "beta"
default:
return "dev"
}
}

getVersionPatch = { List paths ->
if (grgit == null) {
return 0
}

List latestCommits = paths.isEmpty() ? grgit.log() : grgit.log(paths: paths)
return latestCommits.size()
}

getVersionGit = { List paths ->
if (grgit == null) {
return "nogit"
}

List latestCommits = paths.isEmpty() ? grgit.log(maxCommits: 1) : grgit.log(paths: paths, maxCommits: 1)
return latestCommits.isEmpty() ? "uncommited" : "${latestCommits.get(0).id.substring(0, 7)}"
}

getModVersion = {
if (isOnGithubActions() && environmentMap.REDEN_BUILD_TYPE == "BETA") {
return "${project.mod_version}.${getVersionPatch([])}+${getVersionGit([])}-${getVersionType()}+dev-ci-build.${getGitHubActionID()}"
} else {
return "${project.mod_version}.${getVersionPatch([])}+${getVersionGit([])}-${getVersionType()}"
}
}
}

setVersion(project.getModVersion())
group = project.maven_group

repositories {
Expand All @@ -27,7 +74,7 @@ repositories {
}

dependencies {
// implementation 'org.bouncycastle:'
// implementation 'org.bouncycastle:'
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ org.gradle.jvmargs=-Xmx5G
org.gradle.parallel=true

# Mod Properties
mod_name = Reden
mod_version = 0.1
maven_group = com.github.zly2006
archives_base_name = reden-is-what-we-made
Expand Down

0 comments on commit e855ae2

Please sign in to comment.