Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8687e6979 | ||
|
|
2fcd5629bc | ||
|
|
6a13bd0836 | ||
|
|
f0cc0311e0 | ||
|
|
5e1529bc12 | ||
|
|
99cf4656b5 | ||
|
|
b3c14e7ecc | ||
|
|
05b7251cb1 | ||
|
|
2d3283596d | ||
|
|
b5a1c34304 | ||
|
|
77740fc108 | ||
|
|
36e70a6528 | ||
|
|
d5878a0492 | ||
|
|
31089a7435 | ||
|
|
4f5d1c6d12 | ||
|
|
03e576dcd6 | ||
|
|
f95a8c953b | ||
|
|
3dae472464 | ||
|
|
523b0faa40 | ||
|
|
813937b170 | ||
|
|
8af4ab61aa | ||
|
|
59a5481c7d | ||
|
|
4686a99fc5 | ||
|
|
2f01469b02 | ||
|
|
f6d2e5de5d | ||
|
|
f5fec4dcb7 | ||
|
|
37e2edb15e | ||
|
|
c64fa18722 | ||
|
|
a3bd2fdf17 | ||
|
|
a7e6ec0df9 | ||
|
|
23835ee500 | ||
|
|
84b5c35087 | ||
|
|
365543a8d9 | ||
|
|
49d7a2a9ae | ||
|
|
409aab1aac | ||
|
|
f0c3acec24 | ||
|
|
399a47813e | ||
|
|
87ca224aa8 | ||
|
|
a1905c800f | ||
|
|
14cf1a3f11 | ||
|
|
858d2d954a | ||
|
|
4389e6cbc6 | ||
|
|
a471b152dc | ||
|
|
56a652e69d | ||
|
|
8e1e9c4d87 | ||
|
|
017da32f19 | ||
|
|
cb226e935b | ||
|
|
5188e41281 | ||
|
|
1ced41a989 | ||
|
|
4ac301c302 | ||
|
|
5c3d315241 | ||
|
|
0600af6a5c | ||
|
|
1c63d3b831 | ||
|
|
086f9fb649 | ||
|
|
8f6ad7c383 | ||
|
|
13141e86c3 | ||
|
|
41992c08db | ||
|
|
d94ad8f4a5 | ||
|
|
7bb7a2ead1 | ||
|
|
08d7837173 | ||
|
|
cb118effe2 | ||
|
|
8c0828b9c2 | ||
|
|
30d8b6aed2 | ||
|
|
e7b018ff3a | ||
|
|
267db14c3d | ||
|
|
123325ea84 | ||
|
|
06a5370154 | ||
|
|
5781588262 | ||
|
|
2d5af0bae8 | ||
|
|
d2a92405ab | ||
|
|
c1329a99f0 | ||
|
|
618ffe6e1a | ||
|
|
1b4d6c711f | ||
|
|
2ed9c88ae0 | ||
|
|
d8b5280c4b | ||
|
|
8ffad233a0 | ||
|
|
2dc29df57b | ||
|
|
d141f1640a | ||
|
|
c4e0544d9c | ||
|
|
2ff7205390 | ||
|
|
4a44bbb8a6 | ||
|
|
d7578c4eec | ||
|
|
26bf50084a | ||
|
|
45483e4c19 | ||
|
|
6f4d1ee832 | ||
|
|
58a4d54c5d | ||
|
|
d0e7441034 | ||
|
|
c7c0640db8 | ||
|
|
1aaec8dd0f | ||
|
|
ddb7b913ca | ||
|
|
0b6cdde020 | ||
|
|
8078702ac6 | ||
|
|
282b38c3d9 | ||
|
|
12d5ce54d2 | ||
|
|
d00139d608 | ||
|
|
5d4e01ab3b | ||
|
|
a81c830097 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
open_collective: flutter-action
|
||||
105
.github/workflows/workflow.yml
vendored
105
.github/workflows/workflow.yml
vendored
@@ -1,22 +1,101 @@
|
||||
name: Main workflow
|
||||
on: [push]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
run:
|
||||
name: Run
|
||||
test_channel:
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
||||
channel: [stable, beta]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
channel: ${{ matrix.channel }}
|
||||
- name: Print FLUTTER_ROOT
|
||||
shell: bash
|
||||
run: echo "FLUTTER_ROOT set to $FLUTTER_ROOT"
|
||||
- name: Print PUB_CACHE
|
||||
shell: bash
|
||||
run: echo "PUB_CACHE set to $PUB_CACHE"
|
||||
- name: Run dart --version
|
||||
shell: bash
|
||||
run: dart --version
|
||||
- name: Run flutter --version
|
||||
shell: bash
|
||||
run: flutter --version
|
||||
test_version:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
version: [ 2.5.3, 2.x, 1, v1.12 ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
channel: stable
|
||||
flutter-version: ${{ matrix.version }}
|
||||
- name: Run dart --version
|
||||
shell: bash
|
||||
run: dart --version
|
||||
- name: Run flutter --version
|
||||
shell: bash
|
||||
run: flutter --version
|
||||
test_master_channel:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
channel: master
|
||||
- name: Run dart --version
|
||||
shell: bash
|
||||
run: dart --version
|
||||
- name: Run flutter --version
|
||||
shell: bash
|
||||
run: flutter --version
|
||||
test_any_channel:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
channel: any
|
||||
flutter-version: 2
|
||||
- name: Run dart --version
|
||||
shell: bash
|
||||
run: dart --version
|
||||
- name: Run flutter --version
|
||||
shell: bash
|
||||
run: flutter --version
|
||||
test_cache:
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set Node.js 10.x
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
with:
|
||||
node-version: 10.x
|
||||
- name: npm install
|
||||
run: npm install
|
||||
- name: Lint
|
||||
run: npm run format-check
|
||||
- name: npm test
|
||||
run: npm test
|
||||
channel: stable
|
||||
flutter-version: 2.5.0
|
||||
cache: true
|
||||
cache-key: key-20220113
|
||||
cache-path: ${{ runner.tool_cache }}/flutter/2.5.0-stable
|
||||
- name: Run dart --version
|
||||
shell: bash
|
||||
run: dart --version
|
||||
- name: Run flutter --version
|
||||
shell: bash
|
||||
run: flutter --version
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
node_modules/
|
||||
lib/
|
||||
__tests__/runner/*
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
178
README.md
178
README.md
@@ -1,79 +1,165 @@
|
||||
# flutter-action
|
||||
|
||||
This action sets up a flutter environment for use in actions. It works on Linux, Windows, and macOS.
|
||||
Flutter environment for use in GitHub Actions. It works on Linux, Windows, and macOS.
|
||||
|
||||
# Usage
|
||||
## Usage
|
||||
|
||||
Use specific version and channel:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-java@v1
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
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
|
||||
flutter-version: '2.8.0'
|
||||
channel: 'stable'
|
||||
- run: flutter --version
|
||||
```
|
||||
|
||||
Use latest release for particular channel:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-java@v1
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
java-version: '12.x'
|
||||
- uses: subosito/flutter-action@v1
|
||||
with:
|
||||
channel: 'stable' # or: 'dev' or 'beta'
|
||||
- run: flutter pub get
|
||||
- run: flutter test
|
||||
- run: flutter build apk
|
||||
channel: 'stable' # or: 'beta' or 'master'
|
||||
- run: flutter --version
|
||||
```
|
||||
|
||||
Use latest release for particular version and/or channel:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-java@v1
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
java-version: '12.x'
|
||||
- uses: subosito/flutter-action@v1
|
||||
flutter-version: '1.22.x' # or, you can use 1.22
|
||||
channel: 'dev'
|
||||
- run: flutter --version
|
||||
```
|
||||
|
||||
Use particular version on any channel:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
flutter-version: '1.12.x' # you can use 1.12
|
||||
channel: 'dev' # optional, default to: 'stable'
|
||||
flutter-version: '2.x'
|
||||
channel: 'any'
|
||||
- run: flutter --version
|
||||
```
|
||||
|
||||
Build Android APK and app bundle:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '11'
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
flutter-version: '2.10.4'
|
||||
- run: flutter pub get
|
||||
- run: flutter test
|
||||
- run: flutter build apk
|
||||
- run: flutter build appbundle
|
||||
```
|
||||
|
||||
Matrix Testing:
|
||||
Build for iOS (macOS only):
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
test:
|
||||
name: Test on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
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.11.0'
|
||||
channel: 'beta'
|
||||
- run: dart --version
|
||||
- run: flutter --version
|
||||
- run: flutter pub get
|
||||
- run: flutter test
|
||||
- run: flutter build apk
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
flutter-version: '2.10.4'
|
||||
architecture: x64
|
||||
- run: flutter pub get
|
||||
- run: flutter test
|
||||
- run: flutter build ios --release --no-codesign
|
||||
```
|
||||
|
||||
Build for the web:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
flutter-version: '2.10.4'
|
||||
- run: flutter pub get
|
||||
- run: flutter test
|
||||
- run: flutter build web
|
||||
```
|
||||
|
||||
Build for Windows:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
channel: 'beta'
|
||||
- run: flutter config --enable-windows-desktop
|
||||
- run: flutter build windows
|
||||
```
|
||||
|
||||
Build for Linux desktop:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
channel: 'beta'
|
||||
- run: |
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y ninja-build libgtk-3-dev
|
||||
- run: flutter config --enable-linux-desktop
|
||||
- run: flutter build linux
|
||||
```
|
||||
|
||||
Build for macOS desktop:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
channel: 'beta'
|
||||
architecture: x64
|
||||
- run: flutter config --enable-macos-desktop
|
||||
- run: flutter build macos
|
||||
```
|
||||
|
||||
Integration with `actions/cache`:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
with:
|
||||
flutter-version: '2.10.x'
|
||||
channel: 'stable'
|
||||
cache: true
|
||||
cache-key: flutter # optional, change this to force refresh cache
|
||||
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path
|
||||
architecture: x64 # optional, x64 or arm64
|
||||
- run: flutter --version
|
||||
```
|
||||
|
||||
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
@@ -1,121 +0,0 @@
|
||||
import io = require('@actions/io');
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
import nock = require('nock');
|
||||
|
||||
const toolDir = path.join(__dirname, 'runner', 'tools');
|
||||
const tempDir = path.join(__dirname, 'runner', 'temp');
|
||||
const dataDir = path.join(__dirname, 'data');
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
describe('installer tests', () => {
|
||||
beforeAll(async () => {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
}, 100000);
|
||||
|
||||
afterEach(async () => {
|
||||
await io.rmRF(toolDir);
|
||||
await io.rmRF(tempDir);
|
||||
}, 100000);
|
||||
|
||||
it('Downloads flutter', async () => {
|
||||
await installer.getFlutter('1.0.0', 'stable');
|
||||
const sdkDir = path.join(toolDir, 'flutter', '1.0.0-stable', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
||||
}, 300000);
|
||||
|
||||
it('Downloads flutter from dev channel', async () => {
|
||||
await installer.getFlutter('1.17.0-dev.5.0', 'dev');
|
||||
const sdkDir = path.join(toolDir, 'flutter', '1.17.0-dev.5.0-dev', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
||||
}, 300000);
|
||||
|
||||
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.17.0-stable', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
||||
}, 300000);
|
||||
|
||||
it('Downloads latest flutter release from beta channel (using new release format)', async () => {
|
||||
await installer.getFlutter('', 'beta');
|
||||
const sdkDir = path.join(
|
||||
toolDir,
|
||||
'flutter',
|
||||
'1.17.0-3.4.pre-beta',
|
||||
'x64'
|
||||
);
|
||||
|
||||
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
||||
}, 300000);
|
||||
|
||||
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);
|
||||
}, 300000);
|
||||
|
||||
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);
|
||||
}, 300000);
|
||||
|
||||
it('Downloads latest flutter release of 1.17 when using version 1.17.x from dev channel (using new release format)', async () => {
|
||||
await installer.getFlutter('1.17.x', 'dev');
|
||||
const sdkDir = path.join(toolDir, 'flutter', '1.17.0-dev.5.0-dev', 'x64');
|
||||
|
||||
expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true);
|
||||
expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true);
|
||||
}, 300000);
|
||||
});
|
||||
|
||||
it('Throws if no location contains correct flutter version', async () => {
|
||||
let thrown = false;
|
||||
try {
|
||||
await installer.getFlutter('1000.0', 'dev');
|
||||
} catch {
|
||||
thrown = true;
|
||||
}
|
||||
expect(thrown).toBe(true);
|
||||
});
|
||||
});
|
||||
33
action.yml
33
action.yml
@@ -1,17 +1,40 @@
|
||||
name: 'Flutter action'
|
||||
description: 'Setup your runner with Flutter environment'
|
||||
author: 'Alif Rachmawadi'
|
||||
branding:
|
||||
icon: 'maximize'
|
||||
color: 'blue'
|
||||
inputs:
|
||||
flutter-version:
|
||||
description: 'The Flutter version to make available on the path'
|
||||
required: false
|
||||
default: 'any'
|
||||
channel:
|
||||
description: 'The Flutter build release channel'
|
||||
required: false
|
||||
default: 'stable'
|
||||
cache:
|
||||
description: 'Cache the Flutter SDK'
|
||||
required: false
|
||||
cache-key:
|
||||
description: 'Identifier for the Flutter SDK cache'
|
||||
required: false
|
||||
default: 'flutter'
|
||||
cache-path:
|
||||
description: 'Flutter SDK cache path'
|
||||
required: false
|
||||
default: ${{ runner.tool_cache }}/flutter
|
||||
architecture:
|
||||
description: 'The architecture of Flutter SDK executable (x64 or arm64)'
|
||||
required: false
|
||||
default: 'x64'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
icon: 'maximize'
|
||||
color: 'blue'
|
||||
using: 'composite'
|
||||
steps:
|
||||
- if: ${{ inputs.cache == 'true' }}
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ inputs.cache-path }}
|
||||
key: ${{ inputs.cache-key }}-${{ inputs.channel }}-${{ inputs.flutter-version }}
|
||||
- run: $GITHUB_ACTION_PATH/setup.sh -c "${{ inputs.cache-path }}" ${{ inputs.channel }} ${{ inputs.flutter-version }} ${{ inputs.architecture }}
|
||||
shell: bash
|
||||
|
||||
7189
dist/index.js
vendored
7189
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
7507
package-lock.json
generated
7507
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@@ -1,53 +0,0 @@
|
||||
{
|
||||
"name": "flutter-action",
|
||||
"version": "1.3.2",
|
||||
"private": true,
|
||||
"description": "Flutter environment for use in actions",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build-tsc": "tsc",
|
||||
"build-ncc": "ncc build",
|
||||
"build": "run-s build-tsc build-ncc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/subosito/flutter-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"flutter",
|
||||
"setup"
|
||||
],
|
||||
"author": "Alif Rachmawadi <arch@subosito.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.4",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/http-client": "^1.0.8",
|
||||
"@actions/io": "^1.0.2",
|
||||
"@actions/tool-cache": "^1.3.4",
|
||||
"semver": "^7.3.2",
|
||||
"uuid": "^7.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^25.2.1",
|
||||
"@types/node": "^12.12.38",
|
||||
"@types/semver": "^7.1.0",
|
||||
"@types/uuid": "^7.0.3",
|
||||
"@zeit/ncc": "^0.22.1",
|
||||
"jest": "^25.5.4",
|
||||
"jest-circus": "^25.5.4",
|
||||
"nock": "^12.0.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^1.19.1",
|
||||
"ts-jest": "^25.5.0",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"minimist": "^1.2.2"
|
||||
}
|
||||
}
|
||||
122
setup.sh
Executable file
122
setup.sh
Executable file
@@ -0,0 +1,122 @@
|
||||
#!/bin/bash
|
||||
|
||||
OS_NAME=$(echo "$RUNNER_OS" | awk '{print tolower($0)}')
|
||||
MANIFEST_BASE_URL="https://storage.googleapis.com/flutter_infra_release/releases"
|
||||
MANIFEST_URL="${MANIFEST_BASE_URL}/releases_${OS_NAME}.json"
|
||||
|
||||
# convert version like 2.5.x to 2.5
|
||||
normalize_version() {
|
||||
if [[ $1 == *x ]]; then
|
||||
echo ${1::-2}
|
||||
else
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
|
||||
latest_version() {
|
||||
jq --arg channel "$1" --arg arch "$ARCH" '.releases | map(select(.channel==$channel) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
||||
}
|
||||
|
||||
wildcard_version() {
|
||||
if [ $2 == *"v"* ]; then # is legacy version format
|
||||
if [[ $1 == any ]]; then
|
||||
jq --arg version "$2" '.releases | map(select(.version | startswith($version) )) | first'
|
||||
else
|
||||
jq --arg channel "$1" --arg version "$2" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) )) | first'
|
||||
fi
|
||||
elif [[ $1 == any ]]; then
|
||||
jq --arg version "$2" --arg arch "$ARCH" '.releases | map(select(.version | startswith($version)) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
||||
else
|
||||
jq --arg channel "$1" --arg version "$2" --arg arch "$ARCH" '.releases | map(select(.channel==$channel) | select(.version | startswith($version) ) | select(.dart_sdk_arch == null or .dart_sdk_arch == $arch)) | first'
|
||||
fi
|
||||
}
|
||||
|
||||
get_version() {
|
||||
if [[ $2 == any ]]; then
|
||||
latest_version $1
|
||||
else
|
||||
wildcard_version $1 $2
|
||||
fi
|
||||
}
|
||||
|
||||
get_version_manifest() {
|
||||
releases_manifest=$(curl --silent --connect-timeout 15 --retry 5 $MANIFEST_URL)
|
||||
version_manifest=$(echo $releases_manifest | get_version $1 $(normalize_version $2))
|
||||
|
||||
if [[ $version_manifest == null ]]; then
|
||||
# fallback through legacy version format
|
||||
echo $releases_manifest | wildcard_version $1 "v$(normalize_version $2)"
|
||||
else
|
||||
echo $version_manifest
|
||||
fi
|
||||
}
|
||||
|
||||
download_archive() {
|
||||
archive_url="$MANIFEST_BASE_URL/$1"
|
||||
archive_name=$(basename $1)
|
||||
archive_local="$RUNNER_TEMP/$archive_name"
|
||||
|
||||
curl --connect-timeout 15 --retry 5 $archive_url >$archive_local
|
||||
|
||||
# Create the target folder
|
||||
mkdir -p "$2"
|
||||
|
||||
if [[ $archive_name == *zip ]]; then
|
||||
unzip -q -o "$archive_local" -d "$RUNNER_TEMP"
|
||||
# Remove the folder again so that the move command can do a simple rename
|
||||
# instead of moving the content into the target folder.
|
||||
# This is a little bit of a hack since the "mv --no-target-directory"
|
||||
# linux option is not available here
|
||||
rm -r "$2"
|
||||
mv ${RUNNER_TEMP}/flutter "$2"
|
||||
else
|
||||
tar xf "$archive_local" -C "$2" --strip-components=1
|
||||
fi
|
||||
|
||||
rm $archive_local
|
||||
}
|
||||
|
||||
transform_path() {
|
||||
if [[ $OS_NAME == windows ]]; then
|
||||
echo $1 | sed -e 's/^\///' -e 's/\//\\/g'
|
||||
else
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
|
||||
CACHE_PATH=""
|
||||
|
||||
while getopts 'c:' flag; do
|
||||
case "${flag}" in
|
||||
c) CACHE_PATH="$OPTARG" ;;
|
||||
?) exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
CHANNEL="${@:$OPTIND:1}"
|
||||
VERSION="${@:$OPTIND+1:1}"
|
||||
ARCH="${@:$OPTIND+2:1}"
|
||||
|
||||
SDK_CACHE="$(transform_path ${CACHE_PATH})"
|
||||
PUB_CACHE="$(transform_path ${CACHE_PATH}/.pub-cache)"
|
||||
|
||||
if [[ ! -x "${SDK_CACHE}/bin/flutter" ]]; then
|
||||
if [[ $CHANNEL == master ]]; then
|
||||
git clone -b master https://github.com/flutter/flutter.git "$SDK_CACHE"
|
||||
else
|
||||
VERSION_MANIFEST=$(get_version_manifest $CHANNEL $VERSION)
|
||||
if [[ $VERSION_MANIFEST == null ]]; then
|
||||
echo "Unable to determine Flutter version for channel: $CHANNEL version: $VERSION architecture: $ARCH"
|
||||
exit 1
|
||||
fi
|
||||
ARCHIVE_PATH=$(echo $VERSION_MANIFEST | jq -r '.archive')
|
||||
download_archive "$ARCHIVE_PATH" "$SDK_CACHE"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "FLUTTER_ROOT=${SDK_CACHE}" >>$GITHUB_ENV
|
||||
echo "PUB_CACHE=${PUB_CACHE}" >>$GITHUB_ENV
|
||||
|
||||
echo "${SDK_CACHE}/bin" >>$GITHUB_PATH
|
||||
echo "${SDK_CACHE}/bin/cache/dart-sdk/bin" >>$GITHUB_PATH
|
||||
echo "${PUB_CACHE}/bin" >>$GITHUB_PATH
|
||||
15
src/index.ts
15
src/index.ts
@@ -1,15 +0,0 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as installer from './installer';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const version = core.getInput('flutter-version') || '';
|
||||
const channel = core.getInput('channel') || 'stable';
|
||||
|
||||
await installer.getFlutter(version, channel);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
269
src/installer.ts
269
src/installer.ts
@@ -1,269 +0,0 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
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');
|
||||
}
|
||||
|
||||
export async function getFlutter(
|
||||
version: string,
|
||||
channel: string
|
||||
): Promise<void> {
|
||||
const versionPart = version.split('.').filter(Boolean);
|
||||
|
||||
if (
|
||||
versionPart.length > 0 &&
|
||||
(versionPart[1] == null || versionPart[2] == null)
|
||||
) {
|
||||
version = version.concat('.x');
|
||||
}
|
||||
|
||||
const {version: selected, rawVersion, downloadUrl} = await determineVersion(
|
||||
version,
|
||||
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');
|
||||
|
||||
const sdkFile = await tc.downloadTool(downloadUrl);
|
||||
|
||||
let tempDir: string = generateTempDir();
|
||||
const sdkDir = await extractDownload(sdkFile, tempDir);
|
||||
core.debug(`Flutter sdk extracted to ${sdkDir}`);
|
||||
|
||||
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';
|
||||
|
||||
return process.platform;
|
||||
}
|
||||
|
||||
function extName(): string {
|
||||
if (IS_LINUX) return 'tar.xz';
|
||||
|
||||
return 'zip';
|
||||
}
|
||||
|
||||
function generateTempDir(): string {
|
||||
return path.join(
|
||||
tempDirectory,
|
||||
'temp_' + Math.floor(Math.random() * 2000000000)
|
||||
);
|
||||
}
|
||||
|
||||
async function extractDownload(
|
||||
sdkFile: string,
|
||||
destDir: string
|
||||
): Promise<string> {
|
||||
await io.mkdirP(destDir);
|
||||
|
||||
const sdkPath = path.normalize(sdkFile);
|
||||
const stats = fs.statSync(sdkPath);
|
||||
|
||||
if (stats.isFile()) {
|
||||
await extractFile(sdkFile, destDir);
|
||||
|
||||
const sdkDir = path.join(destDir, fs.readdirSync(destDir)[0]);
|
||||
|
||||
return sdkDir;
|
||||
} 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<{version: string; rawVersion: string; downloadUrl: string}> {
|
||||
if (version.endsWith('.x') || version === '') {
|
||||
return await getLatestVersion(version, channel);
|
||||
}
|
||||
|
||||
return await getSelectedVersion(version, channel);
|
||||
}
|
||||
|
||||
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[];
|
||||
}
|
||||
|
||||
async function getReleases(): Promise<IFlutterStorage> {
|
||||
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 flutter releases');
|
||||
}
|
||||
|
||||
return storage;
|
||||
}
|
||||
|
||||
async function getSelectedVersion(
|
||||
version: string,
|
||||
channel: string
|
||||
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
|
||||
const storage = await getReleases();
|
||||
const release = storage.releases.find(release => {
|
||||
if (release.channel != channel) return false;
|
||||
return compare(version, release.version);
|
||||
});
|
||||
|
||||
if (!release) {
|
||||
throw new Error(`invalid flutter version ${version}, channel ${channel}`);
|
||||
}
|
||||
|
||||
return {
|
||||
version,
|
||||
rawVersion: release.version,
|
||||
downloadUrl: `${storageUrl}/${release.archive}`
|
||||
};
|
||||
}
|
||||
|
||||
async function getLatestVersion(
|
||||
version: string,
|
||||
channel: string
|
||||
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
|
||||
const storage = await getReleases();
|
||||
|
||||
if (version.endsWith('.x')) {
|
||||
const sver = version.slice(0, version.length - 2);
|
||||
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 ${cver}`);
|
||||
}
|
||||
|
||||
core.debug(
|
||||
`latest version of ${version} from channel ${channel} is ${release.version}`
|
||||
);
|
||||
|
||||
return {
|
||||
version: cver,
|
||||
rawVersion: release.version,
|
||||
downloadUrl: `${storageUrl}/${release.archive}`
|
||||
};
|
||||
}
|
||||
|
||||
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}`
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user