From 0e91dc70b055af191689cb6ecb5df71f879379e7 Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Tue, 6 Aug 2024 17:09:06 +0100 Subject: [PATCH] add gh actions for building and testing the repo --- .github/actions/yarn-install/action.yml | 27 +++++++++++++ .github/scripts/install_codecov.sh | 16 ++++++++ .github/workflows/build-and-test.yml | 51 +++++++++++++++++++++++++ package.json | 3 ++ 4 files changed, 97 insertions(+) create mode 100644 .github/actions/yarn-install/action.yml create mode 100755 .github/scripts/install_codecov.sh create mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/actions/yarn-install/action.yml b/.github/actions/yarn-install/action.yml new file mode 100644 index 0000000000..a38551bd9e --- /dev/null +++ b/.github/actions/yarn-install/action.yml @@ -0,0 +1,27 @@ +name: Install Dependencies +inputs: + node-version-type: + required: false + default: 'current' + type: choice + options: + - 'current' + - 'min-supported' + min-supported-node-version: + required: false + default: '18.12' + current-node-version: + required: false + default: '20.2' + +runs: + using: "composite" + steps: + - uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version-type == 'current' && inputs.current-node-version || inputs.min-supported-node-version }} + cache: yarn + cache-dependency-path: yarn.lock + - name: Install Dependencies + run: yarn install --frozen-lockfile --non-interactive --ignore-scripts + shell: bash diff --git a/.github/scripts/install_codecov.sh b/.github/scripts/install_codecov.sh new file mode 100755 index 0000000000..13b8e631d8 --- /dev/null +++ b/.github/scripts/install_codecov.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Install Codecov Uploader +# See https://docs.codecov.com/docs/codecov-uploader#using-the-uploader-with-codecovio-cloud + +CODECOV_URL="https://uploader.codecov.io" + +curl "${CODECOV_URL}/verification.gpg" | gpg --no-default-keyring --keyring trustedkeys.gpg --import +curl -Os "${CODECOV_URL}/latest/linux/codecov" +curl -Os "${CODECOV_URL}/latest/linux/codecov.SHA256SUM" +curl -Os "${CODECOV_URL}/latest/linux/codecov.SHA256SUM.sig" + +gpgv codecov.SHA256SUM.sig codecov.SHA256SUM +shasum -a 256 -c codecov.SHA256SUM + +chmod +x codecov diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000000..0b46f93aa6 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,51 @@ +name: facebook/metro/build-and-test +on: + pull_request: + types: [opened, synchronize] + +# head_ref is per PR, so this ensures that updating the latest PR commit +# will cancel the previous run of the workflow and trigger a new one +concurrency: + group: "build-and-test-${{ github.head_ref }}" + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + run-js-checks: + runs-on: ubuntu-latest + name: "Typescript, Lint, Smoke Test" + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + - run: yarn typecheck + - run: yarn typecheck-ts + - run: yarn lint + - run: yarn test-smoke + + test-with-coverage: + runs-on: ubuntu-latest + name: "Test Coverage Calculation" + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + - run: yarn test-coverage + - run: "./.github/scripts/install_codecov.sh" + - run: "./codecov -t ${{ secrets.CODECOV_TOKEN }} -f ./coverage/coverage-final.json" + + test: + strategy: + matrix: + runs-on: ['ubuntu-latest'] # 'windows-latest' + node-version-type: ['current', 'min-supported'] + name: "Tests [${{ matrix.runs-on }} machine, ${{ matrix.node-version-type }} Node.js]" + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + with: + node-version-type: ${{ matrix.node-version-type }} + - name: Run Jest Tests + run: yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit --rootdir='./' diff --git a/package.json b/package.json index 734caf4fd7..e2d0fc7450 100644 --- a/package.json +++ b/package.json @@ -94,5 +94,8 @@ "dependencies": {}, "engines": { "node": ">=18" + }, + "volta": { + "node": "18.0.0" } }