initial commit
This commit is contained in:
commit
df1ea716b4
86
release.config.cjs
Normal file
86
release.config.cjs
Normal file
@ -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,
|
||||||
|
};
|
||||||
43
semantic.groovy
Normal file
43
semantic.groovy
Normal file
@ -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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user