diff --git a/.build/pre-release.sh b/.build/pre-release.sh index 3e233bbe..fe44496a 100644 --- a/.build/pre-release.sh +++ b/.build/pre-release.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash set -ex +echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc +npm whoami + npm ci patchVersion=$(npm --no-git-tag version patch) nextVersion=${patchVersion}-next."$(date +%Y%m%d%H%M%S)" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..d2555481 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,82 @@ +name: Run CI +on: + push: + branches-ignore: + - develop + - release/** + pull_request: + +jobs: + sonar: + runs-on: ubuntu-latest + steps: + - name: Set up Git repository + uses: actions/checkout@v2 + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: 14 + - name: Setup Docker + run: | + docker pull s1hofmann/nut-ci:latest + docker run -it -d --name nut-ci --shm-size 4gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash + - name: Install + run: npm ci + - name: Compile + run: npm run compile + - name: Init e2e test subpackage + run: npm --prefix e2e/tests ci + - name: Clean coverage report + run: npm run coverage:clean + - name: Generate coverage report + uses: GabrielBB/xvfb-action@v1 + with: + run: npm run coverage -- --coverageDirectory=coverage/unit + - name: Run Docker E2E tests + run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} 14" + - name: Merge coverage reports + run: | + npm run coverage:merge + npm run coverage:merge-report + - name: Send results to SonarCloud + uses: SonarSource/sonarcloud-github-action@v1.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + test: + needs: + - sonar + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + node: [ 10, 12, 14 ] + exclude: + - os: ubuntu-latest + node: 14 + runs-on: ${{matrix.os}} + steps: + - name: Set up Git repository + uses: actions/checkout@v2 + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: ${{matrix.node}} + - name: Setup Docker + if: ${{matrix.os == 'ubuntu-latest'}} + run: | + docker pull s1hofmann/nut-ci:latest + docker run -it -d --name nut-ci --shm-size 4gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash + - name: Install + run: npm ci + - name: Compile + run: npm run compile + - name: Init e2e test subpackage + run: npm --prefix e2e/tests ci + - name: Generate coverage report + uses: GabrielBB/xvfb-action@v1 + with: + run: npm run coverage -- --coverageDirectory=coverage/unit + - name: Run Docker E2E tests + if: ${{matrix.os == 'ubuntu-latest'}} + run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}" diff --git a/.github/workflows/snapshot_release.yaml b/.github/workflows/snapshot_release.yaml new file mode 100644 index 00000000..4ef8f123 --- /dev/null +++ b/.github/workflows/snapshot_release.yaml @@ -0,0 +1,57 @@ +name: Create snapshot release +on: + push: + branches: + - develop + +jobs: + test: + needs: + - sonar + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + node: [ 10, 12, 14 ] + runs-on: ${{matrix.os}} + steps: + - name: Set up Git repository + uses: actions/checkout@v2 + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: ${{matrix.node}} + - name: Setup Docker + if: ${{matrix.os == 'ubuntu-latest'}} + run: | + docker pull s1hofmann/nut-ci:latest + docker run -it -d --name nut-ci --shm-size 4gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash + - name: Install + run: npm ci + - name: Compile + run: npm run compile + - name: Init e2e test subpackage + run: npm --prefix e2e/tests ci + - name: Run tests + uses: GabrielBB/xvfb-action@v1 + with: + run: npm test + - name: Run Docker E2E tests + if: ${{matrix.os == 'ubuntu-latest'}} + run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}" + + deploy: + needs: + - sonar + - test + runs-on: ubuntu-latest + steps: + - name: Set up Git repository + uses: actions/checkout@v2 + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: 14 + - name: Publish snapshot release + run: bash ./.build/pre-release.sh + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/tagged_release.yaml b/.github/workflows/tagged_release.yaml new file mode 100644 index 00000000..bc22c7c9 --- /dev/null +++ b/.github/workflows/tagged_release.yaml @@ -0,0 +1,57 @@ +name: Create tagged release +on: + push: + tags: + - v*.*.* + +jobs: + test: + needs: + - sonar + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + node: [ 10, 12, 14 ] + runs-on: ${{matrix.os}} + steps: + - name: Set up Git repository + uses: actions/checkout@v2 + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: ${{matrix.node}} + - name: Setup Docker + if: ${{matrix.os == 'ubuntu-latest'}} + run: | + docker pull s1hofmann/nut-ci:latest + docker run -it -d --name nut-ci --shm-size 4gb --user $(id -u):$(id -g) -v ${PWD}:${PWD}:rw s1hofmann/nut-ci:latest bash + - name: Install + run: npm ci + - name: Compile + run: npm run compile + - name: Init e2e test subpackage + run: npm --prefix e2e/tests ci + - name: Generate coverage report + uses: GabrielBB/xvfb-action@v1 + with: + run: npm test + - name: Run Docker E2E tests + if: ${{matrix.os == 'ubuntu-latest'}} + run: docker exec nut-ci bash -c "bash $PWD/.build/build.sh ${PWD} ${{matrix.node}}" + + deploy: + needs: + - sonar + - test + runs-on: ubuntu-latest + steps: + - name: Set up Git repository + uses: actions/checkout@v2 + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: 14 + - name: Publish tagged release + uses: JS-DevTools/npm-publish@v1 + with: + token: ${{ secrets.NPM_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 852abd63..00000000 --- a/.travis.yml +++ /dev/null @@ -1,74 +0,0 @@ -cache: npm - -os: - - osx - - linux - -osx_image: - - xcode11 - -dist: bionic - -language: node_js - -node_js: - - lts/dubnium - - 11 - - lts/erbium - - 13 - - 14 - -addons: - sonarcloud: - organization: "nut-tree" - token: - secure: "mOHkKrMl0msR9mjlkW30vcJ4R9hBZQiTrdJYFE+Islq0WT/W49RKPJmxyDiHwlBvGH483cWIuA3rC95hMZwjn2c0ybQ+M1gzkB/QKAv1FFy21Ze6H7EhFRGJ9x4fKQA2kZL3IwSMEm4ABbL5ZpcdijC2iSsFbxMXBVYhe7rHNz+rSqCPVbQV/OKc/lZeMRJ62DL2Mx6KXciO5Xq3rKANFM1yie8QLG8DNhcUv0OVtp65RDcOG30uqBOA1qDfq9VOylVKabVJN4ta2THr46ocYY1YfnUUDpcPJHQwZSL7Gl7BwMnMgiDGqZbWasJpqdlJSy6TesJGu8SI4ETWGwTE4jnrH3uegPXGqIdxOtWXPVR90U2upZ7/ztVVmABEAQN0zW0kv3Gwx2XbJ/Db4qc7OTNz5i9uf2BQ/dDEmjX4rMPYKbKFONHknq+e5dZiJGhmwC7ns7qaTIH23QZV9xyvC1ymbgbogdu17/bNvjZaPFtpnnFm49X/VWrf7Lw+rrGL62c7DHfJrYNHiky5OsQmlqyBq7Sm3O6pqtREdeZbgSAYdbn6ADIXbP7luhlSfM0oZ+GuPv3vGqapr41YVE70vs33ehLUDiDqY5F0sKDXLp4vvucupx2YSOx1KJDxaXmfAZAnL3/RVzGFByyGOeF8TQLV29T4cdPcl0wpbJcpmgI=" - -services: - - docker - - xvfb - -install: - - "bash ./.build/setup_${TRAVIS_OS_NAME}.sh" -script: - - "bash ./.build/run_${TRAVIS_OS_NAME}.sh" - -stages: - - sonar - - test - - name: deploy - if: (branch = develop) OR (tag IS present) - -jobs: - exclude: - - stage: test - node_js: lts/erbium - os: linux - - include: - - stage: sonar - os: linux - dist: bionic - node_js: lts/erbium - after_success: - - sonar-scanner - - stage: deploy - os: osx - osx_image: xcode11 - language: node_js - node_js: lts/erbium - install: true - script: true - before_deploy: - - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" >> $HOME/.npmrc 2> /dev/null - deploy: - - provider: script - skip_cleanup: false - script: bash ./.build/pre-release.sh - on: - branch: develop - - provider: script - skip_cleanup: false - script: npm ci && npm publish - on: - tags: true diff --git a/README.md b/README.md index 07eb5911..45e0ac15 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # nut.js (Native UI Toolkit) -| |Travis |Appveyor | -|:-: |:-: |:-: | -|Master |[![Build Status](https://travis-ci.com/nut-tree/nut.js.svg?branch=master)](https://travis-ci.com/nut-tree/nut.js)|[![Build status](https://ci.appveyor.com/api/projects/status/iohwxc5t46gcuvby/branch/master?svg=true)](https://ci.appveyor.com/project/s1hofmann/nut-js/branch/master)| -|Develop|[![Build Status](https://travis-ci.com/nut-tree/nut.js.svg?branch=develop)](https://travis-ci.com/nut-tree/nut.js)|[![Build status](https://ci.appveyor.com/api/projects/status/iohwxc5t46gcuvby/branch/develop?svg=true)](https://ci.appveyor.com/project/s1hofmann/nut-js/branch/develop)| +| |GitHub Actions| +|:-: |:-: | +|Master |![Run CI](https://github.com/nut-tree/nut.js/workflows/Run%20CI/badge.svg?branch=master)| +|Develop|![Run CI](https://github.com/nut-tree/nut.js/workflows/Run%20CI/badge.svg?branch=develop)| ![Supported node versions](https://img.shields.io/badge/node-v10.x%20--%20v14.x-green) [![SonarCloud badge](https://sonarcloud.io/api/project_badges/measure?project=nut-tree%3Anut.js&metric=alert_status)](https://sonarcloud.io/dashboard?id=nut-tree%3Anut.js) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 59c12e57..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,31 +0,0 @@ -platform: - - x64 - -image: - - Visual Studio 2017 - -init: - - git config --global core.autocrlf true - -environment: - matrix: - - nodejs_version: "10" - - nodejs_version: "11" - - nodejs_version: "12" - - nodejs_version: "13" - - nodejs_version: "14" - -clone_folder: c:\projects\nut - -install: - - ps: Install-Product node $env:nodejs_version x64 - - node --version - - cd c:\projects\nut - - npm ci - - npm run compile - - npm --prefix e2e/tests ci - -build: off - -test_script: - - npm test diff --git a/e2e/tests/packages/window-integration-tests/constants.js b/e2e/tests/packages/window-integration-tests/constants.js index 4e187e7b..8b7a520c 100644 --- a/e2e/tests/packages/window-integration-tests/constants.js +++ b/e2e/tests/packages/window-integration-tests/constants.js @@ -1,7 +1,7 @@ const POS_X = 50; const POS_Y = 100; -const WIDTH = 800; -const HEIGTH = 600; +const WIDTH = 400; +const HEIGTH = 300; const TITLE = "libnut window test"; module.exports = { diff --git a/e2e/tests/packages/window-integration-tests/test.js b/e2e/tests/packages/window-integration-tests/test.js index 8fb7b8c5..fdb92d3c 100644 --- a/e2e/tests/packages/window-integration-tests/test.js +++ b/e2e/tests/packages/window-integration-tests/test.js @@ -1,13 +1,18 @@ const Application = require("spectron").Application; const electronPath = require("electron"); const {getActiveWindow, getWindows} = require("@nut-tree/nut-js"); -const { POS_X, POS_Y, WIDTH, HEIGTH, TITLE } = require("./constants"); -const { join } = require("path"); +const {POS_X, POS_Y, WIDTH, HEIGTH, TITLE} = require("./constants"); +const {join} = require("path"); + +const sleep = async (ms) => { + return new Promise(resolve => setTimeout(resolve, ms)); +}; let app; const APP_TIMEOUT = 10000; +jest.setTimeout(3 * APP_TIMEOUT) -beforeAll(async () => { +beforeEach(async () => { app = new Application({ path: electronPath, args: [join(__dirname, 'main.js')], @@ -65,6 +70,7 @@ describe("getActiveWindow", () => { const xPosition = 42; const yPosition = 23; await app.browserWindow.setPosition(xPosition, yPosition); + await sleep(1000); // WHEN const foregroundWindow = await getActiveWindow(); @@ -78,8 +84,9 @@ describe("getActiveWindow", () => { it("should determine correct window size for our application after resizing the window", async () => { // GIVEN const newWidth = 400; - const newHeight = 250; + const newHeight = 350; await app.browserWindow.setSize(newWidth, newHeight); + await sleep(1000); // WHEN const foregroundWindow = await getActiveWindow(); @@ -91,7 +98,7 @@ describe("getActiveWindow", () => { }); }); -afterAll(async () => { +afterEach(async () => { if (app && app.isRunning()) { await app.stop(); } diff --git a/sonar-project.properties b/sonar-project.properties index 43b03709..1f120d9d 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,5 @@ sonar.projectKey=nut-tree:nut.js +sonar.organization=nut-tree sonar.sources=lib/,index.ts sonar.javascript.lcov.reportPaths=coverage/merged/lcov.info sonar.typescript.lcov.reportPaths=coverage/merged/lcov.info