2022-11-01 20:51:03 +01:00
|
|
|
import { info, setOutput } from '@actions/core'
|
2022-11-01 21:03:21 +01:00
|
|
|
import semver from 'semver'
|
2022-11-01 20:44:58 +01:00
|
|
|
|
|
|
|
// Fetch the current versions from the download page
|
|
|
|
const URL = `https://nginx.org/en/download.html`
|
|
|
|
const html = await fetch(URL).then((r) => r.text())
|
|
|
|
|
|
|
|
// Find all the downloadable versions
|
|
|
|
const re = /"\/download\/nginx-(\d+\.){3}tar\.gz"/g
|
|
|
|
const matches = html.match(re)
|
|
|
|
|
|
|
|
// Clean up the matches to semver format
|
|
|
|
const clean = (match) => match.replace(/"/g, '').replace('/download/nginx-', '').replace('.tar.gz', '')
|
|
|
|
const versions = matches.map(clean)
|
|
|
|
|
2022-11-01 21:03:21 +01:00
|
|
|
// Filter
|
2022-11-01 21:31:31 +01:00
|
|
|
// Get the two most up to date versions, mainline and stable
|
|
|
|
const filtered = versions.sort(semver.rcompare).slice(0, 2)
|
2022-11-01 21:03:21 +01:00
|
|
|
|
2022-11-01 20:44:58 +01:00
|
|
|
// Map the docker tags to the versions
|
2022-11-01 21:39:50 +01:00
|
|
|
// const tagsMap = Object.fromEntries(filtered.map((v) => [v, v]))
|
2022-11-01 20:44:58 +01:00
|
|
|
|
|
|
|
// Add the mainline, stable and latests tags
|
2022-11-01 21:39:50 +01:00
|
|
|
// tagsMap['latest'] = versions[0]
|
|
|
|
// tagsMap['mainline'] = versions[0]
|
|
|
|
// tagsMap['stable'] = versions[1]
|
2022-11-01 20:44:58 +01:00
|
|
|
|
|
|
|
// Export as github action matrix
|
|
|
|
// https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
|
|
|
|
const githubActionMatrix = {
|
2022-11-01 21:39:50 +01:00
|
|
|
include: [
|
|
|
|
{ version: filtered[0], tags: ['latest', 'mainline', filtered[0]] },
|
|
|
|
{ version: filtered[1], tags: ['stable', filtered[1]] },
|
|
|
|
],
|
2022-11-01 20:44:58 +01:00
|
|
|
}
|
|
|
|
|
2022-11-01 20:51:03 +01:00
|
|
|
const serialised = JSON.stringify(githubActionMatrix)
|
|
|
|
info(`Found ${versions.length} versions`)
|
|
|
|
info(`Exporting as github action matrix: ${serialised}`)
|
|
|
|
setOutput('matrix', serialised)
|