From d7578c4eec8273e0f8cd6733541da1a29cfe68b3 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Thu, 8 Oct 2020 04:36:23 +0000 Subject: [PATCH] add support for master channel --- __tests__/installer.test.ts | 22 ++++++++++++++++++++++ src/index.ts | 8 ++++++++ src/installer.ts | 16 ++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 7fedfa1..f7c29b9 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -1,4 +1,5 @@ import io = require('@actions/io'); +import exec = require('@actions/exec'); import fs = require('fs'); import path = require('path'); import nock = require('nock'); @@ -42,6 +43,27 @@ describe('installer tests', () => { expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true); }, 300000); + it('Downloads flutter from master channel', async () => { + await installer.getFlutter('', 'master'); + const sdkDir = path.join(toolDir, 'flutter', 'master', 'x64'); + + let stdout = ''; + + const options = { + listeners: { + stdout: (data: Buffer) => { + stdout += data.toString(); + } + } + }; + + expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true); + expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true); + + await exec.exec(path.join(sdkDir, 'bin', 'flutter'), ['channel'], options); + expect(stdout).toContain('* master'); + }, 300000); + it('Throws if no location contains correct flutter version', async () => { let thrown = false; try { diff --git a/src/index.ts b/src/index.ts index f449b00..7a9d463 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,14 @@ async function run() { const version = core.getInput('flutter-version') || ''; const channel = core.getInput('channel') || 'stable'; + if (channel == 'master' && version != '') { + core.setFailed( + 'using `flutter-version` with master channel is not supported.' + ); + + return; + } + await installer.getFlutter(version, channel); } catch (error) { core.setFailed(error.message); diff --git a/src/installer.ts b/src/installer.ts index e59cc4d..85f9e42 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -1,10 +1,9 @@ import * as core from '@actions/core'; import * as io from '@actions/io'; +import * as exec from '@actions/exec'; import * as tc from '@actions/tool-cache'; -import {CONNREFUSED} from 'dns'; import * as fs from 'fs'; import * as path from 'path'; -import {format} from 'path'; import * as release from './release'; export async function getFlutter( @@ -12,14 +11,18 @@ export async function getFlutter( channel: string ): Promise { const platform = release.getPlatform(); + const useMaster = channel == 'master'; const {version: selected, downloadUrl} = await release.determineVersion( version, - channel, + useMaster ? 'dev' : channel, platform ); - let cleanver = `${selected.replace('+', '-')}-${channel}`; + let cleanver = useMaster + ? channel + : `${selected.replace('+', '-')}-${channel}`; + let toolPath = tc.find('flutter', cleanver); if (toolPath) { @@ -37,6 +40,11 @@ export async function getFlutter( core.exportVariable('FLUTTER_HOME', toolPath); core.addPath(path.join(toolPath, 'bin')); core.addPath(path.join(toolPath, 'bin', 'cache', 'dart-sdk', 'bin')); + + if (useMaster) { + await exec.exec('flutter', ['channel', 'master']); + await exec.exec('flutter', ['upgrade']); + } } function tmpBaseDir(platform: string): string {