Initial changes for setup-android

This commit is contained in:
Dave Olsthoorn 2020-07-14 17:41:00 +02:00
parent aa16e13db3
commit 47171f7d89
18 changed files with 12997 additions and 88 deletions

3
.eslintignore Normal file
View file

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

59
.eslintrc.json Normal file
View file

@ -0,0 +1,59 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-object-literal-type-assertion": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error",
"no-console": "off"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}

29
.github/workflows/build-test.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: build-test
on:
pull_request:
paths-ignore:
- '**.md'
push:
branches:
- master
- releases/*
paths-ignore:
- '**.md'
jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm test

View file

@ -1,13 +0,0 @@
name: Main CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup local Android problem matchers
run: |
./index.js
- name: Print example problems
run: |
./test.js

96
.gitignore vendored Normal file
View file

@ -0,0 +1,96 @@
# Ignore node_modules, ncc is used to compile nodejs modules into a single file
node_modules/
__tests__/runner/*
# Ignore js files that are transpiled from ts files in src/
lib/
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
.vscode/

3
.prettierignore Normal file
View file

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

11
.prettierrc.json Normal file
View file

@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

View file

@ -1,58 +1,7 @@
# Android Problem Matchers
# setup-android
For setting up the android sdk in a github-action
Adds common problem matchers for Android builds to GitHub Action workflows. Currently adds support for the following tools:
<!-- TODO: write readme -->
* Kotlin compiler
* Android Lint
* Gradle
This action only configures the problem matchers in order to be compatible with diverse Android workflows.
## Inputs
No inputs are needed.
## Outputs
No outputs are generated apart from configured problem matchers.
## Example usage
In your workflow YAML file add this step:
```yaml
- name: Setup Android problem matchers
uses: jonasb/android-problem-matchers-action@v1
```
Example full workflow definition:
```yaml
name: Android CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Setup Android problem matchers
uses: jonasb/android-problem-matchers-action@v1
- name: Build Android
run: |
./gradlew build -PisCI=true
```
In order for Android Lint problems (especially warnings) to show up in the logs and be detected, make these changes to `app/build.gradle`:
```groovy
android {
lintOptions {
textReport project.hasProperty('isCI')
textOutput 'stdout'
}
}
```
# Thanks
Based on the project [android-problem-matchers-action](https://github.com/jonasb/android-problem-matchers-action) from [@jonasb](https://github.com/jonasb)

View file

@ -0,0 +1,5 @@
describe('setup-android', () => {
it('has sanity', async () => {
expect(true)
})
})

0
test.js → __tests__/test.js Executable file → Normal file
View file

View file

@ -1,9 +1,9 @@
name: 'Android Problem Matchers'
author: 'Jonas Bengtsson'
description: 'Adds common problem matchers for Android builds'
name: 'Setup Android build environment'
author: 'Dave Olsthoorn'
description: 'Setup the sdk commandline tools for Android like sdkmanager'
runs:
using: 'node12'
main: 'index.js'
main: 'dist/index.js'
branding:
icon: 'list'
color: 'green'

5060
dist/index.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +0,0 @@
#!/usr/bin/env node
console.log(`::add-matcher::${__dirname}/.github/android-lint-file-matcher.json`);
console.log(`::add-matcher::${__dirname}/.github/android-lint-line-matcher.json`);
console.log(`::add-matcher::${__dirname}/.github/gradle-matcher.json`);
console.log(`::add-matcher::${__dirname}/.github/kotlin-error-matcher.json`);
console.log(`::add-matcher::${__dirname}/.github/kotlin-warning-matcher.json`);

11
jest.config.js Normal file
View file

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

7588
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,47 @@
{
"name": "android-problem-matchers-action",
"name": "setup-android",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"description": "setup android action",
"main": "lib/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"pack": "ncc build",
"test": "jest",
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
},
"keywords": [],
"author": "",
"license": "ISC"
"repository": {
"type": "git",
"url": "git+https://github.com/daveol/setup-android.git"
},
"keywords": [
"actions",
"node",
"setup",
"android"
],
"author": "daveol",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/tool-cache": "^1.5.5"
},
"devDependencies": {
"@types/jest": "^24.0.23",
"@types/node": "^12.7.12",
"@typescript-eslint/parser": "^2.8.0",
"@zeit/ncc": "^0.20.5",
"eslint": "^5.16.0",
"eslint-plugin-github": "^2.0.0",
"eslint-plugin-jest": "^22.21.0",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"js-yaml": "^3.13.1",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"typescript": "^3.6.4"
}
}

71
src/main.ts Normal file
View file

@ -0,0 +1,71 @@
import * as core from '@actions/core'
import * as path from 'path'
import * as tc from '@actions/tool-cache'
const matchers = [
'android-lint-file-matcher.json',
'android-lint-line-matcher.json',
'gradle-matcher.json',
'kotlin-error-matcher.json',
'kotlin-warning-matcher.json'
]
let tempDirectory = process.env['RUNNER_TEMP'] || ''
const IS_WINDOWS = process.platform === 'win32'
const cmdToolsVersion = '6609375'
let cmdToolsOS: string
if (process.platform === 'win32') {
cmdToolsOS = 'win'
}
if (process.platform === 'darwin') {
cmdToolsOS = 'mac'
}
if (process.platform === 'linux') {
cmdToolsOS = 'linux'
}
if (!tempDirectory) {
let baseLocation
if (IS_WINDOWS) {
// On windows use the USERPROFILE env variable
baseLocation = process.env['USERPROFILE'] || 'C:\\'
} else {
if (process.platform === 'darwin') {
baseLocation = '/Users'
} else {
baseLocation = '/home'
}
}
tempDirectory = path.join(baseLocation, 'actions', 'temp')
}
async function run(): Promise<void> {
const tempDir: string = path.join(
tempDirectory,
`temp_${Math.floor(Math.random() * 2000000000)}`
)
const androidHome = path.join(tempDir, 'android')
const cmdToolsZip = await tc.downloadTool(
`https://dl.google.com/android/repository/commandlinetools-${cmdToolsOS}-${cmdToolsVersion}_latest.zip`
)
core.debug('extract android commandlinetools')
await tc.extractZip(cmdToolsZip, androidHome)
core.exportVariable('ANDROID_HOME', androidHome)
core.addPath(path.join(androidHome, 'tools', 'bin'))
core.debug('add matchers')
const matchersPath = path.join(__dirname, '..', '.github')
for (const matcher of matchers) {
console.log(`##[add-matcher]${path.join(matchersPath, matcher)}`)
}
}
run()

12
tsconfig.json Normal file
View file

@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules", "**/*.test.ts"]
}