ci: add gh-actions workflows (#311)

This commit is contained in:
エリス
2021-09-16 22:18:47 +09:00
committed by GitHub
parent 2cdb0403a8
commit 256f4c92d6
8 changed files with 2753 additions and 1 deletions

155
.github/workflows/android.yml vendored Normal file
View File

@@ -0,0 +1,155 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Android Testsuite
on:
push:
paths-ignore:
- '**.md'
- 'LICENSE'
- '.eslint*'
pull_request:
paths-ignore:
- '**.md'
- 'LICENSE'
- '.eslint*'
jobs:
test:
name: Android ${{ matrix.versions.android }} Test
runs-on: macos-latest
# hoist configurations to top that are expected to be updated
env:
# Storing a copy of the repo
repo: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
node-version: 16
# These are the default Java configurations used by most tests.
# To customize these options, add "java-distro" or "java-version" to the strategy matrix with its overriding value.
default_java-distro: adopt
default_java-version: 8
# These are the default Android System Image configurations used by most tests.
# To customize these options, add "system-image-arch" or "system-image-target" to the strategy matrix with its overriding value.
default_system-image-arch: x86_64
default_system-image-target: google_apis # Most system images have a google_api option. Set this as default.
# configurations for each testing strategy (test matrix)
strategy:
matrix:
versions:
- android: 5.1
android-api: 22
- android: 6
android-api: 23
- android: 7
android-api: 24
- android: 7.1
android-api: 25
- android: 8
android-api: 26
- android: 8.1
android-api: 27
system-image-target: default
- android: 9
android-api: 28
- android: 10
android-api: 29
- android: 11
android-api: 30
java-version: 11
timeout-minutes: 60
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.node-version }}
- uses: actions/setup-java@v2
env:
java-version: ${{ matrix.versions.java-version == '' && env.default_java-version || matrix.versions.java-version }}
java-distro: ${{ matrix.versions.java-distro == '' && env.default_java-distro || matrix.versions.java-distro }}
with:
distribution: ${{ env.java-distro }}
java-version: ${{ env.java-version }}
- name: Run Environment Information
run: |
node --version
npm --version
java -version
- name: Run npm install
run: |
export PATH="/usr/local/lib/android/sdk/platform-tools":$PATH
export JAVA_HOME=$JAVA_HOME_11_X64
npm i -g cordova@latest
npm ci
- name: Run paramedic install
if: ${{ endswith(env.repo, '/cordova-paramedic') != true }}
run: npm i -g github:apache/cordova-paramedic
- uses: reactivecircus/android-emulator-runner@5de26e4bd23bf523e8a4b7f077df8bfb8e52b50e
env:
system-image-arch: ${{ matrix.versions.system-image-arch == '' && env.default_system-image-arch || matrix.versions.system-image-arch }}
system-image-target: ${{ matrix.versions.system-image-target == '' && env.default_system-image-target || matrix.versions.system-image-target }}
with:
api-level: ${{ matrix.versions.android-api }}
target: ${{ env.system-image-target }}
arch: ${{ env.system-image-arch }}
force-avd-creation: false
disable-animations: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
script: echo "Pregenerate the AVD before running Paramedic"
# PLUGIN'S EXTRA STEP
- name: Run file transfer server setup
run: |
npm i
npx forever start index.js
working-directory: ./tests/server
- name: Run paramedic tests
uses: reactivecircus/android-emulator-runner@5de26e4bd23bf523e8a4b7f077df8bfb8e52b50e
env:
system-image-arch: ${{ matrix.versions.system-image-arch == '' && env.default_system-image-arch || matrix.versions.system-image-arch }}
system-image-target: ${{ matrix.versions.system-image-target == '' && env.default_system-image-target || matrix.versions.system-image-target }}
test_config: 'android-${{ matrix.versions.android }}.config.json'
# Generally, this should automatically work for cordova-paramedic & plugins. If the path is unique, this can be manually changed.
test_plugin_path: ${{ endswith(env.repo, '/cordova-paramedic') && './spec/testable-plugin/' || './' }}
paramedic: ${{ endswith(env.repo, '/cordova-paramedic') && 'node main.js' || 'cordova-paramedic' }}
with:
api-level: ${{ matrix.versions.android-api }}
target: ${{ env.system-image-target }}
arch: ${{ env.system-image-arch }}
force-avd-creation: false
disable-animations: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
script: ${{ env.paramedic }} --config ./pr/local/${{ env.test_config }} --plugin ${{ env.test_plugin_path }}

80
.github/workflows/chrome.yml vendored Normal file
View File

@@ -0,0 +1,80 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Chrome Testsuite
on:
push:
paths-ignore:
- '**.md'
- 'LICENSE'
- '.eslint*'
pull_request:
paths-ignore:
- '**.md'
- 'LICENSE'
- '.eslint*'
jobs:
test:
name: Chrome Latest Test
runs-on: ubuntu-latest
# hoist configurations to top that are expected to be updated
env:
# Storing a copy of the repo
repo: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
node-version: 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.node-version }}
- name: Run install xvfb
run: sudo apt-get install xvfb
- name: Run Environment Information
run: |
node --version
npm --version
- name: Run npm install
run: |
npm i -g cordova@latest
npm ci
- name: Run paramedic install
if: ${{ endswith(env.repo, '/cordova-paramedic') != true }}
run: npm i -g github:apache/cordova-paramedic
# PLUGIN'S EXTRA STEP
- name: Run file transfer server setup
run: |
npm i
npx forever start index.js
working-directory: ./tests/server
- name: Run paramedic tests
env:
test_config: 'browser.config.json'
# Generally, this should automatically work for cordova-paramedic & plugins. If the path is unique, this can be manually changed.
test_plugin_path: ${{ endswith(env.repo, '/cordova-paramedic') && './spec/testable-plugin/' || './' }}
paramedic: ${{ endswith(env.repo, '/cordova-paramedic') && 'node main.js' || 'cordova-paramedic' }}
run: xvfb-run --auto-servernum ${{ env.paramedic }} --config ./pr/local/${{ env.test_config }} --plugin ${{ env.test_plugin_path }}

95
.github/workflows/ios.yml vendored Normal file
View File

@@ -0,0 +1,95 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: iOS Testsuite
on:
push:
paths-ignore:
- '**.md'
- 'LICENSE'
- '.eslint*'
pull_request:
paths-ignore:
- '**.md'
- 'LICENSE'
- '.eslint*'
jobs:
test:
name: iOS ${{ matrix.versions.ios-version }} Test
runs-on: macos-latest
# hoist configurations to top that are expected to be updated
env:
# Storing a copy of the repo
repo: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
node-version: 16
# > Starting April 26, 2021, all iOS and iPadOS apps submitted to the App Store must be built with Xcode 12 and the iOS 14 SDK.
# Because of Apple's requirement, listed above, We will only be using the latest Xcode release for testing.
# To customize these options, add "xcode-version" to the strategy matrix with its overriding value.
default_xcode-version: latest-stable
strategy:
matrix:
versions:
- ios-version: 12.x
- ios-version: 13.x
- ios-version: 14.x
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.node-version }}
- uses: maxim-lobanov/setup-xcode@881be567d30efed8fb3f12b5099d68c3fb72aa3d
env:
xcode-version: ${{ matrix.versions.xcode-version == '' && env.default_xcode-version || matrix.versions.xcode-version }}
with:
xcode-version: ${{ env.xcode-version }}
- name: Run Environment Information
run: |
node --version
npm --version
xcodebuild -version
- name: Run npm install
run: |
npm i -g cordova@latest ios-deploy@latest
npm ci
- name: Run paramedic install
if: ${{ endswith(env.repo, '/cordova-paramedic') != true }}
run: npm i -g github:apache/cordova-paramedic
# PLUGIN'S EXTRA STEP
- name: Run file transfer server setup
run: |
npm i
npx forever start index.js
working-directory: ./tests/server
- name: Run paramedic tests
env:
test_config: 'ios-${{ matrix.versions.ios-version }}.config.json'
# Generally, this should automatically work for cordova-paramedic & plugins. If the path is unique, this can be manually changed.
test_plugin_path: ${{ endswith(env.repo, '/cordova-paramedic') && './spec/testable-plugin/' || './' }}
paramedic: ${{ endswith(env.repo, '/cordova-paramedic') && 'node main.js' || 'cordova-paramedic' }}
run: ${{ env.paramedic }} --config ./pr/local/${{ env.test_config }} --plugin ${{ env.test_plugin_path }}

56
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,56 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Lint Test
on:
push:
paths:
- '**.js'
- '.eslint*'
- '.github/workflow/lint.yml'
pull_request:
paths:
- '**.js'
- '.eslint*'
- '.github/workflow/lint.yml'
jobs:
test:
name: Lint Test
runs-on: ubuntu-latest
env:
node-version: 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.node-version }}
- name: Run Environment Information
run: |
node --version
npm --version
- name: Run npm install
run: |
npm ci
- name: Run lint test
run: |
npm run lint

View File

@@ -30,5 +30,5 @@
<hook type="after_prepare" src="hooks/after_prepare.js" />
<preference name="FILETRANSFER_SERVER_ADDRESS" default="http://rwswbpiopr.localtunnel.me"/>
<preference name="FILETRANSFER_SERVER_ADDRESS" default="http://localhost"/>
</plugin>

156
tests/server/index.js Normal file
View File

@@ -0,0 +1,156 @@
const http = require('http');
const stringify = require('json-stringify-safe');
const Busboy = require('busboy');
var { Iconv } = require('iconv');
const port = process.env.PORT || 5000;
const DIRECT_UPLOAD_LIMIT = 85; // bytes
// convert from UTF-8 to ISO-8859-1
const LATIN1_SYMBOLS = '¥§©ÆÖÑøøø¼';
const iconv = new Iconv('UTF-8', 'ISO-8859-1');
function parseMultipartForm (req, res, finishCb) {
let errorOccured = false;
const fields = {};
const files = {};
const busboy = new Busboy({ headers: req.headers });
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
var currentFile = { size: 0 };
file.on('data', function (data) {
currentFile.name = filename;
currentFile.size += data.length;
});
file.on('end', function () {
files.file = currentFile;
});
});
busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
fields[fieldname] = val;
});
busboy.on('finish', function () {
console.log(stringify({ fields, files }));
// This is needed due to this bug: https://github.com/mscdex/busboy/issues/73
if (!errorOccured) {
finishCb(req, res, { fields, files });
}
});
busboy.on('error', function (err) {
console.error(`error: ${err}: ${JSON.stringify(err)}`);
errorOccured = true;
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end(`Could not parse multipart form: ${err}\n`);
});
req.pipe(busboy);
}
function respondWithParsedForm (req, res, parseResultObj) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(stringify(parseResultObj));
res.end('\n');
}
function respondWithParsedFormNonUTF (req, res, parseResultObj) {
parseResultObj.latin1Symbols = LATIN1_SYMBOLS;
var buffer = iconv.convert(stringify(parseResultObj));
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(buffer);
res.end('\n');
}
http.createServer(function (req, res) {
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
const basic_auth_username = 'cordova_user';
const basic_auth_password = 'cordova_password';
const header = req.headers.authorization || ''; // get the header
const token = header.split(/\s+/).pop() || ''; // and the encoded auth token
const auth = Buffer.from(token, 'base64').toString(); // convert from base64
const parts = auth.split(/:/); // split on colon
const username = parts[0];
const password = parts[1];
if (req.url === '/download_basic_auth') {
if (username !== basic_auth_username && password !== basic_auth_password) {
res.writeHead(401, { 'Content-Type': 'text/plain' });
res.end('401\n');
} else {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('User-Agent: *\n');
res.end('Disallow: /\n');
}
} else if (req.url === '/robots.txt') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('User-Agent: *\n');
res.end('Disallow: /\n');
} else if (req.url === '/download_non_utf') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('User-Agent: *\n');
res.write(iconv.convert(LATIN1_SYMBOLS));
res.end('Disallow: /\n');
} else if (req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello!\n');
} else if (req.url === '/upload' && (req.method.toLowerCase() === 'post' || req.method.toLowerCase() === 'put')) {
if (req.headers['content-type'].indexOf('multipart/form-data') === 0) {
console.log('multipart/form upload');
parseMultipartForm(req, res, respondWithParsedForm);
} else {
console.log('direct upload');
var body = '';
req.on('data', function (chunk) {
body += chunk;
if (body.length > DIRECT_UPLOAD_LIMIT) {
req.connection.destroy();
}
});
req.on('end', function () {
console.log('All the data received is: ' + body);
res.writeHead(200, 'OK', { 'content-type': 'text/plain' });
res.write(body);
res.end();
});
}
} else if (req.url === '/upload_basic_auth' && req.method.toLowerCase() === 'post') {
if (username !== basic_auth_username && password !== basic_auth_password) {
res.writeHead(401, { 'Content-Type': 'text/plain' });
res.end('401\n');
} else {
parseMultipartForm(req, res, respondWithParsedForm);
}
} else if (req.url === '/upload_non_utf' && req.method.toLowerCase() === 'post') {
parseMultipartForm(req, res, respondWithParsedFormNonUTF);
} else if (req.url === '/upload_echo_headers' && req.method.toLowerCase() === 'post') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(stringify(req.headers));
res.end('\n');
} else if (req.url.match(/\d{3}/)) {
const matches = req.url.match(/\d{3}/);
const status = matches[0];
res.writeHead(status, { 'Content-Type': 'text/plain' });
res.end('You requested a ' + status + '\n');
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404\n');
}
console.log(req.connection.remoteAddress + ' ' + req.method + ' ' + req.url + ' ' + res.statusCode + ' ' + req.headers['user-agent']);
}).listen(port, '0.0.0.0');
console.log('Server running on ' + port);

2187
tests/server/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
tests/server/package.json Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "cordova-file-transfer-server",
"version": "1.0.0",
"description": "Mock Server for Cordova Plugin File Transfer Tests",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"mock",
"file-transfer",
"testing",
"server"
],
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"dependencies": {
"busboy": "^0.3.1",
"forever": "^4.0.1",
"iconv": "^3.0.0",
"json-stringify-safe": "^5.0.1"
}
}