Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit fb556fb

Browse files
committed
New publishing mechanic
Signed-off-by: DeathsGun <deathsgun@protonmail.com>
1 parent b06b615 commit fb556fb

File tree

4 files changed

+167
-26
lines changed

4 files changed

+167
-26
lines changed

.github/workflows/build.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- "1.16"
6+
- "1.17"
7+
- "1.18"
8+
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
outputs:
14+
version: ${{ steps.properties.outputs.version }}
15+
changelog: ${{ steps.properties.outputs.changelog }}
16+
steps:
17+
18+
# Check out current repository
19+
- name: Fetch Sources
20+
uses: actions/checkout@v2.4.0
21+
22+
# Validate wrapper
23+
- name: Gradle Wrapper Validation
24+
uses: gradle/wrapper-validation-action@v1.0.4
25+
26+
# Setup Java 11 environment for the next steps
27+
- name: Setup Java
28+
uses: actions/setup-java@v2
29+
with:
30+
distribution: zulu
31+
java-version: 17
32+
cache: gradle
33+
34+
# Set environment variables
35+
- name: Export Properties
36+
id: properties
37+
shell: bash
38+
run: |
39+
PROPERTIES="$(./gradlew properties --console=plain -q)"
40+
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
41+
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
42+
CHANGELOG="${CHANGELOG//'%'/'%25'}"
43+
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
44+
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
45+
echo "::set-output name=version::$VERSION"
46+
echo "::set-output name=changelog::$CHANGELOG"
47+
48+
- name: Build artifact
49+
run: ./gradlew build zip
50+
51+
- name: Publish Unit Test Results
52+
uses: EnricoMi/publish-unit-test-result-action@v1
53+
if: always()
54+
with:
55+
files: build/test-results/**/*.xml
56+
57+
- name: Collect Artifact
58+
uses: actions/upload-artifact@v2.2.4
59+
with:
60+
path: ./build/distributions/*.zip
61+
62+
releaseDraft:
63+
name: Release Draft
64+
if: github.event_name != 'pull_request'
65+
needs: build
66+
runs-on: ubuntu-latest
67+
steps:
68+
69+
# Check out current repository
70+
- name: Fetch Sources
71+
uses: actions/checkout@v2.4.0
72+
73+
# Remove old release drafts by using the curl request for the available releases with draft flag
74+
- name: Remove Old Release Drafts
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
run: |
78+
gh api repos/{owner}/{repo}/releases \
79+
--jq '.[] | select(.draft == true) | .id' \
80+
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
81+
# Create new release draft - which is not publicly visible and requires manual acceptance
82+
- name: Create Release Draft
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
run: |
86+
gh release create v${{ needs.build.outputs.version }} \
87+
--draft \
88+
--title "v${{ needs.build.outputs.version }}" \
89+
--notes "$(cat << 'EOM'
90+
${{ needs.build.outputs.changelog }}
91+
EOM
92+
)"

.github/workflows/publish.yml

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,78 @@
1-
name: Publish to Modrinth
1+
name: Release
22
on:
3-
push:
4-
tags:
5-
- v*
3+
release:
4+
types: [ prereleased, released ]
65

76
jobs:
8-
build:
9-
strategy:
10-
matrix:
11-
java: [
12-
16
13-
]
14-
os: [ ubuntu-latest ]
15-
runs-on: ${{ matrix.os }}
7+
8+
# Prepare and publish the plugin to the Marketplace repository
9+
release:
10+
name: Publish Plugin
11+
runs-on: ubuntu-latest
1612
steps:
17-
- name: checkout repository
18-
uses: actions/checkout@v2
19-
- name: validate gradle wrapper
20-
uses: gradle/wrapper-validation-action@v1
21-
- name: setup jdk ${{ matrix.java }}
22-
uses: actions/setup-java@v1
13+
14+
# Check out current repository
15+
- name: Fetch Sources
16+
uses: actions/checkout@v2.4.0
17+
with:
18+
ref: ${{ github.event.release.tag_name }}
19+
20+
# Setup Java 11 environment for the next steps
21+
- name: Setup Java
22+
uses: actions/setup-java@v2
2323
with:
24-
java-version: ${{ matrix.java }}
25-
- name: make gradle wrapper executable
26-
run: chmod +x ./gradlew
27-
- name: build
28-
run: ./gradlew build
29-
- name: Publish artifacts to Modrinth
24+
distribution: zulu
25+
java-version: 17
26+
cache: gradle
27+
28+
# Set environment variables
29+
- name: Export Properties
30+
id: properties
31+
shell: bash
32+
run: |
33+
CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d'
34+
${{ github.event.release.body }}
35+
EOM
36+
)"
37+
38+
CHANGELOG="${CHANGELOG//'%'/'%25'}"
39+
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
40+
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
41+
echo "::set-output name=changelog::$CHANGELOG"
42+
# Update Unreleased section with the current release note
43+
- name: Patch Changelog
44+
if: ${{ steps.properties.outputs.changelog != '' }}
45+
env:
46+
CHANGELOG: ${{ steps.properties.outputs.changelog }}
47+
run: |
48+
./gradlew patchChangelog --release-note="$CHANGELOG"
49+
# Publish the mod to Modrinth
50+
- name: Publish Plugin
51+
env:
52+
MODRINTH: ${{ secrets.MODRINTH }}
3053
run: ./gradlew publishModrinth
54+
55+
# Upload artifact as a release asset
56+
- name: Upload Release Asset
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*
60+
61+
# Create pull request
62+
- name: Create Pull Request
63+
if: ${{ steps.properties.outputs.changelog != '' }}
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
run: |
67+
VERSION="${{ github.event.release.tag_name }}"
68+
BRANCH="changelog-update-$VERSION"
69+
git config user.email "action@github.com"
70+
git config user.name "GitHub Action"
71+
git checkout -b $BRANCH
72+
git commit -am "Changelog update - $VERSION"
73+
git push --set-upstream origin $BRANCH
74+
gh pr create \
75+
--title "Changelog update - \`$VERSION\`" \
76+
--body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \
77+
--base main \
78+
--head $BRANCH

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- Updated to 1.18.1
1818
- Updated Russian translation (thanks to Felix14-v2) [#97](https://github.com/DeathsGun/ModManager/pull/97)
1919

20-
## [1.2.1] - 22.11.2021
20+
## [1.2.0+1.18-pre] - 22.11.2021
2121

2222
### Added
2323

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins {
2020
id "fabric-loom" version "0.10-SNAPSHOT"
2121
id "com.modrinth.minotaur" version "1.2.1"
2222
id "org.jetbrains.kotlin.jvm" version "1.5.30"
23+
id "org.jetbrains.changelog" version "1.3.1"
2324
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.30"
2425
}
2526

@@ -112,5 +113,5 @@ task publishModrinth(type: TaskModrinthUpload) {
112113
addLoader("fabric")
113114
addDependency("JPP6w2U1", Dependency.DependencyType.REQUIRED) // Mod Menu
114115
addDependency("1qsZV7U7", Dependency.DependencyType.REQUIRED) // fabric-language-kotlin
115-
changelog = file("CHANGELOG.md").getText("UTF-8")
116+
changelog = this.changelog.getUnreleased().withHeader(false).toText()
116117
}

0 commit comments

Comments
 (0)