From 1dedf93d18afdf782e512b8ac756cd8f8be18f71 Mon Sep 17 00:00:00 2001 From: Niklas Higi Date: Wed, 3 Feb 2021 20:29:55 +0100 Subject: [PATCH] Set up continuous integration (#39) --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 4 ++++ package.json | 3 ++- src/utils/download-tool.ts | 9 ++++++-- 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ff762b6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: CI +on: push +jobs: + lint: + name: Code Formatting + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v1 + - name: Install Node.js + uses: actions/setup-node@v1 + with: + node-version: 14.x + - name: Install dependencies + run: yarn + - name: Check code formatting + run: yarn lint + test: + name: E2E Test / ${{ matrix.os.name }} / Node.js ${{ matrix.node }} + strategy: + matrix: + node: [10, 14] + os: + - name: Linux + runner: ubuntu-latest + - name: Windows + runner: windows-latest + # Prevent one failing job from cancelling the other ones + fail-fast: false + runs-on: ${{ matrix.os.runner }} + steps: + - name: Check out repository + uses: actions/checkout@v1 + - name: Install Node.js + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - name: Install dependencies + run: yarn + - name: Build package + run: yarn build + - name: Download example APK + # Download Telegram FOSS as an example APK + # (there might be better APKs for testing, I didn't put a lot of thought into picking this one) + run: curl --location --output example.apk https://github.com/Telegram-FOSS-Team/Telegram-FOSS/releases/download/v7.0.0/TF-BETA-THERMATK-v7.0.0.apk + - name: Patch example APK + run: node bin/apk-mitm example.apk diff --git a/.vscode/settings.json b/.vscode/settings.json index 54f3f13..99cb412 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,9 @@ "[markdown]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[yaml]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode" } } diff --git a/package.json b/package.json index ff4e79a..2c89a29 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "build": "tsc", "test": "tsc", "watch": "tsc --watch", - "format": "prettier --write ." + "format": "prettier --write .", + "lint": "prettier --check ." }, "bin": "bin/apk-mitm", "files": [ diff --git a/src/utils/download-tool.ts b/src/utils/download-tool.ts index ce52291..b3369d3 100644 --- a/src/utils/download-tool.ts +++ b/src/utils/download-tool.ts @@ -26,7 +26,7 @@ function downloadCachedFile( url: string, fileName: string, ) { - return observeAsync(async next => { + return observeAsync(async log => { const finalFilePath = getCachedPath(fileName) if (await fs.exists(finalFilePath)) { @@ -39,7 +39,12 @@ function downloadCachedFile( // Prevent file corruption by using a temporary file name const downloadFilePath = finalFilePath + '.dl' - await downloadFile(url, downloadFilePath).forEach(next) + await downloadFile(url, downloadFilePath).forEach(line => { + // Hide verbose download progress in non-TTY mode + if (!process.stdout.isTTY) return + + log(line) + }) await fs.rename(downloadFilePath, finalFilePath) }) }