From 78325dc307b779c2a0156fbd02cf681e8c02af89 Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Mon, 5 Aug 2024 14:18:38 +0100 Subject: [PATCH] adding the deploy step --- .circleci/config.yml | 139 -------------------- .circleci/scripts/install_codecov.sh | 16 --- .circleci/scripts/publish.sh | 28 ---- .github/scripts/publish.sh | 31 +++++ .github/workflows/build-and-test.yml | 52 -------- .github/workflows/build-test-and-deploy.yml | 89 +++++++++++++ 6 files changed, 120 insertions(+), 235 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100755 .circleci/scripts/install_codecov.sh delete mode 100755 .circleci/scripts/publish.sh create mode 100755 .github/scripts/publish.sh delete mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/build-test-and-deploy.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 102de20ed0..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,139 +0,0 @@ -# CircleCI configuration -# https://circleci.com/docs/configuration-reference/ - -version: 2.1 - -orbs: - win: circleci/windows@2.4.0 - -references: - # For stability, Node.js versions we run against in CI are defined explicitly - # (the "lts" alias may bring in a future version before we support it) - node_supported_lts_versions: &node_supported_lts_versions - - &node_min_supported_version "18.12" - - "20.2" - node_lts_image: &node_lts_image cimg/node:18.12 - - secure_unset_publish_token: &secure_unset_publish_token - environment: - NPM_TOKEN: "" - -commands: - yarn_install: - description: "A wrapper to yarn install with caching" - parameters: - working_directory: - type: string - default: "" - steps: - - restore_cache: - keys: - - dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }} - - dependencies-{{ .Branch }}- - - run: - name: Installing dependencies - command: yarn --frozen-lockfile --non-interactive --ignore-scripts - working_directory: << parameters.working_directory >> - - save_cache: - paths: - - node_modules - key: dependencies-{{ .Branch }}-{{ checksum "yarn.lock" }} - - install_and_run_tests: - description: | - Install dependencies and run tests (common steps for test- jobs) - steps: - - yarn_install - - run: yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit - - store_test_results: - path: ./reports/ - -jobs: - run-js-checks: - <<: *secure_unset_publish_token - docker: - - image: *node_lts_image - steps: - - checkout - - yarn_install - - run: yarn typecheck - - run: yarn typecheck-ts - - run: yarn lint - - run: yarn test-smoke - - test-with-coverage: - <<: *secure_unset_publish_token - docker: - - image: *node_lts_image - steps: - - checkout - - yarn_install - - run: yarn test-coverage - - run: - name: Download Codecov Uploader - command: ./.circleci/scripts/install_codecov.sh - - run: - name: Upload coverage results - command: ./codecov -t ${CODECOV_TOKEN} -f ./coverage/coverage-final.json - - test: - <<: *secure_unset_publish_token - parameters: - node-version: - type: string - docker: - - image: cimg/node:<< parameters.node-version >> - steps: - - checkout - - install_and_run_tests - - test-windows: - <<: *secure_unset_publish_token - parameters: - node-version: - type: string - executor: - name: win/default - steps: - - checkout - - run: - name: Install Node.js and Yarn - command: | - choco install -y nodejs --version << parameters.node-version >> - choco install -y yarn - - install_and_run_tests - - publish-to-npm: - docker: - - image: *node_lts_image - steps: - - checkout - - yarn_install - - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc - - run: - name: Infer dist-tag and run npm run publish - command: ./.circleci/scripts/publish.sh - - run: rm ~/.npmrc - -workflows: - build-and-deploy: - jobs: - - run-js-checks - - test-with-coverage - - test: - matrix: - parameters: - node-version: *node_supported_lts_versions - - test-windows: - matrix: - parameters: - node-version: [*node_min_supported_version] - filters: - branches: - only: /windows\/.*/ - - publish-to-npm: - filters: - branches: - ignore: /.*/ - tags: - only: /v\d+(\.\d+){2}(-.*)?/ diff --git a/.circleci/scripts/install_codecov.sh b/.circleci/scripts/install_codecov.sh deleted file mode 100755 index 13b8e631d8..0000000000 --- a/.circleci/scripts/install_codecov.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/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/.circleci/scripts/publish.sh b/.circleci/scripts/publish.sh deleted file mode 100755 index 2c895c3255..0000000000 --- a/.circleci/scripts/publish.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Reduce a semver tag name to a Metro's release branch naming convention, eg v0.1.2-alpha.3 -> 0.1.x -RELEASE_BRANCH=$(echo "$CIRCLE_TAG" | awk -F. '{print substr($1, 2) "." $2 ".x"}') - -# Does a release branch contain this tag (hotfix workflow) -TAG_ON_RELEASE_BRANCH=$(git branch -a --contains "$CIRCLE_TAG" | grep -cFx " remotes/origin/$RELEASE_BRANCH" || true) -echo "Tag is on release branch $RELEASE_BRANCH: $TAG_ON_RELEASE_BRANCH" - -# Does main contain this tag (regular release workflow) -TAG_ON_MAIN=$(git branch -a --contains "$CIRCLE_TAG" | grep -cFx ' remotes/origin/main' || true) -echo "Tag is on main branch: $TAG_ON_MAIN" - -if [ $TAG_ON_RELEASE_BRANCH -eq $TAG_ON_MAIN ]; then - echo "Could not determine whether this tag is 'latest' or a hotfix. Aborting." - exit 1 -fi - -NPM_TAG="latest" -# Use a tag name like "0.123-stable" as the dist-tag for a hotfix. This *must not* be valid semver. -[ "$TAG_ON_RELEASE_BRANCH" -eq 1 ] && NPM_TAG="${RELEASE_BRANCH%.x}-stable" -echo "Publishing with --tag=$NPM_TAG" - -npm run publish --tag="$NPM_TAG" diff --git a/.github/scripts/publish.sh b/.github/scripts/publish.sh new file mode 100755 index 0000000000..3338b947a9 --- /dev/null +++ b/.github/scripts/publish.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# See https://github.com/facebook/metro/pull/1086 regarding handling of hotfix tags + +# Does main contains this tag (regular release workflow) +TAG_ON_MAIN=$(git branch -a --contains "$RAW_TAG_NAME" | grep -cFx ' remotes/origin/main' || true) +echo "Tag is on main branch: $TAG_ON_MAIN" + +# Deduce the expected name of a release branch for a tag based on Metro's release branch naming convention, eg v0.1.2-alpha.3 -> 0.1.x +RELEASE_BRANCH=$(echo "$RAW_TAG_NAME" | awk -F. '{print substr($1, 2) "." $2 ".x"}') + +# Does a release branch contains this tag (hotfix workflow) +git fetch -v --depth=1 +TAG_ON_RELEASE_BRANCH=$(git branch -a --contains "$RAW_TAG_NAME" | grep -cFx " remotes/origin/$RELEASE_BRANCH" || true) +echo "Tag is on release branch $RELEASE_BRANCH: $TAG_ON_RELEASE_BRANCH" + +if [ $TAG_ON_RELEASE_BRANCH -eq $TAG_ON_MAIN ]; then + echo "Could not determine whether this tag is 'latest' or a hotfix. Aborting." + exit 1 +fi + +NPM_TAG="latest" +# Use a tag name like "0.123-stable" as the dist-tag for a hotfix. This *must not* be valid semver. +[ "$TAG_ON_RELEASE_BRANCH" -eq 1 ] && NPM_TAG="${RELEASE_BRANCH%.x}-stable" +echo "Publishing with --tag=$NPM_TAG" + +npm run publish --tag="$NPM_TAG" --dry-run diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index d9dc0bded1..0000000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: facebook/metro/build-and-test -on: - workflow_call: - 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: ['lts', '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/.github/workflows/build-test-and-deploy.yml b/.github/workflows/build-test-and-deploy.yml new file mode 100644 index 0000000000..8c6f83c1fd --- /dev/null +++ b/.github/workflows/build-test-and-deploy.yml @@ -0,0 +1,89 @@ +name: facebook/metro/build-test-and-deploy +on: + workflow_call: + pull_request: + types: [opened, synchronize] + push: + tags: +# The job is triggered for any tag push. Tag format validation will be done +# as part of the deploy job for clearer error reporting on tag formatting + - '**' + +# 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-test-and-deploy-${{ 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: ['lts', '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='./' + + validate-tag: + # runs only on tag pushes + if: ${{ github.ref_type == 'tag' }} + runs-on: ubuntu-latest + name: "Validate Tag For Deployment" + steps: + - uses: actions/github-script@v7 + with: + script: | + if (/^v\d+(\.\d+){2}(-.*)?$/.test('${{ github.ref_name }}')) { + return true; + } else { + core.setFailed('ERROR! Wrong tag format failed the package deployment!'); + } + + deploy: + # runs only on tag pushes + if: ${{ github.ref_type == 'tag' }} + runs-on: ubuntu-latest + name: "Deploy" + # needs: [run-js-checks, test, validate-tag] + needs: [validate-tag] + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/yarn-install + - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc + - run: "./.github/scripts/publish.sh" + env: + RAW_TAG_NAME: ${{ github.ref_name }} + - run: rm ~/.npmrc +