forked from Nicxe/f1_sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (112 loc) · 5.05 KB
/
issue-version-check.yml
File metadata and controls
125 lines (112 loc) · 5.05 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Issue Version Check
on:
issues:
types: [opened]
permissions:
issues: write
jobs:
version-check:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'bug')
steps:
- name: Check reported version against latest release
uses: actions/github-script@v7
with:
script: |
const normalize = v => v.trim().replace(/^v/i, '');
const isBeta = v => /beta/i.test(v);
const ensureLabel = async (name, color, description) => {
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name,
color,
description,
});
} catch {
// Label already exists — ignore
}
};
const body = context.payload.issue.body || '';
const issueNumber = context.payload.issue.number;
const existingLabels = context.payload.issue.labels.map(l => l.name);
// Extract reported version from issue body
const versionMatch = body.match(/### F1 Sensor Version\s*\n+([^\n#]+)/);
if (!versionMatch) return;
const reportedVersion = normalize(versionMatch[1]);
if (!reportedVersion) return;
// Beta version — acknowledge as tester, skip outdated check
if (isBeta(reportedVersion)) {
if (existingLabels.includes('beta')) return;
await ensureLabel('beta', 'bfd4f2', 'Reported on a beta version');
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['beta'],
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'👋 Thanks for testing the beta and taking the time to report this!',
'',
`You're running **${reportedVersion}**, which is a pre-release version. Beta feedback is valuable and helps improve the integration before stable releases.`,
'',
'If this issue is affecting your day-to-day use of F1 Sensor, you can revert to the latest stable release via HACS at any time.',
'',
'**How to switch back to a stable release via HACS:**',
'1. Go to **HACS** in your Home Assistant sidebar',
'2. Find **F1 Sensor**, click **Download**, and select the latest stable version',
'3. Restart Home Assistant',
'',
'We\'ll look into this — thanks again for helping test!',
].join('\n'),
});
return;
}
// Stable version — skip if already labeled
if (existingLabels.includes('outdated-version')) return;
// Get latest release
let latestRelease;
try {
const { data } = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
latestRelease = data;
} catch {
// No releases yet — nothing to compare against
return;
}
const latestVersion = normalize(latestRelease.tag_name);
if (reportedVersion === latestVersion) return;
await ensureLabel('outdated-version', 'e4e669', 'Issue reported on an outdated version');
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['outdated-version'],
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
'👋 Thanks for the report!',
'',
`I noticed you're running version **${reportedVersion}**, but the latest release of F1 Sensor is **${latestVersion}**.`,
'',
'Please update to the latest version and check whether the issue still occurs — many problems are already fixed in newer releases.',
'',
'**How to update via HACS:**',
'1. Go to **HACS** in your Home Assistant sidebar',
'2. Find **F1 Sensor**, click **Download**, and select the latest version',
'3. Restart Home Assistant',
'',
'If the issue persists after updating, please comment here and we\'ll continue investigating.',
'If we don\'t hear back within **24 hours**, this issue will be automatically closed.',
].join('\n'),
});