diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 26c3e4f57..2ebe62839 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,11 +15,58 @@ env: jobs: build-and-test: runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash strategy: fail-fast: false matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [16, 18, 20, 22] os: [macos-14, macos-12, ubuntu-latest, windows-latest] + docker: [false] + include: + - os: ubuntu-latest + docker: true + alpine: false + arch: arm64 + node-version: 22 + - os: ubuntu-latest + docker: true + alpine: true + arch: arm64 + node-version: 22 + - os: ubuntu-latest + docker: true + alpine: true + arch: amd64 + node-version: 22 + - os: ubuntu-latest + docker: true + alpine: false + arch: arm64 + node-version: 20 + - os: ubuntu-latest + docker: true + alpine: true + arch: arm64 + node-version: 20 + - os: ubuntu-latest + docker: true + alpine: true + arch: amd64 + node-version: 20 + - os: ubuntu-latest + docker: true + alpine: true + arch: arm64 + node-version: 18 + - os: ubuntu-latest + docker: true + alpine: true + arch: amd64 + node-version: 18 + + name: Test ${{ matrix.docker == true && matrix.alpine == true && 'linux-musl' || matrix.docker == true && matrix.alpine == false && 'linux' || matrix.os }}-${{ matrix.arch }}-node-${{ matrix.node-version }} steps: - uses: actions/checkout@v3 @@ -29,97 +76,22 @@ jobs: uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - - run: bash scripts/ci/build-and-test.sh - shell: bash - env: - SKIP_EXAMPLES: true - - run: scripts/ci/test-examples.sh - shell: bash - env: - SETUP_DIST_ONLY: true - ## require jest-pact and mocha-pact to update peer deps - # - name: example_mocha - # run: cd examples/mocha && npm install --ignore-scripts && npm test - # - name: example_jest - # run: cd examples/jest && npm install --ignore-scripts && npm test + - run: scripts/ci/build-and-test.sh + if: ${{ matrix.docker != true }} - # passing - - name: example_e2e - run: cd examples/e2e && npm install --ignore-scripts && npm test - - name: example_graphql - run: cd examples/graphql && npm install --ignore-scripts && npm test - - name: example_messages - run: cd examples/messages && npm install --ignore-scripts && npm test - - name: example_serverless - run: cd examples/serverless && npm install --ignore-scripts && npm test - - name: example_typescript - run: cd examples/typescript && npm install --ignore-scripts && npm test - - name: example_v3_e2e - run: cd examples/v3/e2e && npm install --ignore-scripts && npm test - - name: example_v3_provider-state-injected - run: cd examples/v3/provider-state-injected && npm install --ignore-scripts && npm test - - name: example_v3_run-specific-verifications - run: cd examples/v3/run-specific-verifications && npm install --ignore-scripts && npm test - - name: example_v3_todo-consumer - run: cd examples/v3/todo-consumer && npm install --ignore-scripts && npm test - - name: example_v3_typescript - run: cd examples/v3/typescript && npm install --ignore-scripts && npm test - - name: example_v4_plugins - run: cd examples/v4/plugins && npm install --ignore-scripts && npm test - - name: example_v4_matchers - run: cd examples/v4/matchers && npm install --ignore-scripts && npm test - # - name: Upload dist folder - # if: runner.os == 'Linux' - # uses: actions/upload-artifact@v3 - # with: - # path: dist + - name: Set up QEMU + if: ${{ matrix.docker == true && matrix.arch == 'arm64' }} + uses: docker/setup-qemu-action@v3 - # examples: - # needs: [build-and-test] - # strategy: - # matrix: - # node-version: [16,18,20] - # os: [macos-latest, ubuntu-latest, windows-latest] - # example: - # [ - # e2e, - # graphql, - # jest, # requires jest-pact updating - # messages, - # mocha, # requires mocha-pact updating - # serverless, - # typescript, - # v3/e2e, - # v3/provider-state-injected, - # v3/run-specific-verifications, - # v3/todo-consumer, - # v3/typescript, - # v4/plugins, - # ] - # fail-fast: false - # runs-on: ${{ matrix.os }} + - if: ${{ matrix.docker == true && matrix.alpine != true && matrix.arch == 'arm64' }} + name: test arm64 + run: | + docker build --platform linux/${{ matrix.arch }} --build-arg=NODE_VERSION=${{ matrix.node-version }} -f Dockerfile.debian -t pact-js:${{ matrix.node-version }}-debian . + docker run --platform linux/${{ matrix.arch }} -v $PWD:/home -w /home --rm pact-js:${{ matrix.node-version }}-debian - # steps: - # - uses: actions/checkout@v3 - # with: - # fetch-depth: 0 - # - name: Download dist folder - # uses: actions/download-artifact@v3 - # - name: Use Node.js ${{ matrix.node-version }} - # uses: actions/setup-node@v3 - # with: - # node-version: ${{ matrix.node-version }} - # - run: scripts/ci/test-examples.sh - # shell: bash - # env: - # SETUP_DIST_ONLY: true - # if: matrix.example != 'jest' || matrix.example != 'mocha' - # - run: bash scripts/install-plugins.sh - # if: matrix.example == 'v4/plugins' - # - name: run example ${{ matrix.example }} - # run: | - # npm install --ignore-scripts - # npm test - # shell: bash - # working-directory: examples/${{ matrix.example }} + - if: ${{ matrix.docker == true && matrix.alpine == true }} + name: test linux amd64 musl + run: | + docker build --platform linux/${{ matrix.arch }} --build-arg=NODE_VERSION=${{ matrix.node-version }} -f Dockerfile.alpine -t pact-js:${{ matrix.node-version }}-alpine . + docker run --platform linux/${{ matrix.arch }} -v $PWD:/home -w /home --rm pact-js:${{ matrix.node-version }}-alpine \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 000000000..f0cdcbb9f --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,9 @@ +ARG NODE_VERSION=latest +FROM node:${NODE_VERSION}-alpine + +RUN apk add bash curl git file libc6-compat gcompat +# libc6-compat gcompat required for @pact-foundation/pact-cli ruby runtime +# all other dependencies just used for @pact-foundation/pact testing +# so you don't need to use those in your own projects + +ENTRYPOINT [ "bash", "-c", "scripts/ci/build-and-test.sh" ] \ No newline at end of file diff --git a/Dockerfile.debian b/Dockerfile.debian new file mode 100644 index 000000000..d356d73ff --- /dev/null +++ b/Dockerfile.debian @@ -0,0 +1,6 @@ +ARG NODE_VERSION=latest +FROM node:${NODE_VERSION}-slim + +RUN apt-get -y update && apt-get -y install curl git + +ENTRYPOINT [ "bash", "-c", "scripts/ci/build-and-test.sh" ] \ No newline at end of file