Skip to content

Commit ff8808c

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 a55eadd commit ff8808c

File tree

2 files changed

+176
-78
lines changed

2 files changed

+176
-78
lines changed

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

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,97 @@ var __importStar = (this && this.__importStar) || function (mod) {
2525
Object.defineProperty(exports, "__esModule", { value: true });
2626
const child_process_1 = require("child_process");
2727
const core = __importStar(require("@actions/core"));
28+
function sh(cmd) {
29+
return (0, child_process_1.execSync)(cmd, { encoding: 'utf-8' }).trim();
30+
}
31+
function trySh(cmd) {
32+
try {
33+
return sh(cmd);
34+
}
35+
catch {
36+
return '';
37+
}
38+
}
39+
/**
40+
* Determine a sensible base for diff:
41+
* - On pull_request events: origin/<base_branch>
42+
* - On push events: HEAD~1 (previous commit on same branch) if it exists
43+
* - Fallback: merge-base with origin/main (adjust default branch name if needed)
44+
*/
45+
function resolveBaseRef() {
46+
const eventName = process.env.GITHUB_EVENT_NAME || '';
47+
const prBase = process.env.GITHUB_BASE_REF; // set on pull_request events
48+
if (eventName.startsWith('pull_request') && prBase) {
49+
// Ensure we have the PR base locally
50+
trySh(`git fetch origin ${prBase} --force`);
51+
return `origin/${prBase}`;
52+
}
53+
// Push builds: previous commit if available
54+
const prev = trySh('git rev-parse HEAD~1');
55+
if (prev)
56+
return prev;
57+
// Fallback: merge-base with origin/main (change "main" if your default is different)
58+
trySh('git fetch origin main --force');
59+
const mergeBase = trySh('git merge-base HEAD origin/main');
60+
return mergeBase || 'HEAD';
61+
}
2862
function run() {
29-
var _a, _b, _c, _d;
63+
var _a;
3064
try {
31-
const subprojectPrefixes = (_b = (_a = core.getInput('project_prefixes')) === null || _a === void 0 ? void 0 : _a.split(",")) !== null && _b !== void 0 ? _b : [];
32-
const requiredProjects = (_d = (_c = core.getInput('required_projects')) === null || _c === void 0 ? void 0 : _c.split(",")) !== null && _d !== void 0 ? _d : [];
33-
core.debug("executing git fetch");
34-
(0, child_process_1.execSync)('git fetch --unshallow', { encoding: 'utf-8' });
65+
const subprojectPrefixes = (core.getInput('project_prefixes') || '')
66+
.split(',')
67+
.map(s => s.trim())
68+
.filter(Boolean);
69+
const requiredProjects = (core.getInput('required_projects') || '')
70+
.split(',')
71+
.map(s => s.trim())
72+
.filter(Boolean);
73+
// We assume Actions checkout used fetch-depth: 0 and fetch-tags: true.
74+
// Only refresh tags/prune; do NOT attempt to unshallow here.
75+
trySh('git fetch --tags --force --prune');
3576
const githubSha = process.env.GITHUB_SHA;
3677
if (!githubSha) {
3778
core.setFailed('GITHUB_SHA not set');
79+
return;
3880
}
39-
const diffCmd = `git diff --name-only HEAD~1..${githubSha}`;
81+
const base = resolveBaseRef();
82+
const diffCmd = `git diff --name-only ${base}..${githubSha}`;
4083
core.debug(`Executing: ${diffCmd}`);
41-
core.debug(`Git Status: ${(0, child_process_1.execSync)(`git status`, { encoding: 'utf-8' }).trim()}`);
42-
core.debug(`SHA Exists: ${(0, child_process_1.execSync)(`git cat-file -e ${githubSha}`, { encoding: 'utf-8' }).trim()}`);
43-
let modifiedProjects = (0, child_process_1.execSync)(diffCmd, { encoding: 'utf8' });
44-
core.debug("Modified Projects:" + modifiedProjects);
45-
core.debug("Required Projects:" + requiredProjects);
46-
if (modifiedProjects.includes('buildSrc/') && !modifiedProjects.includes('ktor-')) {
47-
core.debug("only buildSrc has modified");
48-
modifiedProjects = "buildSrc";
84+
core.debug(`Git Status:\n${trySh('git status')}`);
85+
const changed = trySh(diffCmd);
86+
core.debug('Changed files:\n' + (changed || '(none)'));
87+
core.debug('Required Projects: ' + JSON.stringify(requiredProjects));
88+
let modifiedProjects = '';
89+
if (changed.includes('buildSrc/') && !changed.includes('ktor-')) {
90+
core.debug('Only buildSrc modified → limiting to buildSrc');
91+
modifiedProjects = 'buildSrc';
4992
}
5093
else {
51-
const subprojectPrefixesPattern = subprojectPrefixes.join("|");
52-
core.debug("subprojectPrefixesPattern: " + subprojectPrefixesPattern);
53-
const regex = subprojectPrefixes.length > 0
54-
? new RegExp(`^(${subprojectPrefixesPattern})`)
55-
: null;
56-
let modifiedProjectsArray = modifiedProjects.split('\n')
57-
.filter(line => {
58-
return regex ? regex.test(line) : true;
59-
})
60-
.map(line => line.split('/', 1)[0])
94+
const pattern = subprojectPrefixes.join('|');
95+
core.debug('subprojectPrefixesPattern: ' + pattern);
96+
const regex = subprojectPrefixes.length > 0 ? new RegExp(`^(${pattern})`) : null;
97+
const modifiedProjectsArray = changed
98+
.split('\n')
99+
.filter(Boolean)
100+
.filter(line => (regex ? regex.test(line) : true))
101+
.map(line => line.split('/', 1)[0]) // project dir
102+
.filter(Boolean)
61103
.sort()
62-
.filter((value, index, self) => self.indexOf(value) === index);
63-
modifiedProjects = [...new Set(modifiedProjectsArray.concat(requiredProjects))].join(',');
104+
.filter((v, i, a) => a.indexOf(v) === i); // uniq
105+
const merged = Array.from(new Set([...modifiedProjectsArray, ...requiredProjects]));
106+
modifiedProjects = merged.join(',');
64107
}
65108
if (modifiedProjects) {
66-
core.info(`Modified subprojects including required projects: ${modifiedProjects}`);
109+
core.info(`Modified subprojects (including required): ${modifiedProjects}`);
67110
core.setOutput('modified_projects', modifiedProjects);
68111
}
69112
else {
70-
core.info("No modified subprojects");
113+
core.info('No modified subprojects');
114+
core.setOutput('modified_projects', '');
71115
}
72116
}
73117
catch (error) {
74-
core.setFailed(`Action failed with error: ${error}`);
118+
core.setFailed(`Action failed with error: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : String(error)}`);
75119
}
76120
}
77121
run();
Lines changed: 103 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,109 @@
1-
import {execSync} from 'child_process';
1+
import { execSync } from 'child_process';
22
import * as core from '@actions/core';
33

4-
function run() {
5-
try {
6-
const subprojectPrefixes = core.getInput('project_prefixes')?.split(",") ?? [];
7-
const requiredProjects = core.getInput('required_projects')?.split(",") ?? [];
8-
9-
core.debug("executing git fetch");
10-
execSync('git fetch --unshallow', {encoding: 'utf-8'});
11-
12-
const githubSha = process.env.GITHUB_SHA;
13-
if (!githubSha) {
14-
core.setFailed('GITHUB_SHA not set')
15-
}
16-
const diffCmd = `git diff --name-only HEAD~1..${githubSha}`;
17-
18-
core.debug(`Executing: ${diffCmd}`);
19-
core.debug(`Git Status: ${execSync(`git status`, {encoding: 'utf-8'}).trim()}`);
20-
core.debug(`SHA Exists: ${execSync(`git cat-file -e ${githubSha}`, {encoding: 'utf-8'}).trim()}`);
21-
22-
let modifiedProjects = execSync(diffCmd, {encoding: 'utf8'});
23-
core.debug("Modified Projects:" + modifiedProjects)
24-
core.debug("Required Projects:" + requiredProjects)
25-
if (modifiedProjects.includes('buildSrc/') && !modifiedProjects.includes('ktor-')) {
26-
core.debug("only buildSrc has modified");
27-
modifiedProjects = "buildSrc";
28-
} else {
29-
const subprojectPrefixesPattern = subprojectPrefixes.join("|")
30-
core.debug("subprojectPrefixesPattern: " + subprojectPrefixesPattern);
31-
const regex = subprojectPrefixes.length > 0
32-
? new RegExp(`^(${subprojectPrefixesPattern})`)
33-
: null;
34-
let modifiedProjectsArray = modifiedProjects.split('\n')
35-
.filter(line => {
36-
return regex ? regex.test(line) : true;
37-
})
38-
.map(line => line.split('/', 1)[0])
39-
.sort()
40-
.filter((value, index, self) => self.indexOf(value) === index)
41-
modifiedProjects = [...new Set(modifiedProjectsArray.concat(requiredProjects))].join(',');
42-
}
43-
if (modifiedProjects) {
44-
core.info(`Modified subprojects including required projects: ${modifiedProjects}`);
45-
core.setOutput('modified_projects', modifiedProjects);
46-
} else {
47-
core.info("No modified subprojects");
48-
}
49-
50-
} catch (error) {
51-
core.setFailed(`Action failed with error: ${error}`);
4+
function sh(cmd: string): string {
5+
return execSync(cmd, { encoding: 'utf-8' }).trim();
6+
}
7+
8+
function trySh(cmd: string): string {
9+
try {
10+
return sh(cmd);
11+
} catch {
12+
return '';
13+
}
14+
}
15+
16+
/**
17+
* Determine a sensible base for diff:
18+
* - On pull_request events: origin/<base_branch>
19+
* - On push events: HEAD~1 (previous commit on same branch) if it exists
20+
* - Fallback: merge-base with origin/main (adjust default branch name if needed)
21+
*/
22+
function resolveBaseRef(): string {
23+
const eventName = process.env.GITHUB_EVENT_NAME || '';
24+
const prBase = process.env.GITHUB_BASE_REF; // set on pull_request events
25+
26+
if (eventName.startsWith('pull_request') && prBase) {
27+
// Ensure we have the PR base locally
28+
trySh(`git fetch origin ${prBase} --force`);
29+
return `origin/${prBase}`;
30+
}
31+
32+
// Push builds: previous commit if available
33+
const prev = trySh('git rev-parse HEAD~1');
34+
if (prev) return prev;
35+
36+
// Fallback: merge-base with origin/main (change "main" if your default is different)
37+
trySh('git fetch origin main --force');
38+
const mergeBase = trySh('git merge-base HEAD origin/main');
39+
return mergeBase || 'HEAD';
40+
}
41+
42+
function run(): void {
43+
try {
44+
const subprojectPrefixes = (core.getInput('project_prefixes') || '')
45+
.split(',')
46+
.map(s => s.trim())
47+
.filter(Boolean);
48+
const requiredProjects = (core.getInput('required_projects') || '')
49+
.split(',')
50+
.map(s => s.trim())
51+
.filter(Boolean);
52+
53+
// We assume Actions checkout used fetch-depth: 0 and fetch-tags: true.
54+
// Only refresh tags/prune; do NOT attempt to unshallow here.
55+
trySh('git fetch --tags --force --prune');
56+
57+
const githubSha = process.env.GITHUB_SHA;
58+
if (!githubSha) {
59+
core.setFailed('GITHUB_SHA not set');
60+
return;
61+
}
62+
63+
const base = resolveBaseRef();
64+
const diffCmd = `git diff --name-only ${base}..${githubSha}`;
65+
66+
core.debug(`Executing: ${diffCmd}`);
67+
core.debug(`Git Status:\n${trySh('git status')}`);
68+
69+
const changed = trySh(diffCmd);
70+
core.debug('Changed files:\n' + (changed || '(none)'));
71+
core.debug('Required Projects: ' + JSON.stringify(requiredProjects));
72+
73+
let modifiedProjects = '';
74+
75+
if (changed.includes('buildSrc/') && !changed.includes('ktor-')) {
76+
core.debug('Only buildSrc modified → limiting to buildSrc');
77+
modifiedProjects = 'buildSrc';
78+
} else {
79+
const pattern = subprojectPrefixes.join('|');
80+
core.debug('subprojectPrefixesPattern: ' + pattern);
81+
82+
const regex = subprojectPrefixes.length > 0 ? new RegExp(`^(${pattern})`) : null;
83+
84+
const modifiedProjectsArray = changed
85+
.split('\n')
86+
.filter(Boolean)
87+
.filter(line => (regex ? regex.test(line) : true))
88+
.map(line => line.split('/', 1)[0]) // project dir
89+
.filter(Boolean)
90+
.sort()
91+
.filter((v, i, a) => a.indexOf(v) === i); // uniq
92+
93+
const merged = Array.from(new Set([...modifiedProjectsArray, ...requiredProjects]));
94+
modifiedProjects = merged.join(',');
95+
}
96+
97+
if (modifiedProjects) {
98+
core.info(`Modified subprojects (including required): ${modifiedProjects}`);
99+
core.setOutput('modified_projects', modifiedProjects);
100+
} else {
101+
core.info('No modified subprojects');
102+
core.setOutput('modified_projects', '');
52103
}
104+
} catch (error: any) {
105+
core.setFailed(`Action failed with error: ${error?.message ?? String(error)}`);
106+
}
53107
}
54108

55109
run();

0 commit comments

Comments
 (0)