From 805449f25e59629d5ed02a5055ec82dcfa6f70e5 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sat, 19 Dec 2020 03:53:36 +0100 Subject: [PATCH] Update dev workflow (#32) Co-authored-by: CrazyMax --- .dockerignore | 6 +++++- .github/CONTRIBUTING.md | 13 +++++++------ .github/workflows/test.yml | 21 +++------------------ .github/workflows/validate.yml | 25 +++++++++++++++++++++++++ Dockerfile => Dockerfile.dev | 21 +++++++++++++++------ docker-bake.hcl | 18 +++++++++++++++--- 6 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/validate.yml rename Dockerfile => Dockerfile.dev (58%) diff --git a/.dockerignore b/.dockerignore index 3c3629e..f55929c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,5 @@ -node_modules +/.dev +/coverage +/dist +/lib +/node_modules diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1a48f38..19bd949 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -8,12 +8,13 @@ Contributions to this project are [released](https://help.github.com/articles/gi 1. [Fork](https://github.com/crazy-max/ghaction-docker-meta/fork) and clone the repository 2. Configure and install the dependencies: `yarn install` -3. Make sure the tests pass on your machine: `yarn run test` -4. Create a new branch: `git checkout -b my-branch-name` -5. Make your change, add tests, and make sure the tests still pass -6. Run pre-checkin: `yarn run pre-checkin` -7. Push to your fork and [submit a pull request](https://github.com/crazy-max/ghaction-docker-meta/compare) -8. Pat your self on the back and wait for your pull request to be reviewed and merged. +3. Create a new branch: `git checkout -b my-branch-name` +4. Make your changes +5. Make sure the tests pass: `docker buildx bake test` +6. Format code and build javascript artifacts: `docker buildx bake pre-checkin` +7. Validate all code has correctly formatted and built: `docker buildx bake validate` +8. Push to your fork and [submit a pull request](https://github.com/crazy-max/ghaction-docker-meta/compare) +9. Pat your self on the back and wait for your pull request to be reviewed and merged. ## Container based developer flow diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2d31bd..6c8bd39 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,39 +8,24 @@ on: paths-ignore: - '**.md' pull_request: + branches: + - 'master' paths-ignore: - '**.md' jobs: - test-containerized: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Validate - run: docker buildx bake validate - - - name: Test - run: docker buildx bake test - test: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - - - name: Install - run: yarn install - name: Test - run: yarn run test + run: docker buildx bake test - name: Upload coverage uses: codecov/codecov-action@v1 - if: success() with: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage/clover.xml diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..0134e68 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,25 @@ +name: validate + +on: + push: + branches: + - 'master' + - 'releases/v*' + paths-ignore: + - '**.md' + pull_request: + branches: + - 'master' + paths-ignore: + - '**.md' + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Validate + run: docker buildx bake validate diff --git a/Dockerfile b/Dockerfile.dev similarity index 58% rename from Dockerfile rename to Dockerfile.dev index 6998ab8..931c7a9 100644 --- a/Dockerfile +++ b/Dockerfile.dev @@ -1,9 +1,9 @@ -#syntax=docker/dockerfile:1.1-experimental +#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 \ +RUN --mount=type=cache,target=/src/node_modules \ yarn install FROM scratch AS update-yarn @@ -17,20 +17,29 @@ FROM deps AS base COPY . . FROM base AS build -RUN yarn build +RUN --mount=type=cache,target=/src/node_modules \ + yarn build FROM deps AS test +ENV RUNNER_TEMP=/tmp/github_runner +ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache COPY . . -RUN yarn run test +RUN --mount=type=cache,target=/src/node_modules \ + yarn run test + +FROM scratch AS test-coverage +COPY --from=test /src/coverage /coverage/ FROM base AS run-format -RUN yarn run format +RUN --mount=type=cache,target=/src/node_modules \ + 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 +RUN --mount=type=cache,target=/src/node_modules \ + yarn run format-check FROM scratch AS dist COPY --from=build /src/dist/ /dist/ diff --git a/docker-bake.hcl b/docker-bake.hcl index e01c414..cf19424 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -7,36 +7,48 @@ group "pre-checkin" { } group "validate" { - targets = ["validate-format", "validate-build", "validate-yarn"] + targets = ["validate-format", "validate-build", "validate-yarn"] +} + +target "dockerfile" { + dockerfile = "Dockerfile.dev" } target "update-yarn" { + inherits = ["dockerfile"] target = "update-yarn" output = ["."] } target "build" { + inherits = ["dockerfile"] target = "dist" output = ["."] } target "test" { - target = "test" + inherits = ["dockerfile"] + target = "test-coverage" + output = ["."] } target "format" { + inherits = ["dockerfile"] target = "format" output = ["."] } target "validate-format" { + inherits = ["dockerfile"] target = "validate-format" } target "validate-build" { + inherits = ["dockerfile"] target = "validate-build" } target "validate-yarn" { - target = "validate-yarn" + inherits = ["dockerfile"] + target = "validate-yarn" }