version: 2.1

workflows:
  build:
    jobs:
      - linux-arm64-glibc-node-12:
          filters:
            tags:
              only: /^v.*/
      - linux-arm64-musl-node-12:
          filters:
            tags:
              only: /^v.*/
      - linux-arm64-glibc-node-16:
          filters:
            tags:
              only: /^v.*/
      - linux-arm64-musl-node-16:
          filters:
            tags:
              only: /^v.*/

jobs:
  linux-arm64-glibc-node-12:
    resource_class: arm.medium
    machine:
      image: ubuntu-2004:202101-01
    steps:
      - checkout
      - run: |
          sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
          sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl"
          sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
          sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_12.x sid main' >/etc/apt/sources.list.d/nodesource.list"
          sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
      - run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
      - run: sudo docker exec sharp sh -c "npm test"
      - run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"npx prebuild --runtime napi --target 5 --upload=$prebuild_upload\" || true"
  linux-arm64-glibc-node-16:
    resource_class: arm.medium
    machine:
      image: ubuntu-2004:202101-01
    steps:
      - checkout
      - run: |
          sudo chown 0.0 ${PWD}
          sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
          sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl"
          sudo docker exec sharp sh -c "curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -"
          sudo docker exec sharp sh -c "echo 'deb https://deb.nodesource.com/node_16.x sid main' >/etc/apt/sources.list.d/nodesource.list"
          sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
      - run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
      - run: sudo docker exec sharp sh -c "npm test"
  linux-arm64-musl-node-12:
    resource_class: arm.medium
    machine:
      image: ubuntu-2004:202101-01
    steps:
      - checkout
      - run: |
          sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:12-alpine3.11
          sudo docker exec sharp sh -c "apk add build-base git python3 --update-cache"
      - run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
      - run: sudo docker exec sharp sh -c "npm test"
      - run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"npx prebuild --runtime napi --target 5 --upload=$prebuild_upload\" || true"
  linux-arm64-musl-node-16:
    resource_class: arm.medium
    machine:
      image: ubuntu-2004:202101-01
    steps:
      - checkout
      - run: |
          sudo chown 0.0 ${PWD}
          sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:16-alpine3.11
          sudo docker exec sharp sh -c "apk add build-base git python3 --update-cache"
      - run: sudo docker exec sharp sh -c "npm install --build-from-source --unsafe-perm"
      - run: sudo docker exec sharp sh -c "npm test"
