From 6d9af541de9feb67d461d95c8069615303226bcc Mon Sep 17 00:00:00 2001 From: Vaughan Jones Date: Fri, 17 May 2024 13:09:54 +1000 Subject: [PATCH] Moves all CI to GitHub Actions (#610) - Adds the remaining steps to GitHub Actions: `lint`, `build`, and `publish`. There is a slight change in that we now always run the `lint` and `build` steps - We also now perform the `lint`, `build`, and `publish` steps using the Node version in `.nvmrc`, rather than explicitly using Node 14 as we did in CircleCI - Removes the CircleCI configuration Once approved, I'll disable CircleCI prior to merging. --- .circleci/config.yml | 139 --------------------------------------- .github/workflows/ci.yml | 81 ++++++++++++++++++++++- README.md | 2 +- 3 files changed, 79 insertions(+), 143 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8833c02..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,139 +0,0 @@ -version: 2.1 - -executors: - node14: - docker: - - image: cimg/node:14.21.3 - resource_class: small - working_directory: ~/repo - - node16: - docker: - - image: cimg/node:16.20.1 - resource_class: small - working_directory: ~/repo - - node18: - docker: - - image: cimg/node:18.18.1 - resource_class: small - working_directory: ~/repo - - node20: - docker: - - image: cimg/node:20.10.0 - resource_class: small - working_directory: ~/repo - - -commands: - install-dependencies: - description: Convenience command to install the dependencies, cached. - steps: - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package.json" }} - - v1-dependencies- - - run: - name: Install main dependencies - command: yarn install --frozen-lockfile - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package.json" }} - - run-tests: - description: A helper command to do the full set of steps to run the tests. - steps: - - checkout - - install-dependencies - - run: - name: Run the unit tests - environment: - JEST_JUNIT_OUTPUT_DIR: ./test-reports/jest - JEST_JUNIT_OUTPUT_NAME: results.xml - JEST_JUNIT_CLASSNAME: "{filepath}" - command: yarn ci:test - - store_test_results: - path: ./test-reports - - -jobs: - run-tests: - parameters: - node-version: - type: string - description: The major version of NodeJS to use. - executor: node<< parameters.node-version >> - steps: - - run-tests - - build-and-run: - executor: node14 - steps: - - checkout - - install-dependencies - - run: yarn build - - run: npm link - - run: npx proxay --help - - run: | - npx proxay -m record -h https://www.google.com -t tapes/ & - # Wait until it loads. - until (curl http://localhost:3000 2>&1 | grep Google &>/dev/null) - do - echo "Waiting until server ready..." - sleep 5 - done - - lint-check: - executor: node14 - steps: - - checkout - - install-dependencies - - run: - name: Run prettier - command: yarn lint:check - - publish: - executor: node14 - steps: - - checkout - - install-dependencies - - run: yarn build - - run: - name: Authenticate with registry - command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc - - run: - name: Publish - command: npm publish --access=public - - -workflows: - build-and-test: - jobs: - - run-tests: - name: test-node<< matrix.node-version >> - matrix: - parameters: - node-version: ["14", "16", "18", "20"] - filters: - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ - - build-and-run: - filters: - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ - - lint-check: - filters: - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ - - publish: - requires: - - run-tests - - build-and-run - - lint-check - filters: - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ - branches: - ignore: /.*/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c43e44..c688511 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,14 +7,15 @@ on: push: branches: - master - tags: - - 'v*.*.*' + release: + types: [published] jobs: test: name: "test-node-${{ matrix.node-version }}" runs-on: ubuntu-latest strategy: + fail-fast: false matrix: node-version: [14, 16, 18, 20] steps: @@ -25,7 +26,6 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - cache: 'yarn' - name: Install dependencies run: yarn install --frozen-lockfile @@ -47,3 +47,78 @@ jobs: uses: test-summary/action@v2 with: paths: ./test-reports/jest/results.xml + + lint: + name: "lint" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: 'yarn' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run prettier + run: yarn lint:check + + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: 'yarn' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - run: yarn build + - run: npm link + - run: npx proxay --help + - run: | + npx proxay -m record -h https://www.google.com -t tapes/ & + # Wait until it loads. + until (curl http://localhost:3000 2>&1 | grep Google &>/dev/null) + do + echo "Waiting until server ready..." + sleep 5 + done + + publish: + runs-on: ubuntu-latest + if: github.event_name == 'release' + needs: + - test + - build + - lint + env: + # Used in setup-node and publish steps + NODE_AUTH_TOKEN: ${{ secrets.NPMJS_PUBLISH_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: 'yarn' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - run: yarn build + + - name: Publish to npm registry + run: npm publish --provenance --access public diff --git a/README.md b/README.md index 487201c..1befd14 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ To release a new version of Proxay, follow the following two steps: 1. Visit the [releases page](https://github.com/airtasker/proxay/releases) to see what was last announced. 2. Draft a new release: - - Tag = `v[version]` (e.g. `v2.1.1`). **Do not forget the `v`, which is required to trigger the NPM publish on CircleCI.** + - Tag = `v[version]` (e.g. `v2.1.1`). **Do not forget the `v`, which is required to trigger the NPM publish in GitHub Actions.** - Title = `Release v[version]` (e.g. `Release v2.1.1`) 3. Make sure to announce major changes since the last version in the description. 4. Once published, [check CircleCI](https://circleci.com/gh/airtasker/proxay) to ensure publication was successful.