mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
build(versioning): synchronize app version across Tauri and simulation configs (#5120)
# Description of Changes
- **What was changed**
- Added `groovy.json.JsonOutput` and `groovy.json.JsonSlurper` imports
to `build.gradle`.
- Introduced a reusable `writeIfChanged(File targetFile, String
newContent)` helper to avoid unnecessary file writes when content is
unchanged.
- Added `updateTauriConfigVersion(String version)` to:
- Parse `frontend/src-tauri/tauri.conf.json`.
- Set the `version` field from `project.version`.
- Re-write the file as pretty-printed JSON (with a trailing line
separator) only if content actually changed.
- Added `updateSimulationVersion(File fileToUpdate, String version)` to:
- Locate the `appVersion: '<value>'` assignment via regex in simulation
files.
- Replace the existing version with `project.version`.
- Fail the build with a clear `GradleException` if `appVersion` cannot
be found.
- Registered a new Gradle task `syncAppVersion` (group: `versioning`)
which:
- Reads `project.version` as the canonical app version.
- Updates `frontend/src-tauri/tauri.conf.json`.
- Updates `frontend/src/core/testing/serverExperienceSimulations.ts`.
- Updates
`frontend/src/proprietary/testing/serverExperienceSimulations.ts`.
- Updated the main `build` task so it now depends on `syncAppVersion` in
addition to `:stirling-pdf:bootJar` and `buildRestartHelper`.
- **Why the change was made**
- To ensure the desktop Tauri configuration and server experience
simulation configs consistently use the same application version as
defined in `project.version`.
- To remove manual version bumps in multiple files and eliminate the
risk of version mismatches between backend, desktop app, and
simulation/testing tooling.
- To minimize noise in commits and CI by only touching versioned files
when their content actually changes (using `writeIfChanged`).
---
## Checklist
### General
- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### Translations (if applicable)
- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
This commit is contained in:
+48
-1
@@ -12,6 +12,8 @@ plugins {
|
||||
}
|
||||
|
||||
import com.github.jk1.license.render.*
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
ext {
|
||||
springBootVersion = "3.5.6"
|
||||
@@ -65,6 +67,51 @@ allprojects {
|
||||
}
|
||||
}
|
||||
|
||||
def writeIfChanged(File targetFile, String newContent) {
|
||||
if (targetFile.getText('UTF-8') != newContent) {
|
||||
targetFile.write(newContent, 'UTF-8')
|
||||
}
|
||||
}
|
||||
|
||||
def updateTauriConfigVersion(String version) {
|
||||
File tauriConfig = file('frontend/src-tauri/tauri.conf.json')
|
||||
def parsed = new JsonSlurper().parse(tauriConfig)
|
||||
parsed.version = version
|
||||
|
||||
def formatted = JsonOutput.prettyPrint(JsonOutput.toJson(parsed)) + System.lineSeparator()
|
||||
writeIfChanged(tauriConfig, formatted)
|
||||
}
|
||||
|
||||
def updateSimulationVersion(File fileToUpdate, String version) {
|
||||
def content = fileToUpdate.getText('UTF-8')
|
||||
def matcher = content =~ /(appVersion:\s*')([^']*)(')/
|
||||
|
||||
if (!matcher.find()) {
|
||||
throw new GradleException("Could not locate appVersion in ${fileToUpdate} for synchronization")
|
||||
}
|
||||
|
||||
def updatedContent = matcher.replaceFirst("${matcher.group(1)}${version}${matcher.group(3)}")
|
||||
writeIfChanged(fileToUpdate, updatedContent)
|
||||
}
|
||||
|
||||
tasks.register('syncAppVersion') {
|
||||
group = 'versioning'
|
||||
description = 'Synchronizes app version across desktop and simulation configs.'
|
||||
|
||||
doLast {
|
||||
def appVersion = project.version.toString()
|
||||
println "Synchronizing application version to ${appVersion}"
|
||||
updateTauriConfigVersion(appVersion)
|
||||
|
||||
[
|
||||
'frontend/src/core/testing/serverExperienceSimulations.ts',
|
||||
'frontend/src/proprietary/testing/serverExperienceSimulations.ts'
|
||||
].each { path ->
|
||||
updateSimulationVersion(file(path), appVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('writeVersion', WriteProperties) {
|
||||
destinationFile = layout.projectDirectory.file('app/common/src/main/resources/version.properties')
|
||||
println "Writing version.properties to ${destinationFile.get().asFile.path}"
|
||||
@@ -314,7 +361,7 @@ tasks.named('bootRun') {
|
||||
tasks.named('build') {
|
||||
group = 'build'
|
||||
description = 'Delegates to :stirling-pdf:bootJar'
|
||||
dependsOn ':stirling-pdf:bootJar', 'buildRestartHelper'
|
||||
dependsOn ':stirling-pdf:bootJar', 'buildRestartHelper', 'syncAppVersion'
|
||||
|
||||
doFirst {
|
||||
println "Delegating to :stirling-pdf:bootJar"
|
||||
|
||||
Reference in New Issue
Block a user