diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f521c13..b029aac 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,9 +29,10 @@ jobs: needs: create-deployment steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: '16' + cache: npm - name: Install run: npm ci @@ -39,45 +40,20 @@ jobs: - name: Build run: npm run build --if-present - # linting: - # name: Super Lint - # runs-on: ubuntu-latest - # needs: build - - # steps: - # - name: Checkout Code - # uses: actions/checkout@v2 - # with: - # # Full git history is needed to get a proper list of changed files within `super-linter` - # fetch-depth: 0 - - # ################################ - # # Run Linter against code base # - # ################################ - # - name: Lint Code Base - # uses: github/super-linter@v4 - # env: - # DEFAULT_BRANCH: master - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # VALIDATE_ALL_CODEBASE: false - # VALIDATE_GITHUB_ACTIONS: false - unit-test: name: Unit Tests runs-on: ubuntu-latest needs: build steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: '16' + cache: npm - name: Install run: npm ci - - name: Build - run: npm run build --if-present - - name: Test run: npm test @@ -93,16 +69,14 @@ jobs: needs: build steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: '16' + cache: npm - name: Install run: npm ci - - name: Build - run: npm run build --if-present - - name: Test run: npm test @@ -114,9 +88,64 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Build Image + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + # list of Docker images to use as base name for tags + images: | + ${{ secrets.DOCKERHUB_USERNAME }}/typescript-node-boilerplate + # tags: | + # ${{ github.sha }} + tags: | + ${{ github.sha }} + type=schedule + type=ref,event=branch + type=ref,event=pr + type=sha + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + - # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + name: Move cache run: | - docker build -t typescript-node-boilerplate:${{ github.sha }} . + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache update-deployment: name: Update Deployment