mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-02 09:14:53 +00:00
ci: generate changelog automatically, auto increase version number
This commit is contained in:
54
.github/workflows/build.yml
vendored
54
.github/workflows/build.yml
vendored
@@ -2,8 +2,6 @@ name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- version*
|
||||
branches:
|
||||
- dev
|
||||
- master
|
||||
@@ -48,6 +46,18 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: adopt
|
||||
architecture: x64
|
||||
java-version: 8
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.3'
|
||||
|
||||
- name: Compute variables
|
||||
id: vars
|
||||
@@ -60,10 +70,10 @@ jobs:
|
||||
git fetch --tags --force | Out-Null
|
||||
|
||||
$ref = "${env:GITHUB_REF}" # e.g. refs/tags/version1.2.3 or refs/heads/dev
|
||||
$refName = "${env:GITHUB_REF_NAME}" # e.g. version1.2.3 or dev
|
||||
$eventType = "${env:GITHUB_EVENT_NAME}" # e.g. "push" or "pull_request"
|
||||
$isTag = $ref.StartsWith("refs/tags/")
|
||||
$isDev = ($ref -eq "refs/heads/dev")
|
||||
$isMaster = ($ref -eq "refs/heads/master")
|
||||
$isPush = ($eventType -eq "push")
|
||||
|
||||
$H = (git rev-parse HEAD).Trim()
|
||||
@@ -90,27 +100,36 @@ jobs:
|
||||
Set-Var "verTag" ""
|
||||
Set-Var "verTitle" ""
|
||||
|
||||
|
||||
# Case 1: Tag versionX.Y.Z
|
||||
if ($isTag -and ($refName -match '^version(\d+)\.(\d+)\.(\d+)$')) {
|
||||
$raw = "";
|
||||
if ($isMaster) {
|
||||
$raw = php cicd_scripts/get_changelog.php true
|
||||
}
|
||||
if ($isDev -and $isPush) {
|
||||
$raw = php cicd_scripts/get_changelog.php false
|
||||
}
|
||||
if ($isMaster -or ($isDev -and $isPush)) {
|
||||
javac -cp build/classes -d build/classes src/com/jpexs/build/ChangelogUpdater.java
|
||||
java -cp build/classes com.jpexs.build.ChangelogUpdater
|
||||
}
|
||||
|
||||
if ($isMaster -and ($raw -match '^(\d+)\.(\d+)\.(\d+)$')) (
|
||||
$X = $Matches[1]
|
||||
$Y = $Matches[2]
|
||||
$Z = $Matches[3]
|
||||
|
||||
|
||||
Set-Var "verMajor" $X
|
||||
Set-Var "verMinor" $Y
|
||||
Set-Var "verRelease" $Z
|
||||
Set-Var "verBuild" "0"
|
||||
Set-Var "verRevision" $H
|
||||
|
||||
$raw = "$X.$Y.$Z"
|
||||
Set-Var "verRaw" $raw
|
||||
Set-Var "verShort" $raw
|
||||
Set-Var "verLong" $raw
|
||||
|
||||
Set-Var "verDebug" "false"
|
||||
Set-Var "verOldTag" ""
|
||||
Set-Var "verTag" $refName
|
||||
Set-Var "verTag" "version$raw"
|
||||
|
||||
Set-Var "doRelease" "true"
|
||||
Set-Var "verTitle" "version $raw"
|
||||
@@ -119,7 +138,7 @@ jobs:
|
||||
}
|
||||
|
||||
# Case 2: dev branch and push
|
||||
if ($isDev -and $isPush) {
|
||||
if ($isDev -and $isPush -and ($raw -eq "nightly")) {
|
||||
# Find latest nightlyN tag (max N)
|
||||
$nightlyTags = git tag --list 'nightly*'
|
||||
$maxN = -1
|
||||
@@ -195,6 +214,13 @@ jobs:
|
||||
echo "revision=${{ steps.vars.outputs.verRevision }}">>$VERSION_PROP_FILE
|
||||
echo "debug=${{ steps.vars.outputs.verDebug }}">>$VERSION_PROP_FILE
|
||||
|
||||
- name: Upload CHANGELOG.md artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
if: steps.vars.outputs.doRelease == 'true'
|
||||
with:
|
||||
name: changelog_md
|
||||
path: CHANGELOG.md
|
||||
|
||||
- name: Upload version.properties artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -934,13 +960,18 @@ jobs:
|
||||
with:
|
||||
distribution: adopt
|
||||
architecture: x64
|
||||
java-version: 8
|
||||
java-version: 8
|
||||
|
||||
- name: Set up Ant
|
||||
run: |
|
||||
sudo apt-get update -y -qq
|
||||
sudo apt-get install -y -qq ant
|
||||
|
||||
- name: Download CHANGELOG.md artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: changelog_md
|
||||
|
||||
- name: Download version.properties artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
@@ -1005,7 +1036,6 @@ jobs:
|
||||
path: ./release_notes.md
|
||||
|
||||
- name: Create tag
|
||||
if: needs.compute-version.outputs.verDebug == 'true'
|
||||
run: |
|
||||
TAG="${{ needs.compute-version.outputs.verTag }}"
|
||||
git fetch --tags --force
|
||||
|
||||
165
cicd_scripts/update_changelog.php
Normal file
165
cicd_scripts/update_changelog.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This script generates changelog from commit messages
|
||||
* and increases version number.
|
||||
*/
|
||||
|
||||
function print_usage()
|
||||
{
|
||||
fwrite(STDERR,
|
||||
"USAGE:\n"
|
||||
. " php update_changelog.php true/false\n"
|
||||
. "\n"
|
||||
. " true = is stable, false = is nightly\n"
|
||||
. " When it is stable it prints new version name on output."
|
||||
);
|
||||
}
|
||||
|
||||
if ($argc < 2) {
|
||||
fwrite(STDERR, "Invalid arguments:\n");
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!in_array($argv[1], ["true", "false"], true)) {
|
||||
fwrite(STDERR, "Invalid arguments:\n");
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$nightly = $argv[1] === "false";
|
||||
|
||||
$result = 0;
|
||||
exec('git tag -l "version*" --sort=-v:refname', $output, $result);
|
||||
$version1 = trim($output[0]);
|
||||
$version2 = "HEAD";
|
||||
|
||||
if ($result !== 0) {
|
||||
echo "cannot git tag";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
$result = 0;
|
||||
exec('git log ' . $version1 . '..' . $version2 . ' --pretty=format:"%s%n%b%n---SPLIT---" --reverse', $output, $result);
|
||||
if ($result !== 0) {
|
||||
echo "cannot git log";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
$messages = [];
|
||||
$message_lines = [];
|
||||
foreach ($output as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === "---SPLIT---") {
|
||||
$messages[] = $message_lines;
|
||||
$message_lines = [];
|
||||
} else {
|
||||
$message_lines[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$changelog_types = [
|
||||
"feat" => "Features",
|
||||
"fix" => "Bug Fixes",
|
||||
"perf" => "Performance Improvements"
|
||||
];
|
||||
|
||||
$changelog = [
|
||||
|
||||
];
|
||||
|
||||
foreach (array_keys($changelog_types) as $type) {
|
||||
$changelog[$type] = [];
|
||||
}
|
||||
|
||||
|
||||
foreach ($messages as $message) {
|
||||
$first_line = $message[0];
|
||||
|
||||
|
||||
if (preg_match('/^(?<type>feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\((?<scope>.+)\))?: (?<desc>.+)$/', $first_line, $matches)) {
|
||||
$type = $matches["type"];
|
||||
$scope = $matches["scope"];
|
||||
$desc = $matches["desc"];
|
||||
|
||||
if ($scope !== "") {
|
||||
$desc = $scope . ": " . $desc;
|
||||
}
|
||||
|
||||
if (array_key_exists($type, $changelog_types)) {
|
||||
$changelog[$type][] = $desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = "";
|
||||
$empty_changelog = true;
|
||||
foreach ($changelog as $type => $descs) {
|
||||
if (count($descs) === 0) {
|
||||
continue;
|
||||
}
|
||||
$empty_changelog = false;
|
||||
$result .= "\r\n";
|
||||
$result .= "### " . $changelog_types[$type] . "\r\n";
|
||||
foreach ($descs as $desc) {
|
||||
$result .= "- " . $desc . "\r\n";
|
||||
}
|
||||
}
|
||||
$result = trim($result) . "\r\n";
|
||||
|
||||
$changelog_file = "CHANGELOG.md";
|
||||
|
||||
$changelog_data = file_get_contents($changelog_file);
|
||||
|
||||
$changelog_data = preg_replace('/\r?\n/', "\r\n", $changelog_data);
|
||||
|
||||
$after = "\r\n## [";
|
||||
|
||||
preg_match('/^version(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)$/', $version1, $matches);
|
||||
|
||||
$major = (int) $matches["major"];
|
||||
$minor = (int) $matches["minor"];
|
||||
$patch = (int) $matches["patch"];
|
||||
|
||||
if (count($changelog["feat"]) > 0) {
|
||||
$minor++;
|
||||
} else if (count($changelog["fix"]) > 0 || count($changelog["perf"]) > 0) {
|
||||
$patch++;
|
||||
} else {
|
||||
$nightly = true;
|
||||
}
|
||||
|
||||
$new_version = "$major.$minor.$patch";
|
||||
|
||||
if ($nightly) {
|
||||
$version_title = "Unreleased";
|
||||
$version_date_add = "";
|
||||
} else {
|
||||
$version_title = $new_version;
|
||||
$version_date_add = " - " . date("Y-m-d");
|
||||
}
|
||||
|
||||
$insert = "\r\n## [$version_title]$version_date_add\r\n" . $result;
|
||||
|
||||
$after_pos = mb_strpos($changelog_data, $after);
|
||||
if ($after_pos !== false) {
|
||||
$changelog_data = mb_substr($changelog_data, 0, $after_pos) . $insert . mb_substr($changelog_data, $after_pos);
|
||||
}
|
||||
|
||||
file_put_contents($changelog_file, $changelog_data);
|
||||
|
||||
if ($empty_changelog) {
|
||||
echo "empty";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$nightly) {
|
||||
echo $version_title;
|
||||
exit;
|
||||
}
|
||||
|
||||
echo "nightly";
|
||||
Reference in New Issue
Block a user