diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cbb40d183..cea4a5edc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/cicd_scripts/update_changelog.php b/cicd_scripts/update_changelog.php new file mode 100644 index 000000000..7d52190cf --- /dev/null +++ b/cicd_scripts/update_changelog.php @@ -0,0 +1,165 @@ + "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('/^(?feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\((?.+)\))?: (?.+)$/', $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(?[0-9]+)\.(?[0-9]+)\.(?[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"; \ No newline at end of file