diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index cf0fc19a6..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,96 +0,0 @@ -version: 2 -jobs: - lint: - docker: - - image: circleci/node:12 - - steps: - - checkout - - - run: yarn install - - run: yarn run lint - - - save_cache: - paths: - - node_modules - key: js-sdk-dependencies-{{ checksum "package.json" }} - - # build on node 8 - build: - docker: - - image: circleci/node:12 - steps: - - checkout - - # restore `npm` dependencies cache - - restore_cache: - keys: - - js-sdk-dependencies-{{ checksum "package.json" }} - - # build bundles - - run: yarn run rollup - - # test on node 8 - test: - docker: - - image: circleci/node:12 - steps: - - checkout - - # restore `npm` dependencies cache - - restore_cache: - keys: - - js-sdk-dependencies-{{ checksum "package.json" }} - - # build bundles - - run: yarn run rollup - - # run tests - - run: - command: yarn run test-output - environment: - MOCHA_FILE: test-results/mocha/test-results.xml - when: always - - - store_test_results: - path: test-results - - store_artifacts: - path: test-results - - # run `semantic-release` for release, publishing - release: - docker: - - image: cimg/node:16.10.0 - steps: - - checkout - - # restore `npm` dependencies cache - - restore_cache: - keys: - - js-sdk-dependencies-{{ checksum "package.json" }} - - # build bundles - - run: yarn run rollup - - # release, publish package - - run: npx semantic-release - -workflows: - version: 2 - build_test_release: - jobs: - - lint - - build: - requires: - - lint - - test: - requires: - - build - - release: - filters: - branches: - only: - - master - - beta - requires: - - test diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f4497571e..9b12ae000 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,27 +1,109 @@ -name: CI +name: CI/CD for the js-sdk -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch on: + push: pull_request: - types: [opened,reopened] + branches: + - 'main' + - 'beta' -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" + # This job uses skip-duplicate-actions to skip one of the duplicate workflow runs when you push to a branch with an open PR. + check_duplicate_workflow: + needs: [] + runs-on: ubuntu-20.04 + outputs: + should_skip: ${{ steps.skip_check.outputs.should_skip }} + steps: + - id: skip_check + uses: fkirc/skip-duplicate-actions@v3.4.1 + with: + skip_after_successful_duplicate: 'true' + concurrent_skipping: 'same_content_newer' + + lint: + needs: [check_duplicate_workflow] + runs-on: ubuntu-20.04 + if: ${{ needs.check_duplicate_workflow.outputs.should_skip != 'true' }} + steps: + - name: Check out repository code + uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '12' + cache: 'yarn' + - name: Run lint + run: | + yarn install + yarn lint + build: - # The type of runner that the job will run on - runs-on: ubuntu-latest + needs: [check_duplicate_workflow] + runs-on: ubuntu-20.04 + steps: + - name: Check out repository code + uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '12' + cache: 'yarn' + - name: Build bundles + run: | + yarn install + yarn rollup + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{ github.event.repository.name }}-${{ github.sha }}-${{ github.run_id }}-bundles + path: dist + retention-days: 3 - # Steps represent a sequence of tasks that will be executed as part of the job + test: + needs: [check_duplicate_workflow] + runs-on: ubuntu-20.04 + env: + MOCHA_FILE: test-results/mocha/test-results.xml + steps: + - name: Check out repository code + uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '12' + cache: 'yarn' + - name: Run tests + run: | + yarn install + yarn test-output + - name: Upload test results + uses: actions/upload-artifact@v2 + with: + name: ${{ github.event.repository.name }}-${{ github.sha }}-${{ github.run_id }}-${{ github.job }}-results + path: test-results + retention-days: 3 + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@v1.27 + with: + files: test-results/**/*.xml + + release: + needs: [lint, build, test] + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta') }} + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELASTICPATH }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Trigger CircleCI - env: - CIRCLE_BRANCH: ${{ github.head_ref }} - run: | - curl -X POST \ - -H 'Circle-Token: ${CIRCLE_TOKEN}' \ - -H 'Content-Type: application/json' \ - -H 'Accept: application/json' \ - -d "{\"branch\":\"${CIRCLE_BRANCH}\"}" \ - https://circleci.com/api/v2/project/gh/moltin/js-sdk/pipeline + - name: Check out repository code + uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '16.10.0' + cache: 'yarn' + - name: Download build artifacts + uses: actions/download-artifact@v2 + with: + name: ${{ github.event.repository.name }}-${{ github.sha }}-${{ github.run_id }}-bundles + - name: Release, publish package + run: | + yarn install + npx semantic-release diff --git a/README.md b/README.md index 75292566c..51efe22cf 100644 --- a/README.md +++ b/README.md @@ -275,4 +275,4 @@ You can learn more about the Rollup API and configuration [here](https://github. ## Terms And Conditions - Any changes to this project must be reviewed and approved by the repository owner. For more information about contributing, see the [Contribution Guide](https://github.com/moltin/gatsby-demo-store/blob/master/.github/CONTRIBUTING.md). -- For more information about the license, see [MIT License](https://github.com/moltin/js-sdk/blob/master/LICENSE). +- For more information about the license, see [MIT License](https://github.com/moltin/js-sdk/blob/main/LICENSE). diff --git a/package.json b/package.json index 584b68a53..6c69d1fb7 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "type": "git", "url": "git://github.com/moltin/js-sdk.git" }, + "release": { + "branches": ["main", "beta"] + }, "bugs": { "url": "https://github.com/moltin/js-sdk/issues" },