diff --git a/.github/workflows/main.pr.yml b/.github/workflows/main.pr.yml new file mode 100644 index 00000000..602691cb --- /dev/null +++ b/.github/workflows/main.pr.yml @@ -0,0 +1,110 @@ +name: Build pull request + +on: + pull_request: + branches: + - "master" + +jobs: + lint-pull-request: + name: Lint pull request + runs-on: ubuntu-20.04 + strategy: + fail-fast: true + matrix: + node: [18.x] + steps: + - name: Setup node v${{ matrix.node }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Cache node_modules + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-node_modules-${{ matrix.node }}-${{ hashFiles('package.json') }} + path: | + node_modules + + - name: Check if source or test files changed + id: files_changed + uses: tj-actions/changed-files@v9.1 + with: + files: | + src/**/* + spec/**/* + + - name: Install dependencies + if: ${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }} + run: | + yarn + + - name: Lint files + if: ${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }} + run: | + yarn lint + + build-and-test-pull-request: + needs: + - lint-pull-request + name: Build and test pull request + runs-on: ubuntu-20.04 + strategy: + fail-fast: true + matrix: + node: [14.x, 16.x, 18.x] + module: [cjs, esm, umd] + target: [es5, es2015, esnext] + steps: + - name: Setup node v${{ matrix.node }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + - name: Checkout + uses: actions/checkout@v3 + + - name: Cache targets + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-targets-${{ matrix.node }}-${{ matrix.target }}-${{ matrix.module }}-${{ hashFiles('package.json') }} + path: | + targets + + - name: Cache node_modules + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-node_modules-${{ matrix.node }}-${{ matrix.target }}-${{ matrix.module }}-${{ hashFiles('package.json') }} + path: | + node_modules + + - name: Check if test files changed + id: test_files_changed + uses: tj-actions/changed-files@v9.1 + with: + files: | + spec/**/* + + - name: Check if source files changed + id: source_files_changed + uses: tj-actions/changed-files@v9.1 + with: + files: | + src/**/* + + - name: Install dependencies + if: ${{ steps.test_files_changed.outputs.any_changed == 'true' || steps.test_files_changed.outputs.any_deleted == 'true' || steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }} + run: | + yarn + + - name: Build package + if: ${{ steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }} + run: | + yarn build -t ${{ matrix.target }} -m ${{ matrix.module }} + + - name: Test package + if: ${{ steps.test_files_changed.outputs.any_changed == 'true' || steps.test_files_changed.outputs.any_deleted == 'true' || steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }} + run: | + yarn test -t ${{ matrix.target }} -m ${{ matrix.module }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6a3d6d86..00000000 --- a/.travis.yml +++ /dev/null @@ -1,44 +0,0 @@ -sudo: false - -language: node_js - -node_js: - - "node" # the latest stable nodejs - -notifications: - email: false - -cache: - yarn: true - -env: - global: - - PATH=$HOME/.yarn/bin:$HOME/.local/bin:$PATH - matrix: - - CI_MATRIX_BUILD=true - - CI_MATRIX_LINT=true - - CI_MATRIX_TEST=true - -before_install: - # Use the latest yarnpkg because Travis' builtin yarn is not the latest. - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH=$HOME/.yarn/bin:$PATH - - which yarn # for debugging Travis - - echo $PATH # for debugging Travis - - node -v && npm i -g npm && npm -v - -script: - - | - if [ "$CI_MATRIX_BUILD" = "true" ]; then - yarn build - elif [ "$CI_MATRIX_LINT" = "true" ]; then - yarn lint - elif [ "$CI_MATRIX_TEST" = "true" ]; then - npm run build -- -t es5 -t es2015 -t esnext -m umd - npm run test -- -t es5 -m umd - npm run test -- -t es2015 -m umd - npm run test -- -t esnext -m umd - else - echo "This code path is run unexpectedly" 1>&2 - exit 1 - fi