Compare commits

..

45 Commits

Author SHA1 Message Date
Alif Rachmawadi
26bf50084a update test platform map
Some checks failed
Main workflow / Run (ubuntu-latest) (push) Failing after 16m21s
Main workflow / Run (macos-latest) (push) Failing after 2s
Main workflow / Run (windows-latest) (push) Has been cancelled
2020-10-08 01:36:34 +00:00
Alif Rachmawadi
45483e4c19 increase test timeout 2020-10-08 01:32:27 +00:00
Alif Rachmawadi
6f4d1ee832 use exact prettier 2020-10-08 01:26:57 +00:00
Alif Rachmawadi
58a4d54c5d update dist 2020-10-08 01:24:34 +00:00
Alif Rachmawadi
d0e7441034 update installer 2020-10-08 01:22:27 +00:00
Alif Rachmawadi
c7c0640db8 add release version check function 2020-10-08 01:22:02 +00:00
Alif Rachmawadi
1aaec8dd0f update dependencies 2020-10-08 01:20:47 +00:00
Alif Rachmawadi
ddb7b913ca update test data 2020-10-08 01:19:56 +00:00
Alif Rachmawadi
0b6cdde020 Merge pull request #60 from subosito/dependabot/npm_and_yarn/actions/core-1.2.6
Bump @actions/core from 1.2.4 to 1.2.6
2020-10-07 19:26:56 +07:00
dependabot[bot]
8078702ac6 Bump @actions/core from 1.2.4 to 1.2.6
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.4 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-01 17:17:20 +00:00
Alif Rachmawadi
282b38c3d9 Merge pull request #30 from AlessioLuciani/master
Add iOS and Android app bundle builds
2020-08-14 10:12:00 +07:00
Alif Rachmawadi
12d5ce54d2 Merge pull request #53 from subosito/dependabot/npm_and_yarn/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19
2020-07-22 17:03:20 +07:00
dependabot[bot]
d00139d608 Bump lodash from 4.17.15 to 4.17.19
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-18 00:09:06 +00:00
Alessio Luciani
5d4e01ab3b Add build instructions for the web 2020-06-19 16:13:08 +02:00
Alif Rachmawadi
40bc2f6940 bump version
Some checks failed
Main workflow / Run (ubuntu-latest) (push) Failing after 39m38s
Main workflow / Run (macos-latest) (push) Failing after 3s
Main workflow / Run (windows-latest) (push) Has been cancelled
2020-05-09 11:03:06 +07:00
Alif Rachmawadi
f0d790518f update dist 2020-05-09 10:37:01 +07:00
Alif Rachmawadi
c4a41752bd update dependencies 2020-05-09 10:36:22 +07:00
Alif Rachmawadi
929035d687 update test 2020-05-09 10:17:16 +07:00
Alif Rachmawadi
4bb529986f use channel for latest release 2020-05-09 09:46:10 +07:00
Alif Rachmawadi
ecb8eabe6f update tests 2020-05-09 09:43:40 +07:00
Alif Rachmawadi
cf426f9aa2 update release manifest 2020-05-09 09:43:05 +07:00
Alif Rachmawadi
794e42ad48 bump version: 1.3.1
Some checks failed
Main workflow / Run (macos-latest) (push) Failing after 3s
Main workflow / Run (ubuntu-latest) (push) Failing after 19m55s
Main workflow / Run (windows-latest) (push) Has been cancelled
2020-04-30 09:48:20 +07:00
Alif Rachmawadi
2dd537cc3f update dist 2020-04-30 09:47:38 +07:00
Alif Rachmawadi
3ba093556e Merge pull request #36 from subosito/dependabot/npm_and_yarn/actions/http-client-1.0.8
Bump @actions/http-client from 1.0.7 to 1.0.8
2020-04-30 09:45:20 +07:00
dependabot[bot]
9cde868c41 Bump @actions/http-client from 1.0.7 to 1.0.8
Bumps [@actions/http-client](https://github.com/actions/http-client) from 1.0.7 to 1.0.8.
- [Release notes](https://github.com/actions/http-client/releases)
- [Changelog](https://github.com/actions/http-client/blob/master/RELEASES.md)
- [Commits](https://github.com/actions/http-client/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2020-04-29 18:01:31 +00:00
Alif Rachmawadi
c1bf65eb31 add dart usage example
Some checks failed
Main workflow / Run (macos-latest) (push) Failing after 3s
Main workflow / Run (ubuntu-latest) (push) Failing after 33s
Main workflow / Run (windows-latest) (push) Has been cancelled
2020-04-14 02:34:44 +00:00
Alif Rachmawadi
cfb544479d use previous prettier 2020-04-14 02:31:17 +00:00
Alif Rachmawadi
c256877acc bump version 2020-04-14 02:20:56 +00:00
Alif Rachmawadi
5c02dc7f05 update dist 2020-04-14 02:19:57 +00:00
Alif Rachmawadi
4d34db08ae update dependencies 2020-04-14 02:19:33 +00:00
Alif Rachmawadi
b4d02d2183 update test duration 2020-04-14 02:05:13 +00:00
Alif Rachmawadi
713f696c59 update test 2020-04-14 01:47:20 +00:00
Alif Rachmawadi
c8f591812e update dist 2020-04-14 01:17:42 +00:00
Alif Rachmawadi
f7a5d4550a handle new release format 2020-04-14 01:14:56 +00:00
Alif Rachmawadi
19074769c8 add test for new release format 2020-04-14 01:14:55 +00:00
Alif Rachmawadi
1b5073106b update releases data 2020-04-14 01:14:55 +00:00
Alif Rachmawadi
a8119581ff npm audit fix 2020-04-14 01:14:54 +00:00
Alif Rachmawadi
0ee5f96289 Merge pull request #33 from tianhaoz95/patch-2
might be interesting to add dart SDK to path
2020-04-14 07:57:34 +07:00
Tianhao Zhou
9d3762c82e fix: use join to comply with other os 2020-04-13 14:41:49 -07:00
Tianhao Zhou
6ebddd1b83 fix: add the missing bin directory in dart sdk 2020-04-11 18:23:34 -07:00
Tianhao Zhou
a79364fc11 dev: add dart sdk to path
Adding Flutter bin to the path doesn't expose the dart SDK which many people might be interested in using. For example, dartdoc for documentation generation.
2020-04-11 18:10:01 -07:00
Alessio Luciani
a81c830097 Add iOS and Android app bundle builds
Solving issue https://github.com/subosito/flutter-action/issues/7 .
2020-04-09 14:40:15 +02:00
Alif Rachmawadi
f4209dc839 force minimist resolution 2020-03-17 09:38:25 +07:00
Alif Rachmawadi
cf2fb6cf42 update depedencies 2020-03-17 09:06:14 +07:00
Alif Rachmawadi
8828996b00 fix acorn vulnerabilities 2020-03-17 09:00:22 +07:00
11 changed files with 12150 additions and 5297 deletions

View File

@@ -18,6 +18,59 @@ steps:
- run: flutter build apk
```
Build for iOS too (macOS only):
```yaml
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.9.1+hotfix.6'
- run: flutter pub get
- run: flutter test
- run: flutter build apk
- run: flutter build ios --release --no-codesign
```
Use app bundle, instead of APK:
```yaml
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.9.1+hotfix.6'
- run: flutter pub get
- run: flutter test
- run: flutter build appbundle
```
Build for the web:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
with:
channel: beta
- run: flutter config --enable-web
- run: flutter pub get
- run: flutter test
- run: flutter build web
```
Use latest release for particular channel:
```yaml
@@ -70,6 +123,8 @@ jobs:
with:
flutter-version: '1.11.0'
channel: 'beta'
- run: dart --version
- run: flutter --version
- run: flutter pub get
- run: flutter test
- run: flutter build apk

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -11,31 +11,27 @@ process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;
import * as installer from '../src/installer';
function osName(): string {
switch (process.platform) {
case 'win32':
return 'windows';
case 'darwin':
return 'macos';
default:
return process.platform;
}
}
import * as release from '../src/release';
describe('installer tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
}, 300000);
}, 100000);
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
beforeEach(() => {
const platform = release.getPlatform();
nock('https://storage.googleapis.com', {allowUnmocked: true})
.get(`/flutter_infra/releases/releases_${platform}.json`)
.replyWithFile(200, path.join(dataDir, `releases_${platform}.json`));
});
afterEach(async () => {
nock.cleanAll();
nock.enableNetConnect();
await io.rmRF(toolDir);
await io.rmRF(tempDir);
}, 100000);
it('Downloads flutter', async () => {
@@ -44,58 +40,7 @@ describe('installer tests', () => {
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
}, 100000);
it('Downloads flutter from beta channel', async () => {
await installer.getFlutter('1.8.3', 'beta');
const sdkDir = path.join(toolDir, 'flutter', '1.8.3-beta', 'x64');
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
}, 100000);
describe('get the latest release of a flutter version', () => {
beforeEach(() => {
const platform = osName();
nock('https://storage.googleapis.com', {allowUnmocked: true})
.get(`/flutter_infra/releases/releases_${platform}.json`)
.replyWithFile(200, path.join(dataDir, `releases_${platform}.json`));
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});
it('Downloads latest flutter release from stable channel', async () => {
await installer.getFlutter('', 'stable');
const sdkDir = path.join(
toolDir,
'flutter',
'1.7.8-hotfix.4-stable',
'x64'
);
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
}, 200000);
it('Downloads latest flutter release of 1.7 when using version 1.7 from dev channel', async () => {
await installer.getFlutter('1.7', 'dev');
const sdkDir = path.join(toolDir, 'flutter', '1.7.11-dev', 'x64');
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
}, 200000);
it('Downloads latest flutter release of 1.7 when using version 1.7.x from dev channel', async () => {
await installer.getFlutter('1.7.x', 'dev');
const sdkDir = path.join(toolDir, 'flutter', '1.7.11-dev', 'x64');
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
}, 200000);
});
}, 300000);
it('Throws if no location contains correct flutter version', async () => {
let thrown = false;

117
__tests__/release.test.ts Normal file
View File

@@ -0,0 +1,117 @@
import fs = require('fs');
import path = require('path');
import nock = require('nock');
import * as release from '../src/release';
const platform = release.getPlatform();
describe('release tests', () => {
it('getPlatform', () => {
const platformMap: {[index: string]: string} = {
linux: 'linux',
darwin: 'macos',
win32: 'windows'
};
expect(platform).toEqual(platformMap[process.platform]);
});
describe('determineVersion', () => {
beforeEach(() => {
const dataDir = path.join(__dirname, 'data');
nock('https://storage.googleapis.com', {allowUnmocked: true})
.get(`/flutter_infra/releases/releases_${platform}.json`)
.replyWithFile(200, path.join(dataDir, `releases_${platform}.json`));
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});
it('channel: "stable", version: ""', async () => {
const result = await release.determineVersion('', 'stable', platform);
expect(result.version).toEqual('1.22.0');
expect(result.rawVersion).toEqual('1.22.0');
expect(result.downloadUrl).toContain('1.22.0');
});
it('channel: "beta", version: ""', async () => {
const result = await release.determineVersion('', 'beta', platform);
expect(result.version).toEqual('1.22.0-12.3.pre');
expect(result.rawVersion).toEqual('1.22.0-12.3.pre');
expect(result.downloadUrl).toContain('1.22.0-12.3.pre');
});
it('channel: "dev", version: ""', async () => {
const result = await release.determineVersion('', 'dev', platform);
expect(result.version).toEqual('1.23.0-7.0.pre');
expect(result.rawVersion).toEqual('1.23.0-7.0.pre');
expect(result.downloadUrl).toContain('1.23.0-7.0.pre');
});
it('channel: "dev", version: "1.17.x"', async () => {
const result = await release.determineVersion('1.17.x', 'dev', platform);
expect(result.version).toEqual('1.17.0-dev.5.0');
expect(result.rawVersion).toEqual('1.17.0-dev.5.0');
expect(result.downloadUrl).toContain('1.17.0-dev.5.0');
});
it('channel: "dev", version: "1.17"', async () => {
const result = await release.determineVersion('1.17', 'dev', platform);
expect(result.version).toEqual('1.17.0-dev.5.0');
expect(result.rawVersion).toEqual('1.17.0-dev.5.0');
expect(result.downloadUrl).toContain('1.17.0-dev.5.0');
});
it('channel: "dev", version: "1.7.x" (old format)', async () => {
const result = await release.determineVersion('1.7.x', 'dev', platform);
expect(result.version).toEqual('1.7.11');
expect(result.rawVersion).toEqual('v1.7.11');
expect(result.downloadUrl).toContain('v1.7.11');
});
it('channel: "dev", version: "1.7" (old format)', async () => {
const result = await release.determineVersion('1.7', 'dev', platform);
expect(result.version).toEqual('1.7.11');
expect(result.rawVersion).toEqual('v1.7.11');
expect(result.downloadUrl).toContain('v1.7.11');
});
it('channel: "dev", version: "0.12.x" (unknown)', async () => {
try {
await release.determineVersion('0.12.x', 'dev', platform);
} catch (e) {
expect(e.message).toEqual('unable to find release for 0.12.x');
}
});
it('channel: "dev", version: "0.12" (unknown)', async () => {
try {
await release.determineVersion('0.12', 'dev', platform);
} catch (e) {
expect(e.message).toEqual('unable to find release for 0.12');
}
});
it('channel: "dev", version: "1.17.0-dev.5.0"', async () => {
const result = await release.determineVersion(
'1.17.0-dev.5.0',
'dev',
platform
);
expect(result.version).toEqual('1.17.0-dev.5.0');
expect(result.rawVersion).toEqual('1.17.0-dev.5.0');
expect(result.downloadUrl).toContain('1.17.0-dev.5.0');
});
});
});

8108
dist/index.js vendored

File diff suppressed because it is too large Load Diff

4379
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "flutter-action",
"version": "1.2.0",
"version": "1.3.2",
"private": true,
"description": "Flutter environment for use in actions",
"main": "lib/index.js",
@@ -25,27 +25,29 @@
"author": "Alif Rachmawadi <arch@subosito.com>",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3",
"@actions/http-client": "^1.0.6",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/http-client": "^1.0.8",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.3.1",
"semver": "^7.1.3",
"uuid": "^7.0.1"
"@actions/tool-cache": "^1.6.0",
"semver": "^7.3.2",
"uuid": "^8.3.1"
},
"devDependencies": {
"@types/jest": "^25.1.3",
"@types/nock": "^10.0.3",
"@types/node": "^12.12.29",
"@types/semver": "^7.1.0",
"@types/uuid": "^7.0.0",
"@zeit/ncc": "^0.21.1",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"nock": "^10.0.6",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.5",
"@types/semver": "^7.3.4",
"@types/uuid": "^8.3.0",
"@vercel/ncc": "^0.24.1",
"jest": "^26.5.2",
"jest-circus": "^26.5.2",
"nock": "^13.0.4",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3"
"prettier": "1.19.1",
"ts-jest": "^26.4.1",
"typescript": "^4.0.3"
},
"resolutions": {
"minimist": "^1.2.2"
}
}

View File

@@ -1,211 +1,103 @@
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import {CONNREFUSED} from 'dns';
import * as fs from 'fs';
import * as path from 'path';
import * as httpm from '@actions/http-client';
import * as semver from 'semver';
const IS_WINDOWS = process.platform === 'win32';
const IS_DARWIN = process.platform === 'darwin';
const IS_LINUX = process.platform === 'linux';
const storageUrl = 'https://storage.googleapis.com/flutter_infra/releases';
let tempDirectory = process.env['RUNNER_TEMP'] || '';
if (!tempDirectory) {
let baseLocation;
if (IS_WINDOWS) {
baseLocation = process.env['USERPROFILE'] || 'C:\\';
} else {
if (process.platform === 'darwin') {
baseLocation = '/Users';
} else {
baseLocation = '/home';
}
}
tempDirectory = path.join(baseLocation, 'actions', 'temp');
}
import {format} from 'path';
import * as release from './release';
export async function getFlutter(
version: string,
channel: string
): Promise<void> {
const versionPart = version.split('.');
const platform = release.getPlatform();
if (versionPart[1] == null || versionPart[2] == null) {
version = version.concat('.x');
}
const {version: selected, downloadUrl} = await release.determineVersion(
version,
channel,
platform
);
version = await determineVersion(version, channel);
let cleanver = `${version.replace('+', '-')}-${channel}`;
let cleanver = `${selected.replace('+', '-')}-${channel}`;
let toolPath = tc.find('flutter', cleanver);
if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`);
} else {
core.debug('Downloading Flutter from Google storage');
core.debug(`Downloading Flutter from Google storage ${downloadUrl}`);
const downloadInfo = getDownloadInfo(version, channel);
const sdkFile = await tc.downloadTool(downloadInfo.url);
let tempDir: string = generateTempDir();
const sdkDir = await extractDownload(sdkFile, tempDir);
core.debug(`Flutter sdk extracted to ${sdkDir}`);
const sdkFile = await tc.downloadTool(downloadUrl);
const sdkCache = await tmpDir(platform);
const sdkDir = await extract(sdkFile, sdkCache, path.basename(downloadUrl));
toolPath = await tc.cacheDir(sdkDir, 'flutter', cleanver);
}
core.exportVariable('FLUTTER_HOME', toolPath);
core.addPath(path.join(toolPath, 'bin'));
core.addPath(path.join(toolPath, 'bin', 'cache', 'dart-sdk', 'bin'));
}
function osName(): string {
if (IS_DARWIN) return 'macos';
if (IS_WINDOWS) return 'windows';
function tmpBaseDir(platform: string): string {
let tempDirectory = process.env['RUNNER_TEMP'] || '';
return process.platform;
if (tempDirectory) {
return tempDirectory;
}
let baseLocation;
switch (platform) {
case 'windows':
baseLocation = process.env['USERPROFILE'] || 'C:\\';
break;
case 'macos':
baseLocation = '/Users';
break;
default:
baseLocation = '/home';
break;
}
return path.join(baseLocation, 'actions', 'temp');
}
function extName(): string {
if (IS_LINUX) return 'tar.xz';
return 'zip';
}
function getDownloadInfo(
version: string,
channel: string
): {version: string; url: string} {
const os = osName();
const ext = extName();
const url = `${storageUrl}/${channel}/${os}/flutter_${os}_v${version}-${channel}.${ext}`;
return {
version,
url
};
}
function generateTempDir(): string {
return path.join(
tempDirectory,
async function tmpDir(platform: string): Promise<string> {
const baseDir = tmpBaseDir(platform);
const tempDir = path.join(
baseDir,
'temp_' + Math.floor(Math.random() * 2000000000)
);
await io.mkdirP(tempDir);
return tempDir;
}
async function extractDownload(
async function extract(
sdkFile: string,
destDir: string
sdkCache: string,
originalFilename: string
): Promise<string> {
await io.mkdirP(destDir);
const fileStats = fs.statSync(path.normalize(sdkFile));
const sdkPath = path.normalize(sdkFile);
const stats = fs.statSync(sdkPath);
if (fileStats.isFile()) {
const stats = fs.statSync(sdkFile);
if (stats.isFile()) {
await extractFile(sdkFile, destDir);
if (!stats) {
throw new Error(`Failed to extract ${sdkFile} - it doesn't exist`);
} else if (stats.isDirectory()) {
throw new Error(`Failed to extract ${sdkFile} - it is a directory`);
}
const sdkDir = path.join(destDir, fs.readdirSync(destDir)[0]);
if (originalFilename.endsWith('tar.xz')) {
await tc.extractTar(sdkFile, sdkCache, 'x');
} else {
await tc.extractZip(sdkFile, sdkCache);
}
return sdkDir;
return path.join(sdkCache, fs.readdirSync(sdkCache)[0]);
} else {
throw new Error(`Flutter sdk argument ${sdkFile} is not a file`);
}
}
async function extractFile(file: string, destDir: string): Promise<void> {
const stats = fs.statSync(file);
if (!stats) {
throw new Error(`Failed to extract ${file} - it doesn't exist`);
} else if (stats.isDirectory()) {
throw new Error(`Failed to extract ${file} - it is a directory`);
}
if ('tar.xz' === extName()) {
await tc.extractTar(file, destDir, 'x');
} else {
await tc.extractZip(file, destDir);
}
}
async function determineVersion(
version: string,
channel: string
): Promise<string> {
if (version.endsWith('.x') || version === '') {
return await getLatestVersion(version, channel);
}
return version;
}
interface IFlutterChannel {
[key: string]: string;
beta: string;
dev: string;
stable: string;
}
interface IFlutterRelease {
hash: string;
channel: string;
version: string;
}
interface IFlutterStorage {
current_release: IFlutterChannel;
releases: IFlutterRelease[];
}
async function getLatestVersion(
version: string,
channel: string
): Promise<string> {
const releasesUrl: string = `${storageUrl}/releases_${osName()}.json`;
const http: httpm.HttpClient = new httpm.HttpClient('flutter-action');
const storage: IFlutterStorage | null = (
await http.getJson<IFlutterStorage | null>(releasesUrl)
).result;
if (!storage) {
throw new Error('unable to get latest version');
}
if (version.endsWith('.x')) {
const sver = version.slice(0, version.length - 2);
const releases = storage.releases.filter(
release =>
release.version.startsWith(`v${sver}`) && release.channel === channel
);
const versions = releases.map(release =>
release.version.slice(1, release.version.length)
);
const sortedVersions = versions.sort(semver.rcompare);
core.debug(
`latest version of ${version} from channel ${channel} is ${sortedVersions[0]}`
);
return sortedVersions[0];
}
const channelVersion = storage.releases.find(
release => release.hash === storage.current_release[channel]
);
if (!channelVersion) {
throw new Error(`unable to get latest version from channel ${channel}`);
}
let cver = channelVersion.version;
cver = cver.slice(1, cver.length);
core.debug(`latest version from channel ${channel} is ${cver}`);
return cver;
}

175
src/release.ts Normal file
View File

@@ -0,0 +1,175 @@
import * as core from '@actions/core';
import * as httpm from '@actions/http-client';
import * as semver from 'semver';
export const storageUrl =
'https://storage.googleapis.com/flutter_infra/releases';
interface IFlutterChannel {
[key: string]: string;
beta: string;
dev: string;
stable: string;
}
interface IFlutterRelease {
hash: string;
channel: string;
version: string;
archive: string;
}
interface IFlutterStorage {
current_release: IFlutterChannel;
releases: IFlutterRelease[];
}
export function getPlatform(): string {
const platform = process.platform;
if (platform == 'win32') {
return 'windows';
}
if (platform == 'darwin') {
return 'macos';
}
return platform;
}
export async function determineVersion(
version: string,
channel: string,
platform: string
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
const storage = await getReleases(platform);
if (version === '') {
return getLatestVersion(storage, channel);
}
if (version.endsWith('.x')) {
return getWildcardVersion(storage, channel, version);
}
return getVersion(storage, channel, version);
}
async function getReleases(platform: string): Promise<IFlutterStorage> {
const releasesUrl: string = `${storageUrl}/releases_${platform}.json`;
const http: httpm.HttpClient = new httpm.HttpClient('flutter-action');
const storage: IFlutterStorage | null = (
await http.getJson<IFlutterStorage | null>(releasesUrl)
).result;
if (!storage) {
throw new Error('unable to get flutter releases');
}
return storage;
}
async function getLatestVersion(
storage: IFlutterStorage,
channel: string
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
const channelVersion = storage.releases.find(release => {
return (
release.hash === storage.current_release[channel] &&
release.channel == channel
);
});
if (!channelVersion) {
throw new Error(`unable to get latest version from channel ${channel}`);
}
let rver = channelVersion.version;
let cver = rver.startsWith('v') ? rver.slice(1, rver.length) : rver;
core.debug(`latest version from channel ${channel} is ${rver}`);
return {
version: cver,
rawVersion: rver,
downloadUrl: `${storageUrl}/${channelVersion.archive}`
};
}
async function getWildcardVersion(
storage: IFlutterStorage,
channel: string,
version: string
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
let sver = version.endsWith('.x')
? version.slice(0, version.length - 2)
: version;
const releases = storage.releases.filter(release => {
if (release.channel != channel) return false;
return prefixCompare(sver, release.version);
});
const versions = releases
.map(release => release.version)
.map(version =>
version.startsWith('v') ? version.slice(1, version.length) : version
);
const sortedVersions = versions.sort(semver.rcompare);
let cver = sortedVersions[0];
let release = releases.find(release => compare(cver, release.version));
if (!release) {
throw new Error(`unable to find release for ${version}`);
}
core.debug(
`latest version of ${version} from channel ${channel} is ${release.version}`
);
return {
version: cver,
rawVersion: release.version,
downloadUrl: `${storageUrl}/${release.archive}`
};
}
async function getVersion(
storage: IFlutterStorage,
channel: string,
version: string
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
const release = storage.releases.find(release => {
if (release.channel != channel) return false;
return compare(version, release.version);
});
if (!release) {
return getWildcardVersion(storage, channel, version);
}
return {
version,
rawVersion: release.version,
downloadUrl: `${storageUrl}/${release.archive}`
};
}
function compare(version: string, releaseVersion: string): boolean {
if (releaseVersion.startsWith('v')) {
return releaseVersion === `v${version}`;
}
return releaseVersion === version;
}
function prefixCompare(version: string, releaseVersion: string): boolean {
if (releaseVersion.startsWith('v')) {
return releaseVersion.startsWith(`v${version}`);
}
return releaseVersion.startsWith(version);
}