|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + backend: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v2 |
| 17 | + |
| 18 | + - name: Prepare |
| 19 | + id: prep |
| 20 | + run: | |
| 21 | + TAG=$(echo $GITHUB_SHA | head -c7) |
| 22 | + IMAGE="ukpsquare/square-backend" |
| 23 | + echo ::set-output name=image::${IMAGE} |
| 24 | + echo ::set-output name=tag::${TAG} |
| 25 | + - name: Set up Docker Buildx |
| 26 | + id: buildx |
| 27 | + uses: docker/setup-buildx-action@v1 |
| 28 | + with: |
| 29 | + install: true |
| 30 | + |
| 31 | + - name: Cache Docker layers |
| 32 | + uses: actions/cache@v2 |
| 33 | + with: |
| 34 | + path: /tmp/.buildx-cache |
| 35 | + key: ${{ runner.os }}-buildx-backend-${{ github.sha }} |
| 36 | + restore-keys: | |
| 37 | + ${{ runner.os }}-buildx-backend- |
| 38 | + ${{ runner.os }}-buildx- |
| 39 | + |
| 40 | + - name: Build test image |
| 41 | + uses: docker/build-push-action@v2 |
| 42 | + with: |
| 43 | + builder: ${{ steps.buildx.outputs.name }} |
| 44 | + context: ./square-backend |
| 45 | + target: test |
| 46 | + load: true |
| 47 | + tags: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}-test |
| 48 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 49 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new |
| 50 | + |
| 51 | + |
| 52 | + # Temp fix |
| 53 | + # https://github.com/docker/build-push-action/issues/252 |
| 54 | + # https://github.com/moby/buildkit/issues/1896 |
| 55 | + - name: Move cache |
| 56 | + run: | |
| 57 | + rm -rf /tmp/.buildx-cache |
| 58 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 59 | + |
| 60 | + - name: Retrieve Test Reports |
| 61 | + id: extract |
| 62 | + uses: shrink/actions-docker-extract@v1 |
| 63 | + with: |
| 64 | + image: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}-test |
| 65 | + path: /app/test-reports |
| 66 | + |
| 67 | + - uses: actions/upload-artifact@v2 |
| 68 | + with: |
| 69 | + name: backend-test-reports |
| 70 | + path: ${{ steps.extract.outputs.destination }}/test-reports |
| 71 | + |
| 72 | + - name: Publish Test Report |
| 73 | + uses: mikepenz/action-junit-report@v2 |
| 74 | + with: |
| 75 | + report_paths: ${{ steps.extract.outputs.destination }}/test-reports/junit.xml |
| 76 | + check_name: Backend Test Report |
| 77 | + fail_on_failure: true |
| 78 | + |
| 79 | + - name: Login to Docker Hub |
| 80 | + uses: docker/login-action@v1 |
| 81 | + with: |
| 82 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 83 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 84 | + |
| 85 | + - name: Build deployable image |
| 86 | + uses: docker/build-push-action@v2 |
| 87 | + with: |
| 88 | + builder: ${{ steps.buildx.outputs.name }} |
| 89 | + context: ./square-backend |
| 90 | + target: build |
| 91 | + push: ${{github.ref == 'refs/heads/master'}} |
| 92 | + tags: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}, ${{ steps.prep.outputs.image }}:latest |
| 93 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 94 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new |
| 95 | + |
| 96 | + # Temp fix |
| 97 | + # https://github.com/docker/build-push-action/issues/252 |
| 98 | + # https://github.com/moby/buildkit/issues/1896 |
| 99 | + - name: Move cache |
| 100 | + run: | |
| 101 | + rm -rf /tmp/.buildx-cache |
| 102 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 103 | + frontend: |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v2 |
| 107 | + |
| 108 | + - name: Prepare |
| 109 | + id: prep |
| 110 | + run: | |
| 111 | + TAG=$(echo $GITHUB_SHA | head -c7) |
| 112 | + IMAGE="ukpsquare/square-frontend" |
| 113 | + echo ::set-output name=image::${IMAGE} |
| 114 | + echo ::set-output name=tag::${TAG} |
| 115 | + - name: Set up Docker Buildx |
| 116 | + id: buildx |
| 117 | + uses: docker/setup-buildx-action@v1 |
| 118 | + with: |
| 119 | + install: true |
| 120 | + |
| 121 | + - name: Cache Docker layers |
| 122 | + uses: actions/cache@v2 |
| 123 | + with: |
| 124 | + path: /tmp/.buildx-cache |
| 125 | + key: ${{ runner.os }}-buildx-frontend-${{ github.sha }} |
| 126 | + restore-keys: | |
| 127 | + ${{ runner.os }}-buildx-frontend- |
| 128 | + ${{ runner.os }}-buildx- |
| 129 | +
|
| 130 | + - name: Login to Docker Hub |
| 131 | + uses: docker/login-action@v1 |
| 132 | + with: |
| 133 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 134 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 135 | + |
| 136 | + - name: Build deployable image |
| 137 | + uses: docker/build-push-action@v2 |
| 138 | + with: |
| 139 | + builder: ${{ steps.buildx.outputs.name }} |
| 140 | + context: ./square-frontend |
| 141 | + target: build |
| 142 | + push: ${{github.ref == 'refs/heads/master'}} |
| 143 | + tags: ${{ steps.prep.outputs.image }}:${{ steps.prep.outputs.tag }}, ${{ steps.prep.outputs.image }}:latest |
| 144 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 145 | + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new |
| 146 | + |
| 147 | + # Temp fix |
| 148 | + # https://github.com/docker/build-push-action/issues/252 |
| 149 | + # https://github.com/moby/buildkit/issues/1896 |
| 150 | + - name: Move cache |
| 151 | + run: | |
| 152 | + rm -rf /tmp/.buildx-cache |
| 153 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments