Skip to content

Commit

Permalink
fixed bug causing edge gh releases to not resolve correctly in prerel…
Browse files Browse the repository at this point in the history
…ease tag situations and allow for slim things (#18)

* SUPERSLIM

* SUPERSLIM2
  • Loading branch information
pirog authored Jan 13, 2024
1 parent 148a7e5 commit e5eb40b
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 87 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr-versions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ jobs:
- '3'
- '3.14'
- '3.14.0'
- 'v3.21.0-alpha.9-slim'
- '3-stable'
- '3-stable-slim'
- '3-edge'
- '3-edge-slim'
- '3-latest'
- '3-dev'
- '3-dev-slim'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v2.3.0 - [January 13, 2024](https://github.com/lando/setup-lando/releases/tag/v2.3.0)

* Added support for approved `-slim` variants
* Fixed bug causing `edge` GitHub convenience aliases to not resolve to the correct version

## v2.2.2 - [December 7, 2023](https://github.com/lando/setup-lando/releases/tag/v2.2.2)

* Added passthru support for `3-dev-slim` although it just maps to `3-dev` for now
Expand Down
11 changes: 11 additions & 0 deletions lib/can-be-slim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const satisfies = require('semver/functions/satisfies');
const {s3Releases} = require('./get-convenience-aliases');

module.exports = version => {
// slim can be any v3 s3 alias
if (s3Releases.includes(version)) return version.split('-')[0] === '3';
// or anything in the range
return satisfies(version, '>3.20 <4', {includePrerelease: true, loose: true});
};
19 changes: 17 additions & 2 deletions lib/get-convenience-aliases.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
'use strict';

exports.s3Releases = ['dev', 'latest', '4-dev', '4-latest', '3-dev', '3-dev-slim', '3-latest', '3-latest-slim'];
exports.gitHubReleases = ['stable', 'edge', '4-stable', '4-edge', '3-stable', '3-stable-slim', '3-edge', '3-edge-slim'];
exports.s3Releases = [
'dev',
'latest',
'4-dev',
'4-latest',
'3-dev',
'3-latest',
];

exports.gitHubReleases = [
'stable',
'edge',
'4-stable',
'4-edge',
'3-stable',
'3-edge',
];
18 changes: 13 additions & 5 deletions lib/get-download-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {s3Releases} = require('./get-convenience-aliases');
const s3Base = 'https://files.lando.dev/cli';
const gitHubBase = 'https://github.com/lando/cli/releases/download';

module.exports = (version, {os, architecture} = {}) => {
module.exports = (version, {os, architecture, slim = false} = {}) => {
// if version is actually a downlaod url then just return that right away
if (isValidUrl(version)) return version;

Expand All @@ -16,16 +16,24 @@ module.exports = (version, {os, architecture} = {}) => {
parts.push(architecture.toLowerCase());

// if version is a dev release from s3
// @TODO: we allow s3 convenience aliases with major version stuff eg 4-dev but we dont actually
// have those releases labeled in S3, thats fine with just Lando 3 but with Lando 4 we probably need
// to have ALL of the below
//
// https://files.lando.dev/cli/lando-macos-arm64-dev
// https://files.lando.dev/cli/lando-macos-arm64-3-dev
// https://files.lando.dev/cli/lando-macos-arm64-4-dev
//
// right now we basically just strip the version
if (s3Releases.includes(version)) {
// if 3-dev-slim then just map to 3-dev for now
// @TODO: have this actually pull the slim release when its available
if (version === '3-dev-slim') version = '3-dev';
// add the s3 alias
parts.push(version.split('-').length === 2 ? version.split('-')[1] : version.split('-')[0]);

// otherwise append the version
} else parts.push(version);

// add slim if needed
if (slim) parts.push('slim');

// and add special handling for windows
const filename = os === 'Windows' ? `${parts.join('-')}.exe` : parts.join('-');

Expand Down
1 change: 1 addition & 0 deletions lib/get-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ module.exports = () => ({
debug: getDebug(),
os: core.getInput('os') || getOS(),
telemetry: process.env.GITHUB_ACTIONS ? core.getBooleanInput('telemetry') : true,
slim: false,
setup: core.getInput('setup'),
});
29 changes: 23 additions & 6 deletions lib/resolve-version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const core = require('@actions/core');
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const tc = require('@actions/tool-cache');

const isValidUrl = require('./is-valid-url');
Expand All @@ -19,22 +20,38 @@ module.exports = (spec, releases = [], dmv = 3) => {

// if we have a file that exists on the filesystem then return that
if (fs.existsSync(spec)) return spec;
// then continue by returning any special "dev" aliases
if (s3Releases.includes(spec)) return spec;
// also return any spec that include "preview"
if (spec.includes('preview')) return spec;
// also return any url specs
if (isValidUrl(spec)) return spec;

// at this point it should be safe to remove -slim
if (spec.endsWith('-slim')) spec = spec.replace(/(-slim)(?!.*\1)/, '');

// resolve and normalize s3 aliases
if (s3Releases.includes(spec)) {
// add the dmv if needed
if (spec.split('-')[0] !== '3' && spec.split('-')[0] !== '4') spec = `${dmv}-${spec}`;
// return
return spec;
}

// then attempt to resolve special "convenience" aliases to actual versions
if (gitHubReleases.includes(spec)) {
const mv = spec.split('-').length === 1 ? dmv : spec.split('-')[0];
const prerelease = spec.split('-').length === 1 ? spec.split('-')[0] === 'edge' : spec.split('-')[1] === 'edge';
// fitler based on release type and reset spec
releases = releases.filter(release => release.prerelease === prerelease);
spec = `>=${mv}`;

// filter based on release type and major version and validity etc
releases = releases
.filter(release => release.prerelease === prerelease)
.filter(release => semver.valid(semver.clean(release.tag_name)) !== null)
.filter(release => semver.satisfies(release.tag_name, `>=${mv} <${mv + 1}`, {loose: true, includePrerelease: true}));

// theoretically our spec should be at the top so reset to that
spec = releases[0].tag_name;

// debug
core.debug(`filtered to ${releases.length} prereleases`);
core.debug(`filtered to ${releases.length} releases`);
core.debug(`reset version spec ${spec}`);
}

Expand Down
Loading

0 comments on commit e5eb40b

Please sign in to comment.