mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-09 00:07:33 -06:00
Use @actions/core for error annotations, try/catch wrapper for checklist
This commit is contained in:
63
.github/workflows/checklist.yaml
vendored
63
.github/workflows/checklist.yaml
vendored
@@ -10,37 +10,46 @@ jobs:
|
|||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
const core = require('@actions/core');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = 'CHANGELOG.md';
|
const path = 'CHANGELOG.md';
|
||||||
const changelog = fs.readFileSync(path, 'utf8');
|
const changelog = fs.readFileSync(path, 'utf8');
|
||||||
const errors = [];
|
let failed = false;
|
||||||
|
|
||||||
// Check each line that starts with '##' for the version & date format
|
try {
|
||||||
changelog.split('\n').forEach((line, index) => {
|
// Check each line that starts with '##' for the version & date format
|
||||||
index += 1;
|
changelog.split('\n').forEach((line, index) => {
|
||||||
|
index += 1;
|
||||||
|
|
||||||
if (!line.startsWith('## '))
|
if (!line.startsWith('## '))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (line.toLowerCase().includes('unreleased')) {
|
if (line.toLowerCase().includes('unreleased')) {
|
||||||
const message = `Unreleased section found at line ${index}: ${line}`;
|
core.error({
|
||||||
const command = `::error file=${path},line=${index},endLine=${index},title=Unreleased Section Found::${message}`;
|
title: 'Unreleased Section Found',
|
||||||
console.log(command);
|
file: path,
|
||||||
errors.push(message);
|
startline: index,
|
||||||
|
});
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expected format: '## [X.Y.Z] - YYYY-MM-DD'
|
||||||
|
const pattern = /^\d+\.\d+\.\d+ - \d{4}-\d{2}-\d{2}$/;
|
||||||
|
if (pattern.test(line)) {
|
||||||
|
core.error({
|
||||||
|
title: 'Invalid Version/Date Format',
|
||||||
|
file: path,
|
||||||
|
startline: index,
|
||||||
|
});
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
|
core.setFailed('Changelog validation failed')
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
// Expected format: '## [X.Y.Z] - YYYY-MM-DD'
|
core.setFailed(`Exception occurred while validating changelog: ${error}`);
|
||||||
const pattern = /^\d+\.\d+\.\d+ - \d{4}-\d{2}-\d{2}$/;
|
|
||||||
if (pattern.test(line)) {
|
|
||||||
const message = `Invalid version/date format at line ${index}: ${line}`;
|
|
||||||
const command = `::error file=${path},line=${index},endLine=${index},title=Invalid Version/Date Format::${message}`;
|
|
||||||
console.log(command);
|
|
||||||
errors.push(message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (errors.length > 0) {
|
|
||||||
throw new Error(errors.join('\n'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draft:
|
draft:
|
||||||
@@ -50,14 +59,12 @@ jobs:
|
|||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
|
const core = require('@actions/core')
|
||||||
const forbiddenLabels = ['draft'];
|
const forbiddenLabels = ['draft'];
|
||||||
let labels = context.payload.pull_request.labels;
|
let labels = context.payload.pull_request.labels;
|
||||||
|
|
||||||
if (labels.some(l => forbiddenLabels.includes(l.name))) {
|
if (labels.some(l => forbiddenLabels.includes(l.name))) {
|
||||||
const message = `Forbidden labels detected: ${forbiddenLabels.join(', ')}`;
|
core.setFailed(`Forbidden labels detected: ${forbiddenLabels.join(', ')}`);
|
||||||
const command = `::error file=${__filename},line=1,endLine=1,title=Forbidden Labels Detected::${message}`;
|
|
||||||
console.log(command);
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user