Skip to content

Commit 098c691

Browse files
author
smkc
committed
ci: add daily ksef-docs release watcher with deduplicated issues
1 parent 6594b3a commit 098c691

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Watch ksef-docs releases
2+
3+
on:
4+
schedule:
5+
# Once per day (UTC)
6+
- cron: "0 6 * * *"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
13+
jobs:
14+
create-issue-on-new-release:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check latest ksef-docs release and create issue once per version
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const sourceOwner = "CIRFMF";
22+
const sourceRepo = "ksef-docs";
23+
24+
const targetOwner = context.repo.owner;
25+
const targetRepo = context.repo.repo;
26+
27+
async function getLatestVersion() {
28+
try {
29+
const { data } = await github.rest.repos.getLatestRelease({
30+
owner: sourceOwner,
31+
repo: sourceRepo,
32+
});
33+
return {
34+
version: (data.tag_name || data.name || "").trim(),
35+
htmlUrl: data.html_url,
36+
publishedAt: data.published_at || null,
37+
};
38+
} catch (error) {
39+
// Fallback for repos without formal releases: use latest tag.
40+
if (error.status !== 404) throw error;
41+
const { data } = await github.rest.repos.listTags({
42+
owner: sourceOwner,
43+
repo: sourceRepo,
44+
per_page: 1,
45+
});
46+
if (!data.length) {
47+
core.info("No releases/tags found in source repository.");
48+
return null;
49+
}
50+
return {
51+
version: (data[0].name || "").trim(),
52+
htmlUrl: `https://github.com/${sourceOwner}/${sourceRepo}/releases`,
53+
publishedAt: null,
54+
};
55+
}
56+
}
57+
58+
const latest = await getLatestVersion();
59+
if (!latest || !latest.version) {
60+
core.info("No version found, skipping.");
61+
return;
62+
}
63+
64+
const marker = `<!-- ksef-docs-release:${latest.version} -->`;
65+
const issueTitle = `ksef-docs: nowy release ${latest.version}`;
66+
const labelName = "ksef-docs-release";
67+
68+
// Ensure label exists.
69+
try {
70+
await github.rest.issues.getLabel({
71+
owner: targetOwner,
72+
repo: targetRepo,
73+
name: labelName,
74+
});
75+
} catch (error) {
76+
if (error.status !== 404) throw error;
77+
await github.rest.issues.createLabel({
78+
owner: targetOwner,
79+
repo: targetRepo,
80+
name: labelName,
81+
color: "1D76DB",
82+
description: "Tracking new releases in CIRFMF/ksef-docs",
83+
});
84+
}
85+
86+
// Search all issues (open + closed) to avoid duplicates forever for the same version.
87+
const existingIssues = await github.paginate(github.rest.issues.listForRepo, {
88+
owner: targetOwner,
89+
repo: targetRepo,
90+
state: "all",
91+
per_page: 100,
92+
labels: labelName,
93+
});
94+
95+
const duplicate = existingIssues.find((issue) => {
96+
if (issue.pull_request) return false;
97+
const body = issue.body || "";
98+
return body.includes(marker);
99+
});
100+
101+
if (duplicate) {
102+
core.info(`Issue already exists for ${latest.version}: #${duplicate.number}`);
103+
return;
104+
}
105+
106+
const bodyLines = [
107+
`Wykryto nowy release w \`${sourceOwner}/${sourceRepo}\`: **${latest.version}**.`,
108+
"",
109+
`Źródło: ${latest.htmlUrl}`,
110+
latest.publishedAt ? `Data publikacji: ${latest.publishedAt}` : null,
111+
"",
112+
"Checklist:",
113+
"- [ ] Przejrzeć changelog/release notes",
114+
"- [ ] Ocenić wpływ na SDK i CLI",
115+
"- [ ] Zaplanować ewentualne zmiany",
116+
"",
117+
marker,
118+
].filter(Boolean);
119+
120+
const created = await github.rest.issues.create({
121+
owner: targetOwner,
122+
repo: targetRepo,
123+
title: issueTitle,
124+
body: bodyLines.join("\n"),
125+
labels: [labelName],
126+
});
127+
128+
core.info(`Created issue #${created.data.number} for version ${latest.version}`);

0 commit comments

Comments
 (0)