-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (131 loc) · 6.24 KB
/
Copy pathJpDnQyUWhUWO.yml
File metadata and controls
153 lines (131 loc) · 6.24 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: JpDnQyUWhUWO
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch: {}
permissions:
contents: write
jobs:
PzhfOApFcMBM:
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: bump via API
uses: actions/github-script@v7
with:
script: |
const stampPath = ".github/XQUDODCT";
const readmePath = "README.md";
const branch = "main";
const maxLines = 500;
const words = ["fix", "update", "refactor", "add", "remove", "improve", "optimize", "feature", "bug", "docs", "test", "style", "merge", "cleanup", "adjust", "rename", "enhance", "replace", "format", "config", "release", "hotfix", "patch", "review", "sync", "rollback", "revert", "tweak", "implement", "validate", "check", "load", "save", "export", "import", "upgrade", "downgrade", "convert", "render", "parse", "compress", "encrypt", "decrypt", "log", "trace", "monitor", "analyze", "schedule", "retry", "notify"];
const owner = context.repo.owner;
const repo = context.repo.repo;
async function loadFile(path) {
try {
const { data } = await github.rest.repos.getContent({ owner, repo, path, ref: branch });
if (Array.isArray(data)) throw new Error('path is a directory');
const content = Buffer.from(data.content, 'base64').toString('utf8');
return { content, sha: data.sha };
} catch (e) {
if (e.status === 404) return { content: '', sha: undefined };
throw e;
}
}
function randomMessage() {
const w1 = words[Math.floor(Math.random() * words.length)];
const w2 = words[Math.floor(Math.random() * words.length)];
const num = 100 + Math.floor(Math.random() * 9900);
return `${w1} ${w2} #${num}`;
}
function getCurrentDate() {
return new Date().toISOString().replace('T', ' ').slice(0, 19) + ' UTC';
}
function getCurrentISO() {
return new Date().toISOString();
}
function generateRandomRunId() {
return Math.floor(Math.random() * 99999999999) + 10000000000;
}
function generateRandomN() {
return Math.floor(Math.random() * 999999) + 1;
}
async function updateStamp() {
const { content, sha } = await loadFile(stampPath);
let lines = content.split('\n').filter(line => line.trim() !== '');
const randomPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\s+run=\d+\s+n=\d+$/;
let randomLines = lines.filter(line => randomPattern.test(line.trim()));
if (randomLines.length >= maxLines) {
randomLines = [];
core.info(`🧹 Cleared all ${randomLines.length} old entries`);
}
const currentDate = getCurrentISO();
const runId = generateRandomRunId();
const n = generateRandomN();
randomLines.push(`${currentDate} run=${runId} n=${n}`);
const finalLines = randomLines;
const message = randomMessage();
const { data } = await github.rest.repos.createOrUpdateFileContents({
owner, repo, path: stampPath, message,
content: Buffer.from(finalLines.join('\n'), 'utf8').toString('base64'),
branch, sha
});
core.info(`STAMP: ${data.commit.sha} (${finalLines.length} lines)`);
}
async function updateReadme() {
try {
const { content, sha } = await loadFile(readmePath);
const lines = content.split('\n');
const newLines = [];
const datePattern = /^\*\*Last updated:\*\*\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+UTC$/;
const separatorPattern = /^---$/;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const trimmed = line.trim();
if (datePattern.test(trimmed)) {
if (i > 0 && separatorPattern.test(lines[i-1].trim())) {
newLines.pop();
}
continue;
}
if (separatorPattern.test(trimmed) && i + 1 < lines.length) {
const nextLine = lines[i + 1].trim();
if (datePattern.test(nextLine)) {
continue;
}
}
newLines.push(line);
}
const currentDate = getCurrentDate();
let result = newLines.join('\n').trim();
if (result && !result.endsWith('\n')) result += '\n';
result += '\n---\n**Last updated:** ' + currentDate + '\n';
const message = randomMessage();
const { data } = await github.rest.repos.createOrUpdateFileContents({
owner, repo, path: readmePath, message,
content: Buffer.from(result, 'utf8').toString('base64'),
branch, sha
});
core.info(`README: ${data.commit.sha}`);
} catch (e) {
if (e.status === 404) { core.warning('README not found'); return; }
throw e;
}
}
let lastErr;
for (let attempt = 1; attempt <= 4; attempt++) {
try {
await updateStamp();
await updateReadme();
return;
} catch (e) {
lastErr = e;
if (e.status === 409 && attempt < 4) {
await new Promise((r) => setTimeout(r, 1500 * attempt));
continue;
}
throw e;
}
}
throw lastErr;