Skip to content

Commit 368d901

Browse files
committed
ops(ci): conventional-commits based release versions
- added enforcing of conventional commits - project version is now set by axion-release gradle plugin, configured to extract the version based on the commit history see https://axion-release-plugin.readthedocs.io/en/latest/
1 parent 72f11e4 commit 368d901

File tree

3 files changed

+9
-248
lines changed

3 files changed

+9
-248
lines changed

.github/actions/detect-modified-projects/dist/index.js

Lines changed: 0 additions & 156 deletions
This file was deleted.

.github/actions/detect-modified-projects/src/index.ts

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,19 @@
1-
import { execSync } from 'child_process';
1+
import {execSync} from 'child_process';
22
import * as core from '@actions/core';
33

4-
function sh(cmd: string, opts: { silent?: boolean } = {}): string {
4+
function run() {
55
try {
6-
return execSync(cmd, { encoding: 'utf-8', stdio: opts.silent ? ['ignore', 'pipe', 'pipe'] : 'pipe' }).trim();
7-
} catch (e) {
8-
if (!opts.silent) core.debug(`Command failed: ${cmd}\n${String(e)}`);
9-
throw e;
10-
}
11-
}
12-
13-
function trySh(cmd: string, opts: { silent?: boolean } = {}): string {
14-
try {
15-
return sh(cmd, opts);
16-
} catch {
17-
return '';
18-
}
19-
}
6+
const subprojectPrefixes = core.getInput('project_prefixes')?.split(",") ?? [];
7+
const requiredProjects = core.getInput('required_projects')?.split(",") ?? [];
208

21-
function isShallowRepo(): boolean {
22-
const out = trySh('git rev-parse --is-shallow-repository', { silent: true });
23-
return out === 'true';
24-
}
25-
26-
function ensureHistoryAndTags(): void {
27-
// Detect shallow/non-shallow
28-
let isShallow: boolean;
29-
try {
30-
const out = execSync('git rev-parse --is-shallow-repository', { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
31-
isShallow = out === 'true';
32-
} catch {
33-
// If the command isn't supported (very old git), assume not shallow
34-
isShallow = false;
35-
}
36-
37-
core.info(`Repo shallow: ${isShallow}`);
38-
39-
if (isShallow) {
40-
// Shallow checkout → unshallow and fetch tags
41-
core.info('Fetching to unshallow repository and include tags…');
42-
execSync('git fetch --unshallow --tags --force', { encoding: 'utf-8' });
43-
} else {
44-
// Already complete → just refresh tags and prune
45-
core.info('Repository already complete; fetching tags and pruning…');
46-
execSync('git fetch --tags --force --prune', { encoding: 'utf-8' });
47-
}
48-
}
49-
/**
50-
* Determine a sensible base for diff:
51-
* - On pull_request events: origin/<base_branch>
52-
* - On push events: HEAD~1 (previous commit on same branch) if exists
53-
* - Fallback: merge-base with origin/main (adjust default if needed)
54-
*/
55-
function resolveBaseRef(): string {
56-
const eventName = process.env.GITHUB_EVENT_NAME || '';
57-
const prBase = process.env.GITHUB_BASE_REF; // set on pull_request events
58-
if (eventName.startsWith('pull_request') && prBase) {
59-
core.info(`PR build detected. Using origin/${prBase} as diff base`);
60-
// Ensure we have the PR base
61-
trySh(`git fetch origin ${prBase} --force`, { silent: true });
62-
return `origin/${prBase}`;
63-
}
64-
65-
// Push builds: previous commit if available
66-
const prev = trySh('git rev-parse HEAD~1', { silent: true });
67-
if (prev) {
68-
core.info('Push build detected. Using HEAD~1 as diff base');
69-
return prev;
70-
}
71-
72-
// Fallback: merge-base with origin/main (change "main" if your default is different)
73-
core.info('Fallback diff base: merge-base with origin/main');
74-
trySh('git fetch origin main --force', { silent: true });
75-
const mergeBase = trySh('git merge-base HEAD origin/main', { silent: true });
76-
return mergeBase || 'HEAD';
77-
}
78-
79-
function run(): void {
80-
try {
81-
const subprojectPrefixes = (core.getInput('project_prefixes') || '')
82-
.split(',')
83-
.map(s => s.trim())
84-
.filter(Boolean);
85-
const requiredProjects = (core.getInput('required_projects') || '')
86-
.split(',')
87-
.map(s => s.trim())
88-
.filter(Boolean);
89-
90-
core.debug('Ensuring full history and tags…');
91-
ensureHistoryAndTags();
9+
core.debug("executing git fetch");
10+
execSync('git fetch --unshallow', {encoding: 'utf-8'});
9211

9312
const githubSha = process.env.GITHUB_SHA;
9413
if (!githubSha) {
95-
core.setFailed('GITHUB_SHA not set');
96-
return;
14+
core.setFailed('GITHUB_SHA not set')
9715
}
98-
99-
const base = resolveBaseRef();
100-
const diffCmd = `git diff --name-only ${base}..${githubSha}`;
16+
const diffCmd = `git diff --name-only HEAD~1..${githubSha}`;
10117

10218
core.debug(`Executing: ${diffCmd}`);
10319
core.debug(`Git Status: ${execSync(`git status`, {encoding: 'utf-8'}).trim()}`);

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ plugins {
2828

2929
// set version based on conventional commit history
3030
scmVersion {
31+
unshallowRepoOnCI.set(true)
3132
tag {
3233
prefix.set("v")
3334
versionSeparator.set("")

0 commit comments

Comments
 (0)