From 2d272bc32063203537acafc35b63ebe6935acbdf Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Thu, 1 Aug 2024 15:01:06 +0100 Subject: [PATCH] add the gh actions setup file --- .github/actions/yarn-install/action.yml | 19 ++++++++ .github/workflows/build-and-deploy.yml | 34 ++++++++++++++ .github/workflows/build-and-test.yml | 60 +++++++++++++++++++++++++ package.json | 3 ++ 4 files changed, 116 insertions(+) create mode 100644 .github/actions/yarn-install/action.yml create mode 100644 .github/workflows/build-and-deploy.yml 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..1eddbdac9a --- /dev/null +++ b/.github/actions/yarn-install/action.yml @@ -0,0 +1,19 @@ +name: Install Dependencies +inputs: + use-min-supported-version: + required: false + default: false + +runs: + using: "composite" + steps: + - uses: actions/setup-node@v4 + with: + # if both node-version-file and node-version are provided, node-version is used + node-version-file: 'package.json' + node-version: ${{ inputs.use-min-supported-version == 'false' && 'lts/*' || '' }} + 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/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000000..3695ba9659 --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,34 @@ +name: facebook/metro/build-and-deploy +on: + push: + +defaults: + run: + shell: bash + +jobs: + build-and-test: + uses: ./.github/workflows/build-and-test.yml + secrets: inherit + + publish-to-npm: + needs: build-and-test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + with: + use-min-supported-version: true + - name: Check Tag Format + id: check_tag + run: | + if [[ $GITHUB_REF =~ ^refs/tags/v\d+(\.\d+){2}(-.*)?$ ]]; then + echo "valid=true" >> $GITHUB_OUTPUT + else + echo "valid=false" >> $GITHUB_OUTPUT + fi + - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc + - name: Infer dist-tag and run npm run publish + if: steps.check_tag.outputs.valid == 'true' + run: "./.circleci/scripts/publish.sh" + - run: rm ~/.npmrc diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000000..0863d9c72b --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,60 @@ +name: facebook/metro/build-and-test +on: + workflow_call: + pull_request: + types: [synchronize] + +# head_ref is per PR, so this ensures that updaing a PR +# will cancel the previous run of the workflow +concurrency: + group: "build-and-test-${{ github.head_ref }}" + cancel-in-progress: true + +defaults: + run: + shell: bash + +jobs: + run-js-checks: + runs-on: ubuntu-latest + 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 + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + - run: yarn test-coverage + - name: Download Codecov Uploader + run: "./.circleci/scripts/install_codecov.sh" + - name: Upload coverage results + run: "./codecov -t ${{ secrets.CODECOV_TOKEN }} -f ./coverage/coverage-final.json" + + test: + runs-on: ubuntu-latest + strategy: + matrix: + use-min-supported-version: [true, false] + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + with: + use-min-supported-version: ${{ matrix.use-min-supported-version }} + - name: Run Jest tests + run: yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit + + test-windows: + if: startsWith(github.ref, 'refs/heads/windows/') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + - name: Run Jest tests + run: yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit +# todo: how many max workers are best performing? diff --git a/package.json b/package.json index c5f7e05cb6..112f5ce789 100644 --- a/package.json +++ b/package.json @@ -94,5 +94,8 @@ "dependencies": {}, "engines": { "node": ">=18" + }, + "volta": { + "node": "18.0.0" } }