feat: Started on updates and workflows

This commit is contained in:
Tickbase
2025-05-18 21:05:32 +02:00
parent 2376690230
commit e633524465
18 changed files with 7471 additions and 454 deletions

215
scripts/api-changelog.js Normal file
View File

@@ -0,0 +1,215 @@
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
// Define paths
const rustFilesPath = path.join(__dirname, '..', 'src-tauri')
function getApiDefinitions() {
// Get a list of all Rust files
const rustFiles = findRustFiles(rustFilesPath)
// Extract API functions and structs from Rust files
const apiDefinitions = {
commands: [],
structs: [],
}
rustFiles.forEach((filePath) => {
const content = fs.readFileSync(filePath, 'utf8')
// Find Tauri commands (API endpoints)
const commandRegex = /#\[tauri::command\]\s+(?:pub\s+)?(?:async\s+)?fn\s+([a-zA-Z0-9_]+)/g
let match
while ((match = commandRegex.exec(content)) !== null) {
apiDefinitions.commands.push({
name: match[1],
file: path.relative(rustFilesPath, filePath),
})
}
// Find structs that are likely part of the API
const structRegex = /#\[derive\(.*Serialize.*\)\]\s+(?:pub\s+)?struct\s+([a-zA-Z0-9_]+)/g
while ((match = structRegex.exec(content)) !== null) {
apiDefinitions.structs.push({
name: match[1],
file: path.relative(rustFilesPath, filePath),
})
}
})
return apiDefinitions
}
function findRustFiles(dir) {
let results = []
const list = fs.readdirSync(dir)
list.forEach((file) => {
const filePath = path.join(dir, file)
const stat = fs.statSync(filePath)
if (stat && stat.isDirectory() && file !== 'target') {
// Recursively search subdirectories, but skip the 'target' directory
results = results.concat(findRustFiles(filePath))
} else if (path.extname(file) === '.rs') {
// Add Rust files to the results
results.push(filePath)
}
})
return results
}
function compareApiDefinitions(oldApi, newApi) {
const changes = {
commands: {
added: [],
removed: [],
},
structs: {
added: [],
removed: [],
},
}
// Find added and removed commands
const oldCommandNames = oldApi.commands.map((cmd) => cmd.name)
const newCommandNames = newApi.commands.map((cmd) => cmd.name)
changes.commands.added = newApi.commands.filter((cmd) => !oldCommandNames.includes(cmd.name))
changes.commands.removed = oldApi.commands.filter((cmd) => !newCommandNames.includes(cmd.name))
// Find added and removed structs
const oldStructNames = oldApi.structs.map((struct) => struct.name)
const newStructNames = newApi.structs.map((struct) => struct.name)
changes.structs.added = newApi.structs.filter((struct) => !oldStructNames.includes(struct.name))
changes.structs.removed = oldApi.structs.filter((struct) => !newStructNames.includes(struct.name))
return changes
}
function updateChangelog(changes) {
const changelogPath = path.join(__dirname, '..', 'CHANGELOG.md')
let changelog = ''
// Create changelog if it doesn't exist
if (fs.existsSync(changelogPath)) {
changelog = fs.readFileSync(changelogPath, 'utf8')
} else {
changelog =
'# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
}
// Get the current version and date
const packageJson = require(path.join(__dirname, '..', 'package.json'))
const version = packageJson.version
const date = new Date().toISOString().split('T')[0]
// Create the new changelog entry
let newEntry = `## [${version}] - ${date}\n\n`
if (
changes.commands.added.length > 0 ||
changes.commands.removed.length > 0 ||
changes.structs.added.length > 0 ||
changes.structs.removed.length > 0
) {
newEntry += '### API Changes\n\n'
if (changes.commands.added.length > 0) {
newEntry += '#### New Commands\n\n'
changes.commands.added.forEach((cmd) => {
newEntry += `- \`${cmd.name}\` in \`${cmd.file}\`\n`
})
newEntry += '\n'
}
if (changes.commands.removed.length > 0) {
newEntry += '#### Removed Commands\n\n'
changes.commands.removed.forEach((cmd) => {
newEntry += `- \`${cmd.name}\` (was in \`${cmd.file}\`)\n`
})
newEntry += '\n'
}
if (changes.structs.added.length > 0) {
newEntry += '#### New Structures\n\n'
changes.structs.added.forEach((struct) => {
newEntry += `- \`${struct.name}\` in \`${struct.file}\`\n`
})
newEntry += '\n'
}
if (changes.structs.removed.length > 0) {
newEntry += '#### Removed Structures\n\n'
changes.structs.removed.forEach((struct) => {
newEntry += `- \`${struct.name}\` (was in \`${struct.file}\`)\n`
})
newEntry += '\n'
}
} else {
newEntry += 'No API changes in this release.\n\n'
}
// Add git commit information since last release
try {
// Get the latest tag
const latestTag = execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim()
// Get commits since the latest tag
const commits = execSync(`git log ${latestTag}..HEAD --pretty=format:"%h %s (%an)"`, {
encoding: 'utf8',
}).trim()
if (commits) {
newEntry += '### Other Changes\n\n'
// Split commits by line and add them to the changelog
commits.split('\n').forEach((commit) => {
newEntry += `- ${commit}\n`
})
newEntry += '\n'
}
} catch (error) {
// If there are no tags or other git issues, just continue without commit info
console.warn('Could not get git commit information:', error.message)
}
// Add the new entry to the changelog
if (changelog.includes('## [')) {
// Insert new entry after the first heading
changelog = changelog.replace('# Changelog\n\n', `# Changelog\n\n${newEntry}`)
} else {
// Append to the end if no existing versions
changelog += newEntry
}
// Write the updated changelog
fs.writeFileSync(changelogPath, changelog)
console.log(`Updated CHANGELOG.md with API changes for version ${version}`)
}
// Main execution
try {
// Check if we have a saved API definition
const apiCachePath = path.join(__dirname, '.api-cache.json')
let oldApi = { commands: [], structs: [] }
let newApi = getApiDefinitions()
if (fs.existsSync(apiCachePath)) {
oldApi = JSON.parse(fs.readFileSync(apiCachePath, 'utf8'))
}
// Compare and update the changelog
const changes = compareApiDefinitions(oldApi, newApi)
updateChangelog(changes)
// Save the new API definition for next time
fs.writeFileSync(apiCachePath, JSON.stringify(newApi, null, 2))
} catch (error) {
console.error('Error updating API changelog:', error)
process.exit(1)
}

View File

@@ -0,0 +1,82 @@
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
// Read the current version from package.json
const packageJson = require('../package.json')
const version = packageJson.version
console.log(`Current version: ${version}`)
// Get the current date in RFC 3339 format for pub_date
const pubDate = new Date().toISOString()
// Base URL where the assets will be available
const baseUrl = 'https://github.com/tickbase/creamlinux/releases/download'
const releaseTag = `v${version}`
const releaseUrl = `${baseUrl}/${releaseTag}`
// Create the updater JSON structure
const updaterJson = {
version,
notes: `Release version ${version}`,
pub_date: pubDate,
platforms: {
// Windows x64
'windows-x86_64': {
url: `${releaseUrl}/creamlinux-setup.exe`,
signature: readSignature('windows', 'creamlinux-setup.exe'),
},
// Linux x64
'linux-x86_64': {
url: `${releaseUrl}/creamlinux.AppImage`,
signature: readSignature('linux', 'creamlinux.AppImage'),
},
// macOS x64 and arm64 (universal)
'darwin-universal': {
url: `${releaseUrl}/creamlinux.app.tar.gz`,
signature: readSignature('macos', 'creamlinux.app.tar.gz'),
},
},
}
// Write the updater JSON file
fs.writeFileSync('latest.json', JSON.stringify(updaterJson, null, 2))
console.log('Created latest.json updater file')
// Helper function to read signature files
function readSignature(platform, filename) {
try {
// Determine path based on platform
let sigPath
switch (platform) {
case 'windows':
// Check both NSIS and MSI
try {
sigPath = path.join('src-tauri', 'target', 'release', 'bundle', 'nsis', `${filename}.sig`)
return fs.readFileSync(sigPath, 'utf8').trim()
} catch (e) {
sigPath = path.join('src-tauri', 'target', 'release', 'bundle', 'msi', `${filename}.sig`)
return fs.readFileSync(sigPath, 'utf8').trim()
}
case 'linux':
sigPath = path.join(
'src-tauri',
'target',
'release',
'bundle',
'appimage',
`${filename}.sig`
)
return fs.readFileSync(sigPath, 'utf8').trim()
case 'macos':
sigPath = path.join('src-tauri', 'target', 'release', 'bundle', 'macos', `${filename}.sig`)
return fs.readFileSync(sigPath, 'utf8').trim()
default:
throw new Error(`Unknown platform: ${platform}`)
}
} catch (error) {
console.error(`Error reading signature for ${platform}/${filename}:`, error.message)
return ''
}
}

29
scripts/sync-version.js Normal file
View File

@@ -0,0 +1,29 @@
const fs = require('fs')
const path = require('path')
// Read current version from package.json
const packageJsonPath = path.join(__dirname, '..', 'package.json')
const packageJson = require(packageJsonPath)
const version = packageJson.version
console.log(`Current version: ${version}`)
// Update Cargo.toml
const cargoTomlPath = path.join(__dirname, '..', 'src-tauri', 'Cargo.toml')
let cargoToml = fs.readFileSync(cargoTomlPath, 'utf8')
// Replace the version in Cargo.toml
cargoToml = cargoToml.replace(/version\s*=\s*"[^"]+"/m, `version = "${version}"`)
fs.writeFileSync(cargoTomlPath, cargoToml)
console.log(`Updated Cargo.toml version to ${version}`)
// Update tauri.conf.json
const tauriConfigPath = path.join(__dirname, '..', 'src-tauri', 'tauri.conf.json')
const tauriConfig = JSON.parse(fs.readFileSync(tauriConfigPath, 'utf8'))
// Set the version in tauri.conf.json
tauriConfig.version = version
fs.writeFileSync(tauriConfigPath, JSON.stringify(tauriConfig, null, 2))
console.log(`Updated tauri.conf.json version to ${version}`)
console.log('Version synchronization completed!')

View File

@@ -0,0 +1,42 @@
const fs = require('fs')
const path = require('path')
// Path to your tauri.conf.json file
const tauriConfigPath = path.join(__dirname, '..', 'src-tauri', 'tauri.conf.json')
// Read the current config
const rawConfig = fs.readFileSync(tauriConfigPath, 'utf8')
const config = JSON.parse(rawConfig)
// Add or update the updater configuration
if (!config.plugins) {
config.plugins = {}
}
// Get the public key from environment variable
const pubkey = process.env.TAURI_PUBLIC_KEY || ''
if (!pubkey) {
console.warn(
'Warning: TAURI_PUBLIC_KEY environment variable is not set. Updater will not work correctly!'
)
}
// Configure the updater plugin
config.plugins.updater = {
pubkey,
endpoints: ['https://github.com/tickbase/creamlinux/releases/latest/download/latest.json'],
}
// Configure bundle settings for updater artifacts
if (!config.bundle) {
config.bundle = {}
}
// Set createUpdaterArtifacts to true
config.bundle.createUpdaterArtifacts = true
// Write the updated config back to the file
fs.writeFileSync(tauriConfigPath, JSON.stringify(config, null, 2))
console.log('Tauri config updated with updater configuration')