commit df1ea716b488f526ea12c46dfe32f61c75dada7c Author: weissmall Date: Wed Nov 5 13:55:13 2025 +0300 initial commit diff --git a/release.config.cjs b/release.config.cjs new file mode 100644 index 0000000..887f9aa --- /dev/null +++ b/release.config.cjs @@ -0,0 +1,86 @@ +const { execSync } = require("child_process"); +const fs = require("fs"); + +function getCurrentOrigin() { + try { + const origin = execSync('git remote get-url origin', { encoding: 'utf8' }).trim(); + if (origin) { + return origin; + } + return null; + } catch (error) { + return null; + } +} + +function isJsProject() { + return fs.existsSync("package.json"); +} + +function getGitAssets() { + if (isJsProject()) { + return [ + 'CHANGELOG.md', + 'package.json', + ]; + } + return [ + 'CHANGELOG.md', + ] +} + +function getGitCurrentBranch() { + try { + const branch = execSync("git branch --show-current", { encoding: "utf-8" }).trim(); + if (branch) { + return branch; + } + return null; + } catch (error) { + return null; + } +} + +const defaultPlugins = [ + ['@semantic-release/commit-analyzer', { preset: 'conventionalcommits' }], + ['@semantic-release/release-notes-generator', { preset: 'conventionalcommits' }], + '@saithodev/semantic-release-gitea' +]; + +const releasePlugins = [ + ['@semantic-release/commit-analyzer', { preset: 'conventionalcommits' }], + ['@semantic-release/release-notes-generator', { preset: 'conventionalcommits' }], + ['@semantic-release/changelog', { changelogFile: 'CHANGELOG.md', changelogTitle: '# Changelog' }], + ["@semantic-release/npm", { "npmPublish": false }], + '@saithodev/semantic-release-gitea', + ['@semantic-release/git', { + assets: getGitAssets(), + message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}' + }], +]; + +let plugins; +const branch = getGitCurrentBranch(); + +const repositoryUrl = getCurrentOrigin(); +if (repositoryUrl == null) { + throw new Error("Failed to retreive origin url from system"); +} + +if (branch == "main" || branch == "master") { + plugins = releasePlugins; +} else { + plugins = defaultPlugins; +} + +module.exports = { + repositoryUrl, + branches: [ + 'main', + 'master', + { name: 'develop', prerelease: 'beta' }, + { name: 'release/*', prerelease: 'rc' }, + ], + tagFormat: 'v${version}', + plugins, +}; diff --git a/semantic.groovy b/semantic.groovy new file mode 100644 index 0000000..b2bd7d1 --- /dev/null +++ b/semantic.groovy @@ -0,0 +1,43 @@ +def downloadHelpers(path) { + sh "curl -L ${env.GIT_SCHEME}${env.GIT_HOST}/Jenkins/jenkins-tools/raw/branch/master/helpers.groovy -o $path" +} + +def semanticStage(String stageName, String containerName, Closure body) { + stage(stageName) { + container(containerName) { + sh "git config --global --add safe.directory \$(pwd)" + } + } +} + +def semanticExec(String giteaUrl) { + sh "GITEA_URL=${giteaUrl} semantic-release --ci" +} + +def semanticSyncDev(String currentBranch, String devBranch) { + if (currentBranch == "main" || currentBranch == "master") { + sh "git checkout ${devBranch}" + sh "git pull origin" + sh "git merge ${currentBranch} -m 'Merge versioning [skip ci]'" + sh "git push origin ${devBranch}" + sh "git checkout ${currentBranch}" + } +} + +def semantic(String stageName, String containerName, String giteaTokenCredId, String giteaCredId) { + semanticStage(stageName, containerName) { + withCredentials([ + usernamePassword(credentialsId: giteaCredId, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS'), + usernameColonPassword(credentialsId: giteaCredId, variable: 'GIT_CREDENTIALS'), + string(credentialsId: giteaTokenCredId, variable: "GITEA_TOKEN"), + ]) { + semanticExec() + semanticSyncDev() + } + } +} + +def semanticGetVersion() { + def version = sh(script: 'git describe --tags --abbrev=0', returnStdout: true).trim() + return version +}