-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
110 lines (86 loc) · 3.63 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: "Changelog Check"
description: "Run a changelog check"
author: "Graylog, Inc. <[email protected]>"
inputs:
gh-token:
description: "GitHub access token"
required: false
cli-version:
description: "Version of the graylog-project CLI command"
required: true
default: "latest"
runs:
using: "composite"
steps:
- name: "Check changelog presence"
uses: "actions/github-script@v6"
id: "check-presence"
with:
script: |
const fs = require('node:fs');
const path = require('node:path');
const pr = context.payload.pull_request;
const author = pr.user.login;
const setSummary = (title, text, files = []) => {
core.summary.addHeading(title, 2);
core.summary.addRaw(`<p>${text}</p>`, true);
if (files.length > 0) {
core.summary.addRaw(`<p>Files:</p>`);
core.summary.addList(files.map(f => `<code>${f}</code>`));
}
core.summary.write({ overwrite: true });
};
if (author.includes('dependabot') || author.includes('github-actions')) {
setSummary('Changelog Check Skipped', `Check skipped because the PR author is a bot user. (author: ${author})`);
return;
}
const body = pr.body || "";
if (body.includes('/nocl')) {
setSummary('Changelog Check Skipped', 'Check skipped because of /nocl flag.');
return;
}
const owner = pr.base.repo.owner.login;
const repo = pr.base.repo.name;
const baseRef = `${pr.base.repo.owner.login}:${pr.base.sha}`;
const headRef = `${pr.head.repo.owner.login}:${pr.head.sha}`;
console.log(`Getting changed files for ${owner}/${repo}: ${baseRef}...${headRef}`);
const response = await github.rest.repos.compareCommitsWithBasehead({
owner: owner,
repo: repo,
basehead: `${baseRef}...${headRef}`,
});
const clFiles = response.data.files
.filter(f => f.filename.startsWith('changelog/'))
.filter(f => f.status !== 'removed')
.map(f => f.filename);
if (clFiles.length === 0) {
const msg = 'The PR does not contain a changelog entry file.';
setSummary('Failure', msg);
core.setFailed(msg);
} else {
setSummary('Success', 'At least one changelog entry file is present.', clFiles);
const clFilesPath = path.join(process.env.RUNNER_TEMP, 'changelog-files');
fs.mkdirSync(clFilesPath, 0o700);
core.setOutput('changelog_path', clFilesPath);
clFiles.forEach(async (file) => {
const outputPath = path.join(clFilesPath, path.basename(file));
console.log(`Downloading ${file} into ${outputPath}`);
const response = await github.rest.repos.getContent({
owner: owner,
repo: repo,
path: file,
ref: pr.head.sha,
});
const text = Buffer.from(response.data.content, 'base64').toString('utf-8');
fs.writeFileSync(outputPath, text, {mode: 0o600});
});
}
- name: "Install graylog-project CLI (version: ${{ inputs.cli-version }})"
uses: "Graylog2/actions/project-cli@main"
with:
cli-version: "${{ inputs.cli-version }}"
- name: "Run changelog linter"
if: steps.check-presence.outputs.changelog_path
shell: "bash"
run: |
graylog-project changelog lint --strict ${{ steps.check-presence.outputs.changelog_path }}