ci: ignore new releases triggered only by renovate (#916)

This commit is contained in:
Almeida
2024-03-18 20:52:38 +00:00
committed by GitHub
parent 22e6bafd39
commit 1377730766

View File

@@ -1,20 +1,48 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
import { execSync } from 'node:child_process';
import { execSync, spawnSync } from 'node:child_process';
import process from 'node:process';
import { Octokit } from '@octokit/action';
import conventionalRecommendedBump from 'conventional-recommended-bump';
const IGNORED_COMMIT_AUTHORS = ['renovate[bot]'];
const RELEASE_COMMIT_PREFIX = 'chore(release):';
console.log('🚀 Running the release script...');
const lastCommitMessage = execSync('git log -1 --pretty=%B', { encoding: 'utf8' });
console.log(` Last commit message: ${lastCommitMessage}`);
if (lastCommitMessage.startsWith('chore(release)')) {
if (lastCommitMessage.startsWith(RELEASE_COMMIT_PREFIX)) {
console.log('Preventing the action from completing as there are no new commits to release.');
process.exit(1);
}
const lastReleaseCommitHash = execSync(`git log -1 --grep="${RELEASE_COMMIT_PREFIX}" --pretty=%H`, {
encoding: 'utf8',
});
if (lastReleaseCommitHash) {
console.log(` Last release commit hash: ${lastReleaseCommitHash}`);
const commitAuthorsAfterLastReleaseProcess = spawnSync(
'git',
['log', `${lastReleaseCommitHash.trim()}..HEAD`, '--pretty=%an'],
{ encoding: 'utf8' },
);
const commitAuthorsAfterLastRelease = commitAuthorsAfterLastReleaseProcess.stdout.split('\n').filter(Boolean);
console.log(` Authors after the last release: ${commitAuthorsAfterLastRelease.join(', ')}`);
if (commitAuthorsAfterLastRelease.every((author) => IGNORED_COMMIT_AUTHORS.includes(author))) {
console.log(
'Preventing the action from completing as all commits after the last release were made by ignored authors.',
);
process.exit(1);
}
}
const conventionalReleaseTypesTo0Ver = new Map([
['major', 'minor'],
['minor', 'patch'],
@@ -64,7 +92,7 @@ const pullRequests = await octokit.pulls.list({
const previousPullRequest = pullRequests.data.find(
// Find release PRs made by GitHub actions
({ title, user }) => title.startsWith(`chore(release):`) && user?.id === 41_898_282,
({ title, user }) => title.startsWith(RELEASE_COMMIT_PREFIX) && user?.id === 41_898_282,
);
if (previousPullRequest) {