From 717aeffae8b42e01b11ed936a87fcb6ff0f8c5be Mon Sep 17 00:00:00 2001 From: Nick Pappas Date: Sun, 17 Jan 2021 10:41:47 -0600 Subject: [PATCH] feat: leverage cache to prevent unnecessary pushing and building (#14) * feat: leverage cache to prevent unnecessary pushing and building * fix: combine test build and test suite to leverage cache * fix: revert inadvertently changed parts * fix: review-requested changes * fix: update test tags to use static ci tag --- .github/workflows/default_on_push.yml | 47 ++++++----------------- .github/workflows/test_merge_requests.yml | 27 ++++--------- 2 files changed, 19 insertions(+), 55 deletions(-) diff --git a/.github/workflows/default_on_push.yml b/.github/workflows/default_on_push.yml index cd7fc031..f710a367 100644 --- a/.github/workflows/default_on_push.yml +++ b/.github/workflows/default_on_push.yml @@ -5,23 +5,13 @@ on: branches: [ "master", "stable" ] jobs: - build: + build-and-test-image: runs-on: ubuntu-20.04 - outputs: - imagetag: ${{ steps.prep.outputs.imagetag }} steps: - name: Checkout uses: actions/checkout@v2 with: submodules: recursive - - name: Prepare - id: prep - run: | - DOCKER_IMAGE=docker.io/mailserver/testing - TAGS="${DOCKER_IMAGE}:${GITHUB_SHA::8},${DOCKER_IMAGE}:latest" - echo ::set-output name=tags::${TAGS} - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 id: buildx @@ -32,11 +22,6 @@ jobs: key: ${{ runner.os }}-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-buildx- - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - name: Build image locally uses: docker/build-push-action@v2 with: @@ -46,35 +31,26 @@ jobs: build-args: | VCS_REF=${{ github.sha }} VCS_VER=${{ github.ref }} - platforms: linux/amd64,linux/arm/v7,linux/arm64 - pull: true - push: true - tags: ${{ steps.prep.outputs.tags }} + platforms: linux/amd64 + load: true + tags: mailserver-testing:ci cache-to: type=local,dest=/tmp/.buildx-cache - - test: - needs: build - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive - - name: run test suite - run: | - NAME=docker.io/mailserver/testing:${GITHUB_SHA::8} bash -c 'make generate-accounts tests' + - name: Run test suite + run: > + NAME=mailserver-testing:ci + bash -c 'make generate-accounts tests' env: CI: true - publish: - needs: test + build-multiarch-and-publish: + needs: build-and-test-image runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v2 with: submodules: recursive - - name: Prepare + - name: Prepare tags id: prep run: | DOCKER_IMAGE=docker.io/mailserver/docker-mailserver @@ -111,7 +87,6 @@ jobs: VCS_REF=${{ github.sha }} VCS_VER=${{ github.ref }} platforms: linux/amd64,linux/arm/v7,linux/arm64 - pull: true push: true tags: ${{ steps.prep.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache diff --git a/.github/workflows/test_merge_requests.yml b/.github/workflows/test_merge_requests.yml index e9ae9dbd..87c276f9 100644 --- a/.github/workflows/test_merge_requests.yml +++ b/.github/workflows/test_merge_requests.yml @@ -6,35 +6,24 @@ jobs: build-and-test: runs-on: ubuntu-20.04 steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v2 with: submodules: recursive - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - id: buildx - - - name: Build image locally + - name: Build image locally uses: docker/build-push-action@v2 with: - builder: ${{ steps.buildx.outputs.name }} + context: . + file: ./Dockerfile build-args: | VCS_REF=${{ github.sha }} VCS_VER=${{ github.ref }} - context: . - file: ./Dockerfile - load: true platforms: linux/amd64 - tags: docker.io/mailserver/testing:ci - - - name: Run all tests + load: true + tags: mailserver-testing:ci + - name: Run test suite run: > - NAME=docker.io/mailserver/testing:ci + NAME=mailserver-testing:ci bash -c 'make generate-accounts tests' env: CI: true