diff --git a/.dockerignore b/.dockerignore index 3c3629e6..ccc29308 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -node_modules +/coverage +/node_modules diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9e9d40e..d877164a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,12 +44,14 @@ jobs: with: version: ${{ matrix.version }} args: check --debug + workdir: ./test - name: GoReleaser uses: ./ with: version: ${{ matrix.version }} args: release --skip-publish --rm-dist + workdir: ./test install-only: runs-on: ubuntu-latest @@ -115,6 +117,7 @@ jobs: with: version: latest args: -f .goreleaser-signing.yml check --debug + workdir: ./test env: GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} - @@ -123,6 +126,7 @@ jobs: with: version: latest args: -f .goreleaser-signing.yml release --skip-publish --rm-dist + workdir: ./test env: GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} @@ -144,11 +148,13 @@ jobs: uses: ./ with: args: check --debug + workdir: ./test - name: GoReleaser uses: ./ with: args: release --skip-publish --rm-dist + workdir: ./test - name: Upload assets uses: actions/upload-artifact@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 560a1157..93790e95 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,55 +3,32 @@ name: test on: push: branches: - - master - - releases/v* - paths-ignore: - - '**.md' + - 'master' + - 'releases/v*' pull_request: - paths-ignore: - - '**.md' + branches: + - 'master' + - 'releases/v*' jobs: - test-containerized: + test: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - with: - fetch-depth: 0 - name: Validate - run: docker buildx bake validate - - - name: Test - run: docker buildx bake test - - test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - macOS-latest - - windows-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 + uses: docker/bake-action@v1 with: - fetch-depth: 0 - - - name: Install - run: yarn install + targets: validate - name: Test - run: yarn run test + uses: docker/bake-action@v1 + with: + targets: test - name: Upload coverage uses: codecov/codecov-action@v1 - if: success() with: - token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage/clover.xml diff --git a/dev.Dockerfile b/dev.Dockerfile deleted file mode 100644 index 74fa10a0..00000000 --- a/dev.Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -#syntax=docker/dockerfile:1.2 - -FROM node:12 AS deps -WORKDIR /src -COPY package.json yarn.lock ./ -RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \ - yarn install - -FROM scratch AS update-yarn -COPY --from=deps /src/yarn.lock / - -FROM deps AS validate-yarn -COPY .git .git -RUN status=$(git status --porcelain -- yarn.lock); if [ -n "$status" ]; then echo $status; exit 1; fi - -FROM deps AS base -COPY . . - -FROM base AS build -RUN yarn build - -FROM deps AS test -ARG TARGETOS -ARG TARGETARCH -ENV RUNNER_TEMP=/tmp/github_runner -ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache -COPY . . -RUN yarn run test - -FROM base AS run-format -RUN yarn run format - -FROM scratch AS format -COPY --from=run-format /src/src/*.ts /src/ - -FROM base AS validate-format -RUN yarn run format-check - -FROM scratch AS dist -COPY --from=build /src/dist/ /dist/ - -FROM build AS validate-build -RUN status=$(git status --porcelain -- dist); if [ -n "$status" ]; then echo $status; exit 1; fi - -FROM base AS dev -ENTRYPOINT ["bash"] diff --git a/docker-bake.hcl b/docker-bake.hcl index 11871f5c..7054cf77 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,53 +1,67 @@ -group "default" { - targets = ["build"] +variable "NODE_VERSION" { + default = "12" } -group "pre-checkin" { - targets = ["update-yarn", "format", "build"] +target "node-version" { + args = { + NODE_VERSION = NODE_VERSION + } } -group "validate" { - targets = ["validate-format", "validate-build", "validate-yarn"] +group "default" { + targets = ["build"] } -target "dockerfile" { - dockerfile = "dev.Dockerfile" +group "pre-checkin" { + targets = ["vendor-update", "format", "build"] } -target "update-yarn" { - inherits = ["dockerfile"] - target = "update-yarn" - output = ["."] +group "validate" { + targets = ["format-validate", "build-validate", "vendor-validate"] } target "build" { - inherits = ["dockerfile"] - target = "dist" + inherits = ["node-version"] + dockerfile = "./hack/build.Dockerfile" + target = "build-update" output = ["."] } -target "test" { - inherits = ["dockerfile"] - target = "test" +target "build-validate" { + inherits = ["node-version"] + dockerfile = "./hack/build.Dockerfile" + target = "build-validate" } target "format" { - inherits = ["dockerfile"] - target = "format" + inherits = ["node-version"] + dockerfile = "./hack/build.Dockerfile" + target = "format-update" output = ["."] } -target "validate-format" { - inherits = ["dockerfile"] - target = "validate-format" +target "format-validate" { + inherits = ["node-version"] + dockerfile = "./hack/build.Dockerfile" + target = "format-validate" } -target "validate-build" { - inherits = ["dockerfile"] - target = "validate-build" +target "vendor-update" { + inherits = ["node-version"] + dockerfile = "./hack/vendor.Dockerfile" + target = "update" + output = ["."] } -target "validate-yarn" { - inherits = ["dockerfile"] - target = "validate-yarn" +target "vendor-validate" { + inherits = ["node-version"] + dockerfile = "./hack/vendor.Dockerfile" + target = "validate" +} + +target "test" { + inherits = ["node-version"] + dockerfile = "./hack/test.Dockerfile" + target = "test-coverage" + output = ["./coverage"] } diff --git a/hack/build.Dockerfile b/hack/build.Dockerfile new file mode 100644 index 00000000..a0796d71 --- /dev/null +++ b/hack/build.Dockerfile @@ -0,0 +1,42 @@ +# syntax=docker/dockerfile:1.2 +ARG NODE_VERSION + +FROM node:${NODE_VERSION}-alpine AS base +RUN apk add --no-cache cpio findutils git +WORKDIR /src + +FROM base AS deps +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn install + +FROM deps AS build +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn run build && mkdir /out && cp -Rf dist /out/ + +FROM scratch AS build-update +COPY --from=build /out / + +FROM build AS build-validate +RUN --mount=type=bind,target=.,rw \ + git add -A && cp -rf /out/* .; \ + if [ -n "$(git status --porcelain -- dist)" ]; then \ + echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'; \ + git status --porcelain -- dist; \ + exit 1; \ + fi + +FROM deps AS format +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn run format \ + && mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out + +FROM scratch AS format-update +COPY --from=format /out / + +FROM deps AS format-validate +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn run format-check \ diff --git a/hack/test.Dockerfile b/hack/test.Dockerfile new file mode 100644 index 00000000..06c5d678 --- /dev/null +++ b/hack/test.Dockerfile @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1.2 +ARG NODE_VERSION + +FROM node:${NODE_VERSION}-alpine AS base +RUN apk add --no-cache git +WORKDIR /src + +FROM base AS deps +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn install + +FROM deps AS test +ENV RUNNER_TEMP=/tmp/github_runner +ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn run test --coverageDirectory=/tmp/coverage + +FROM scratch AS test-coverage +COPY --from=test /tmp/coverage / diff --git a/hack/vendor.Dockerfile b/hack/vendor.Dockerfile new file mode 100644 index 00000000..dd7906bc --- /dev/null +++ b/hack/vendor.Dockerfile @@ -0,0 +1,23 @@ +# syntax=docker/dockerfile:1.2 +ARG NODE_VERSION + +FROM node:${NODE_VERSION}-alpine AS base +RUN apk add --no-cache git +WORKDIR /src + +FROM base AS vendored +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/src/node_modules \ + yarn install && mkdir /out && cp yarn.lock /out + +FROM scratch AS update +COPY --from=vendored /out / + +FROM vendored AS validate +RUN --mount=type=bind,target=.,rw \ + git add -A && cp -rf /out/* .; \ + if [ -n "$(git status --porcelain -- yarn.lock)" ]; then \ + echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \ + git status --porcelain -- yarn.lock; \ + exit 1; \ + fi diff --git a/jest.config.js b/jest.config.js index 3d7a3786..67eaa307 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,7 +8,7 @@ module.exports = { testEnvironment: 'node', testMatch: ['**/*.test.ts'], testRunner: 'jest-circus/runner', - testTimeout: 10000, + testTimeout: 30000, transform: { '^.+\\.ts$': 'ts-jest' }, diff --git a/.goreleaser-signing.yml b/test/.goreleaser-signing.yml similarity index 100% rename from .goreleaser-signing.yml rename to test/.goreleaser-signing.yml diff --git a/.goreleaser.yml b/test/.goreleaser.yml similarity index 100% rename from .goreleaser.yml rename to test/.goreleaser.yml diff --git a/go.mod b/test/go.mod similarity index 100% rename from go.mod rename to test/go.mod diff --git a/main.go b/test/main.go similarity index 100% rename from main.go rename to test/main.go