mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2025-12-05 23:34:45 +00:00
Fix latest fetching prerelease versions. (#29)
* Fix fetching latest version to not fetch prerelease. Signed-off-by: Kuba Martin <kubam@spacelift.io> * Add tests. Signed-off-by: Jakub Martin <kubam@spacelift.io> --------- Signed-off-by: Kuba Martin <kubam@spacelift.io> Signed-off-by: Jakub Martin <kubam@spacelift.io>
This commit is contained in:
parent
d00c6817f1
commit
ae80d4ecaa
3 changed files with 187 additions and 6 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
|
|
@ -61,7 +61,7 @@ async function fetchReleases (githubToken) {
|
|||
const semver = __nccwpck_require__(1383);
|
||||
|
||||
async function findLatestVersion (versions) {
|
||||
return versions.sort((a, b) => semver.rcompare(a, b))[0];
|
||||
return versions.filter((v) => semver.prerelease(v) === null).sort((a, b) => semver.rcompare(a, b))[0];
|
||||
}
|
||||
|
||||
async function findLatestVersionInRange (versions, range) {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ async function fetchReleases (githubToken) {
|
|||
const semver = require('semver');
|
||||
|
||||
async function findLatestVersion (versions) {
|
||||
return versions.sort((a, b) => semver.rcompare(a, b))[0];
|
||||
return versions.filter((v) => semver.prerelease(v) === null).sort((a, b) => semver.rcompare(a, b))[0];
|
||||
}
|
||||
|
||||
async function findLatestVersionInRange (versions, range) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,184 @@ const pkg = require('../releases');
|
|||
describe('getRelease', () => {
|
||||
function mockFetchReleases () {
|
||||
const mockReleasesMeta = [{
|
||||
tag_name: 'v1.7.0-alpha2',
|
||||
assets: [{
|
||||
name: 'tofu_1.7.0-alpha2_386.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_386.apk'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_386.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_386.deb'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_386.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_386.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_amd64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_amd64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_amd64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_amd64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_amd64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_amd64.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_arm.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_arm.apk'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_arm.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_arm.deb'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_arm.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_arm.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_arm64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_arm64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_arm64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_arm64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_arm64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_arm64.rpm'
|
||||
}, {
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_darwin_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_darwin_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_darwin_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_freebsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_freebsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_freebsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_freebsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_freebsd_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_freebsd_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_linux_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_linux_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_linux_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_linux_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_linux_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_linux_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_linux_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_linux_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_openbsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_openbsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_openbsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_openbsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_SHA256SUMS',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_SHA256SUMS'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_SHA256SUMS.pem',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_SHA256SUMS.pem'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_SHA256SUMS.sig',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_SHA256SUMS.sig'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_solaris_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_solaris_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_windows_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_windows_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.7.0-alpha2_windows_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.7.0-alpha2/tofu_1.7.0-alpha2_windows_amd64.zip'
|
||||
}]
|
||||
}, {
|
||||
tag_name: 'v1.6.0',
|
||||
assets: [{
|
||||
name: 'tofu_1.6.0_386.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_386.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_386.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_386.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_386.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_386.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_amd64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_amd64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_amd64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_amd64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_amd64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_amd64.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_arm.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_arm.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_arm.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_arm.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_arm.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_arm.rpm'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_arm64.apk',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_arm64.apk'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_arm64.deb',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_arm64.deb'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_arm64.rpm',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_arm64.rpm'
|
||||
}, {
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_darwin_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_darwin_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_darwin_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_freebsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_freebsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_freebsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_freebsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_freebsd_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_freebsd_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_linux_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_linux_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_linux_arm.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_arm.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_linux_arm64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_linux_arm64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_openbsd_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_openbsd_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_openbsd_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_openbsd_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_SHA256SUMS',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_SHA256SUMS.pem',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS.pem'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_SHA256SUMS.sig',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_SHA256SUMS.sig'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_solaris_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_solaris_amd64.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_windows_386.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_windows_386.zip'
|
||||
}, {
|
||||
name: 'tofu_1.6.0_windows_amd64.zip',
|
||||
browser_download_url: 'https://github.com/opentofu/opentofu/releases/download/v1.6.0/tofu_1.6.0_windows_amd64.zip'
|
||||
}]
|
||||
}, {
|
||||
tag_name: 'v1.6.0-alpha2',
|
||||
assets: [{
|
||||
name: 'tofu_1.6.0-alpha2_386.apk',
|
||||
|
|
@ -188,12 +366,15 @@ describe('getRelease', () => {
|
|||
|
||||
it.each(
|
||||
[
|
||||
['latest', '1.6.0-alpha2'],
|
||||
['latest', '1.6.0'],
|
||||
['<1.6.0-beta', '1.6.0-alpha2'],
|
||||
['>1.6.0-alpha1', '1.6.0-alpha2'],
|
||||
['>1.6.0-alpha1', '1.6.0'],
|
||||
['>1.6.0-alpha1 <1.6.0', '1.6.0-alpha2'],
|
||||
['~1.6.0-alpha', '1.6.0-alpha2'],
|
||||
['<=1.6.0-alpha1', '1.6.0-alpha1']
|
||||
['~1.6.0-alpha', '1.6.0'],
|
||||
['<=1.6.0-alpha1', '1.6.0-alpha1'],
|
||||
['>1.5.0', '1.6.0'],
|
||||
['>1.5.0', '1.6.0'],
|
||||
['>1.7.0-alpha', '1.7.0-alpha2']
|
||||
]
|
||||
)('happy path: getRelease(\'%s\') -> \'%s\'', async (input, wantVersion) => {
|
||||
const want = mockFetchReleases().find(el => el.version === wantVersion);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue