Skip to content

Commit 973ec63

Browse files
committed
add-entry.js: optionally allow "back-filling" missing releases
There has been a problem with the `upload-snapshot` workflow, fixed in git-for-windows/gfw-helper-github-app#128, that prevented the v2.49.0-rc* releases from being added. I manually ran the automation for -rc2, but for -rc0 and -rc1 I want to use a different approach: I want to cross-link to the existing releases in `git-for-windows/git`. The new `--backfill-release=<tag-name>` option allows just that. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c19ec36 commit 973ec63

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

add-entry.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,56 @@ const main = async (...args) => {
2323
const addURL = url => {
2424
const fileName = url.replace(/.*\//, '')
2525
const match = fileName.match(fileNameRegex)
26-
if (!match) throw new Error(`Cannot parse URL: ${url}`)
26+
if (!match) throw new Error(`Cannot parse URL: ${url} (fileName: ${fileName})`)
2727
else if (match[1]) urls.installers.push({ url, cpu: cpus[match[2]] })
2828
else if (match[3]) urls.portableGits.push({ url, cpu: cpus[match[4]] })
2929
else if (match[5]) urls.busyBoxMinGits.push({ url, cpu: cpus[match[6]] })
3030
else if (match[7]) urls.minGits.push({ url, cpu: cpus[match[8]] })
3131
else throw new Error(`Cannot parse URL: ${url}`)
3232
}
3333

34+
let mode = 'append-to-top'
3435
let date
3536
let commit
3637
while (args.length > 0) {
3738
const arg = args.shift()
3839
if (arg.startsWith('--date=')) date = arg.replace(/.*?=/, '')
3940
else if (arg.startsWith('--commit=')) commit = arg.replace(/.*?=/, '')
4041
else if (arg.startsWith('https://')) addURL(arg)
41-
else {
42+
else if (arg.startsWith('--backfill-release=')) {
43+
if (args.length) throw new Error(`--backfill-release cannot be combined with other arguments!`)
44+
const tagName = arg.replace(/.*?=/, '')
45+
.replace(/^https:\/\/github\.com\/git-for-windows\/git\/releases\/tag\//, '')
46+
if (!tagName.match(/^v[1-9][0-9]*(\.\d+){2}(-rc\d+)?\.windows\.\d+$/)) {
47+
throw new Error(`Unexpected tag format: '${tagName}'!`)
48+
}
49+
50+
const gh = async (path) =>
51+
(await fetch(`https://api.github.com/repos/git-for-windows/git/${path}`)).json()
52+
const { object: { sha: tagSHA } } = await gh(`git/ref/tags/${tagName}`)
53+
const { object: { sha: commitSHA } } = await gh(`git/tags/${tagSHA}`)
54+
commit = commitSHA
55+
const { committer: { date: commitDate } } = await gh(`git/commits/${commitSHA}`)
56+
date = (new Date(commitDate)).toLocaleString('en-US', {
57+
weekday: 'short',
58+
month: 'short',
59+
day: 'numeric',
60+
year: 'numeric',
61+
hour: '2-digit',
62+
hourCycle: "h24",
63+
minute: '2-digit',
64+
second: '2-digit',
65+
timeZoneName: 'longOffset',
66+
timeZone: "Etc/UTC"
67+
})
68+
69+
const { assets } = await gh(`releases/tags/${tagName}`)
70+
assets.forEach(asset => {
71+
if (!asset.name.endsWith('.tar.bz2') && !asset.name.startsWith('pdbs')) addURL(asset.browser_download_url)
72+
})
73+
74+
mode = 'insert-by-date'
75+
} else {
4276
throw new Error(`Unhandled argument '${arg}`)
4377
}
4478
}
@@ -87,7 +121,12 @@ const main = async (...args) => {
87121
'</ul>'
88122
].join('')
89123

90-
sections[1] = `${insert}\n\n${sections[1]}`
124+
let index = 1
125+
if (mode === 'insert-by-date') {
126+
while (index + 2 < sections.length && insert.localeCompare(sections[index]) < 0) index += 2
127+
} else if (mode !== 'append-to-top') throw new Error(`Unhandled mode: '${mode}'`)
128+
sections[index] = `${insert}\n\n${sections[index]}`
129+
91130
fs.writeFileSync('index.html', sections.join(''))
92131
}
93132

0 commit comments

Comments
 (0)