Release new version ant task - github-newversion.

Metainfo updater Java class instead of sh script - to be able to run it properly on windows.
This commit is contained in:
Jindra Petřík
2023-02-25 19:37:46 +01:00
parent 23742c9195
commit 9a693a7f5d
4 changed files with 230 additions and 4 deletions

View File

@@ -83,6 +83,7 @@ app.bundle.dir = mac/bundle
changelog.file = CHANGELOG.md
src.dir = src
resources.dir = resources
metainfo.file = ${resources.dir}/com.jpexs.decompiler.flash.metainfo.xml
test.dir = test
test.lib.dir = testlib
test.result.dir = reports/tests

106
build.xml
View File

@@ -904,4 +904,110 @@
<fixcrlf srcdir="${src.dir}" includes="**/*.sh" eol="lf" />
<ant antfile="${core.lib.script}" target="fix-src-endoflines" inheritAll="false" usenativebasedir="true" />
</target>
<target name="update-changelog-md" depends="compile">
<java classname="com.jpexs.build.ChangelogUpdater" failonerror="true" fork="true">
<classpath>
<fileset dir="${basedir}" includes="lib/**/*.jar"/>
<pathelement location="build/classes"/>
</classpath>
</java>
</target>
<target name="update-metainfo" depends="compile" >
<java classname="com.jpexs.build.MetainfoUpdater" failonerror="true" fork="true">
<classpath>
<fileset dir="${basedir}" includes="lib/**/*.jar"/>
<pathelement location="build/classes"/>
</classpath>
</java>
</target>
<target name="-github-newversion-input">
<input message="Enter new version number (for example 19.2.3) :" addproperty="gh.newversion" />
<fail unless="gh.newversion">Version number must be nonempty</fail>
<tstamp>
<format property="gh.newversion.time" pattern="yyyy-MM-dd" />
</tstamp>
</target>
<target name="rename-unreleased-section" depends="-github-newversion-input">
<replace file="${basedir}/${changelog.file}" token="## [Unreleased]" value="## [${gh.newversion}] - ${gh.newversion.time}"/>
</target>
<target name="-add-unreleased-section" depends="-github-newversion-input">
<replace file="${basedir}/${changelog.file}" token="## [${gh.newversion}] - ${gh.newversion.time}" value="## [Unreleased]${line.separator}${line.separator}## [${gh.newversion}] - ${gh.newversion.time}"/>
</target>
<target name="-git-checkout-master" depends="-git-required">
<exec executable="git" failonerror="true">
<arg value="checkout"/>
<arg value="master"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="pull"/>
<arg value="origin"/>
<arg value="master"/>
</exec>
</target>
<target name="github-newversion" depends="-git-required,-git-checkout-master,-github-newversion-input,rename-unreleased-section,update-changelog-md,update-metainfo">
<exec executable="git" failonerror="true">
<arg value="add"/>
<arg value="${changelog.file}"/>
<arg value="${metainfo.file}"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="commit"/>
<arg value="-m"/>
<arg value="version changed to ${gh.newversion}"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="tag"/>
<arg value="version${gh.newversion}"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="push"/>
<arg value="origin"/>
<arg value="master"/>
<arg value="version${gh.newversion}"/>
</exec>
<antcall target="-add-unreleased-section" />
<antcall target="update-changelog-md" />
<exec executable="git" failonerror="false">
<arg value="branch"/>
<arg value="-D"/>
<arg value="dev"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="checkout"/>
<arg value="-b"/>
<arg value="dev"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="add"/>
<arg value="${changelog.file}"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="commit"/>
<arg value="-m"/>
<arg value="created new Unreleased section in CHANGELOG.md"/>
</exec>
<exec executable="git" failonerror="true">
<arg value="push"/>
<arg value="--set-upstream"/>
<arg value="origin"/>
<arg value="dev"/>
<arg value="--force"/>
</exec>
</target>
</project>

View File

@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
package com.jpexs.build;
import com.jpexs.helpers.Helper;
import java.io.UnsupportedEncodingException;
@@ -26,16 +26,18 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* Updates CHANGELOG.md file. Adds links to issue numbers - brackets, adds links to versions
* @author JPEXS
*/
public class ChangelogUpdater {
private static final String GITHUB_ADDRESS = "https://github.com/jindrapetrik/jpexs-decompiler/";
private static final String ISSUE_TRACKER_ADDRESS = "https://www.free-decompiler.com/flash/issues/";
private static final String CHANGELOG_FILENAME = "CHANGELOG.md";
public static void main(String[] args) throws UnsupportedEncodingException {
String changeLog = Helper.readTextFile("CHANGELOG.md");
String changeLog = Helper.readTextFile(CHANGELOG_FILENAME);
changeLog = changeLog.replaceAll("\\[[^\\]]+\\]: [^\\r\\n]+\\r\\n", "");
changeLog = changeLog.replaceAll("\\[#([0-9]+)\\]", "#$1");
@@ -89,6 +91,6 @@ public class ChangelogUpdater {
changeLog += "[#" + issue + "]: " + ISSUE_TRACKER_ADDRESS + issue + "\r\n";
}
Helper.writeFile("CHANGELOG.md", changeLog.getBytes("UTF-8"));
Helper.writeFile(CHANGELOG_FILENAME, changeLog.getBytes("UTF-8"));
}
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright (C) 2023 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.build;
import com.jpexs.helpers.Helper;
import java.io.UnsupportedEncodingException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Update Flatpak metainfo XML file. Generates metainfo from CHANGELOG.md file. Appends new versions that are not present in metainfo file.
* @author JPEXS
*/
public class MetainfoUpdater {
public static final String METAINFO_FILENAME = "resources/com.jpexs.decompiler.flash.metainfo.xml";
private static final String CHANGELOG_FILENAME = "CHANGELOG.md";
public static void main(String[] args) throws UnsupportedEncodingException {
String metainfo = Helper.readTextFile(METAINFO_FILENAME);
String changeLog = Helper.readTextFile(CHANGELOG_FILENAME);
String newline = System.lineSeparator();
Pattern metainfoVersionPattern = Pattern.compile("<release version=\"(?<version>[0-9]+\\.[0-9]+\\.[0-9]+)\" date=\"(?<date>[0-9]+-[0-9]+-[0-9]+)\">");
Matcher metainfoVersionMatcher = metainfoVersionPattern.matcher(metainfo);
if (!metainfoVersionMatcher.find()) {
throw new IllegalArgumentException("No last metainfo version found");
}
String latestMetainfoVersion = metainfoVersionMatcher.group("version");
Pattern changelogVersionPattern = Pattern.compile("## \\[(?<version>[0-9]+\\.[0-9]+\\.[0-9]+)\\] - (?<date>[0-9]+-[0-9]+-[0-9]+)");
Matcher changelogVersionMatcher = changelogVersionPattern.matcher(changeLog);
int prevMatchEnd = -1;
String prevVersion = null;
String prevDate = null;
String releases = "";
while (changelogVersionMatcher.find()) {
if(prevMatchEnd != -1) {
if (prevVersion.equals(latestMetainfoVersion)) {
break;
}
String versionChangelog = changeLog.substring(prevMatchEnd, changelogVersionMatcher.start()).trim();
String parts[] = (versionChangelog + "\r\n").split("\r?\n");
String prev = null;
String description = "";
String li = "";
for (String s:parts) {
if (s.startsWith("### ")) {
if (!li.isEmpty()) {
description += "\t\t\t\t\t<li>" + filterLiText(li) + "</li>"+newline;
li = "";
}
if (!description.isEmpty()) {
description += "\t\t\t\t</ul>"+newline;
}
description += "\t\t\t\t<p>" + s.substring(4).trim() + "</p>"+newline;
description += "\t\t\t\t<ul>" + newline;
continue;
}
if (s.startsWith("- ")) {
if (!li.isEmpty()) {
description += "\t\t\t\t\t<li>" + filterLiText(li) + "</li>"+newline;
}
li = s.trim().substring(2);
} else {
if (!s.trim().isEmpty()) {
li = li + " " + s.trim();
}
}
}
if (!li.isEmpty()) {
description += "\t\t\t\t\t<li>" + filterLiText(li) + "</li>"+newline;
}
if (!description.isEmpty()) {
description += "\t\t\t\t</ul>" + newline;
}
String release = "\t\t<release version=\"" + prevVersion + "\" date=\""+prevDate+"\">" + newline
+ "\t\t\t<description>" + newline
+ description
+ "\t\t\t</description>" + newline
+ "\t\t</release>" + newline;
releases += release;
}
prevVersion = changelogVersionMatcher.group("version");
prevDate = changelogVersionMatcher.group("date");
prevMatchEnd = changelogVersionMatcher.end();
}
metainfo = metainfo.replaceAll("<releases>", ("<releases>" + newline + releases).trim());
Helper.writeFile(METAINFO_FILENAME, metainfo.getBytes("UTF-8"));
}
private static String filterLiText(String li) {
return li.replaceAll("\\[(#[0-9]+)\\]", "$1");
}
}