You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2021/08/30 15:04:16 UTC

[apisix-dashboard] branch master updated: ci: optimize github actions (#2072)

This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 709d815  ci: optimize github actions (#2072)
709d815 is described below

commit 709d8153a1ffa558ad1748d18ce34d86155f0f82
Author: qsliu2017 <57...@users.noreply.github.com>
AuthorDate: Mon Aug 30 23:04:10 2021 +0800

    ci: optimize github actions (#2072)
---
 .github/workflows/backend-cli-test.yml             | 29 ++++++----
 .github/workflows/backend-e2e-test.yml             | 66 ++++++++++++++++++++--
 .github/workflows/backend-unit-test.yml            | 19 +++++--
 .github/workflows/deploy-with-docker.yml           | 32 ++++++++++-
 .github/workflows/frontend-e2e-test.yml            | 25 ++++----
 .github/workflows/frontend-plugin-e2e-test.yml     | 25 ++++----
 .github/workflows/go-lint.yml                      | 55 ++++++++++++++----
 .github/workflows/make-build.yaml                  | 11 ++++
 .github/workflows/release-test.yml                 | 23 ++++++++
 .../test-frontend-multiple-node-build.yml          |  2 +
 .gitmodules                                        |  3 +
 11 files changed, 232 insertions(+), 58 deletions(-)

diff --git a/.github/workflows/backend-cli-test.yml b/.github/workflows/backend-cli-test.yml
index c44d0bc..55b42bb 100644
--- a/.github/workflows/backend-cli-test.yml
+++ b/.github/workflows/backend-cli-test.yml
@@ -4,23 +4,23 @@ on:
   push:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
   pull_request:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
 
 jobs:
   run-test:
     runs-on: ubuntu-latest
-
+    strategy:
+      matrix:
+        etcd: [3.4.13]
     services:
       etcd:
-        image: bitnami/etcd:3.4.13
+        image: bitnami/etcd:${{ matrix.etcd }}
         ports:
           - 2379:2379
           - 2380:2380
@@ -30,11 +30,20 @@ jobs:
     steps:
       - uses: actions/checkout@v2
 
+      - name: cache etcd
+        id: cache-etcd
+        uses: actions/cache@v2
+        with:
+          path: |
+            ${{ github.workspace }}/api/etcd-v${{ matrix.etcd }}-linux-amd64
+          key: etcd-v${{ matrix.etcd }}-linux-amd64
+
       - name: download etcd
+        if: ${{ steps.cache-etcd.outputs.cache-hit != 'true' }}
         working-directory: ./api
         run: |
-          wget https://github.com/etcd-io/etcd/releases/download/v3.4.14/etcd-v3.4.14-linux-amd64.tar.gz
-          tar zxvf etcd-v3.4.14-linux-amd64.tar.gz
+          wget https://github.com/etcd-io/etcd/releases/download/v${{ matrix.etcd }}/etcd-v${{ matrix.etcd }}-linux-amd64.tar.gz
+          tar zxvf etcd-v${{ matrix.etcd }}-linux-amd64.tar.gz
 
       - name: run test
         working-directory: ./api
diff --git a/.github/workflows/backend-e2e-test.yml b/.github/workflows/backend-e2e-test.yml
index dee0e64..cc42ffb 100644
--- a/.github/workflows/backend-e2e-test.yml
+++ b/.github/workflows/backend-e2e-test.yml
@@ -4,15 +4,13 @@ on:
   push:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
   pull_request:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
 
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_number || github.ref }}
@@ -31,6 +29,25 @@ jobs:
           go-version: "1.13"
           submodules: recursive
 
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
+      - uses: docker/setup-buildx-action@v1
+
+      - uses: actions/cache@v2
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-apisixdashboard-${{ github.sha }}
+          restore-keys: |
+            ${{ runner.os }}-buildx-apisixdashboard-
+            ${{ runner.os }}-buildx-
+
       - name: Modify conf.yaml
         run: |
           sed -i 's/127.0.0.1:2379/172.16.238.10:2379/' ./api/conf/conf.yaml
@@ -44,6 +61,15 @@ jobs:
         run: |
           curl -o Dockerfile-apisix https://raw.githubusercontent.com/apache/apisix-docker/master/alpine/Dockerfile
 
+      - name: build docker images
+        working-directory: ./api/test/docker
+        continue-on-error: true
+        run: |
+          docker buildx bake --load \
+          -f docker-compose.yaml \
+          --set *.cache-from=type=local,src=/tmp/.buildx-cache \
+          --set *.cache-to=type=local,dest=/tmp/.buildx-cache
+
       - name: run docker compose
         working-directory: ./api/test/docker
         run: |
@@ -67,6 +93,15 @@ jobs:
           docker-compose down
           sleep 10
 
+      - name: re-build docker images
+        working-directory: ./api/test/docker
+        continue-on-error: true
+        run: |
+          docker buildx bake --load \
+          -f docker-compose.yaml \
+          --set *.cache-from=type=local,src=/tmp/.buildx-cache \
+          --set *.cache-to=type=local,dest=/tmp/.buildx-cache
+
       - name: re-run docker compose
         working-directory: ./api/test/docker
         run: |
@@ -99,6 +134,16 @@ jobs:
         with:
           go-version: "1.13"
 
+      - uses: docker/setup-buildx-action@v1
+
+      - uses: actions/cache@v2
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-apisixdashboard-${{ github.sha }}
+          restore-keys: |
+            ${{ runner.os }}-buildx-apisixdashboard-
+            ${{ runner.os }}-buildx-
+
       - name: Modify conf.yaml Configure for use by the manage-api cluster
         run: |
           sed -i 's/127.0.0.1:2379/172.16.238.10:2379/' ./api/conf/conf.yaml
@@ -111,6 +156,15 @@ jobs:
         run: |
           curl -o Dockerfile-apisix https://raw.githubusercontent.com/apache/apisix-docker/master/alpine/Dockerfile
 
+      - name: build docker images
+        working-directory: ./api/test/docker
+        continue-on-error: true
+        run: |
+          docker buildx bake --load \
+          -f docker-compose.yaml \
+          --set *.cache-from=type=local,src=/tmp/.buildx-cache \
+          --set *.cache-to=type=local,dest=/tmp/.buildx-cache
+
       - name: run docker compose
         working-directory: ./api/test/docker
         run: |
diff --git a/.github/workflows/backend-unit-test.yml b/.github/workflows/backend-unit-test.yml
index 62207eb..bf58e13 100644
--- a/.github/workflows/backend-unit-test.yml
+++ b/.github/workflows/backend-unit-test.yml
@@ -4,15 +4,13 @@ on:
   push:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
   pull_request:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
 
 jobs:
   run-test:
@@ -35,6 +33,15 @@ jobs:
         with:
           go-version: "1.13"
 
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
       - name: run test
         run: |
           make api-test
diff --git a/.github/workflows/deploy-with-docker.yml b/.github/workflows/deploy-with-docker.yml
index eb6a8b7..bb6a897 100644
--- a/.github/workflows/deploy-with-docker.yml
+++ b/.github/workflows/deploy-with-docker.yml
@@ -25,6 +25,16 @@ jobs:
         with:
           submodules: recursive
 
+      - uses: docker/setup-buildx-action@v1
+
+      - uses: actions/cache@v2
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-apisixdashboard-${{ github.sha }}
+          restore-keys: |
+            ${{ runner.os }}-buildx-apisixdashboard-
+            ${{ runner.os }}-buildx-
+
       - uses: Azure/docker-login@v1
         if: ${{ github.event_name == 'push' }}
         with:
@@ -33,8 +43,17 @@ jobs:
           password: ${{ secrets.REGISTRY_PASSWORD }}
 
       - name: Build Docker Image
-        run: |
-          docker build -t dashboard:ci . --build-arg APISIX_DASHBOARD_VERSION=master
+        uses: docker/build-push-action@v2
+        with:
+          load: true
+          tags: dashboard:ci
+          context: .
+          build-args: |
+            APISIX_DASHBOARD_VERSION=master
+          cache-from: |
+            type=local,src=/tmp/.buildx-cache
+          cache-to: |
+            type=local,dest=/tmp/.buildx-cache
 
       - name: Modify Config
         run: |
@@ -45,6 +64,15 @@ jobs:
           # So we need to configure `listen.host` so that it can be accessed outside docker
           sed -i '/port: 9000/i\    host: 0.0.0.0' ./api/conf/conf.yaml
 
+      - name: build docker images
+        working-directory: ./api/test/docker-deploy
+        continue-on-error: true
+        run: |
+          docker buildx bake --load \
+          -f docker-compose.yaml \
+          --set *.cache-from=type=local,src=/tmp/.buildx-cache \
+          --set *.cache-to=type=local,dest=/tmp/.buildx-cache
+
       - name: Run Docker Compose
         working-directory: ./api/test/docker-deploy
         run: |
diff --git a/.github/workflows/frontend-e2e-test.yml b/.github/workflows/frontend-e2e-test.yml
index 6687308..d9d7d4d 100644
--- a/.github/workflows/frontend-e2e-test.yml
+++ b/.github/workflows/frontend-e2e-test.yml
@@ -45,27 +45,29 @@ jobs:
         uses: actions/setup-node@v2.4.0
         with:
           node-version: 14.x
+          cache: 'yarn'
+          cache-dependency-path: web/yarn.lock
 
       - name: Setup golang environment
         uses: actions/setup-go@v2.1.3
         with:
           go-version: '1.13'
 
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
       - name: Start manager-api
         working-directory: ./api
         run: |
           sed -i 's@# - dubbo-proxy@- dubbo-proxy@' ./conf/conf.yaml
           nohup go run ./main.go &
 
-      - name: Cache node_modules
-        uses: actions/cache@v2.1.6
-        id: yarn-cache
-        with:
-          path: '*/node_modules'
-          key: '${{ runner.os }}-yarn-cache0-${{ hashFiles(''**/yarn.lock'') }}'
-          restore-keys: |
-            ${{ runner.os }}-yarn-cache0
-
       - name: Cache Cypress binary
         uses: actions/cache@v2.1.6
         id: cypress-binary-cache
@@ -76,7 +78,6 @@ jobs:
             cypress-${{ runner.os }}-cypress-cache0
 
       - name: Install dependencies
-        if: steps.yarn-cache.outputs.cache-hit != 'true'
         run: yarn
 
       - name: Start frontend then test
@@ -97,6 +98,6 @@ jobs:
         with:
           name: cypress-report
           path: |
-           web/cypress/videos
-           web/cypress/screenshots
+            web/cypress/videos
+            web/cypress/screenshots
           retention-days: 5
diff --git a/.github/workflows/frontend-plugin-e2e-test.yml b/.github/workflows/frontend-plugin-e2e-test.yml
index 51c918e..b0486c4 100644
--- a/.github/workflows/frontend-plugin-e2e-test.yml
+++ b/.github/workflows/frontend-plugin-e2e-test.yml
@@ -43,12 +43,23 @@ jobs:
         uses: actions/setup-node@v2.4.0
         with:
           node-version: 14.x
+          cache: 'yarn'
+          cache-dependency-path: web/yarn.lock
 
       - name: Setup golang environment
         uses: actions/setup-go@v2.1.3
         with:
           go-version: '1.13'
 
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
       - name: Download dag-to-lua
         working-directory: ./
         run: make dag-lib
@@ -59,15 +70,6 @@ jobs:
           sed -i 's@# - dubbo-proxy@- dubbo-proxy@' ./conf/conf.yaml
           nohup go run ./main.go &
 
-      - name: Cache node_modules
-        uses: actions/cache@v2.1.6
-        id: yarn-cache
-        with:
-          path: '*/node_modules'
-          key: '${{ runner.os }}-yarn-cache0-${{ hashFiles(''**/yarn.lock'') }}'
-          restore-keys: |
-            ${{ runner.os }}-yarn-cache0
-
       - name: Cache Cypress binary
         uses: actions/cache@v2.1.6
         id: cypress-binary-cache
@@ -78,7 +80,6 @@ jobs:
             cypress-${{ runner.os }}-cypress-cache0
 
       - name: Install dependencies
-        if: steps.yarn-cache.outputs.cache-hit != 'true'
         run: yarn
 
       - name: Start frontend then test
@@ -90,6 +91,6 @@ jobs:
         with:
           name: cypress-report
           path: |
-           web/cypress/videos
-           web/cypress/screenshots
+            web/cypress/videos
+            web/cypress/screenshots
           retention-days: 5
diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml
index 00f2365..d646a92 100644
--- a/.github/workflows/go-lint.yml
+++ b/.github/workflows/go-lint.yml
@@ -3,37 +3,72 @@ on:
   push:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
   pull_request:
     branches:
       - master
-    paths-ignore:
-      - 'docs/**'
-      - 'web/**'
+    paths:
+      - 'api/**'
 
 jobs:
+  go-filter:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodule: true
+
+      - uses: ./.github/actions/paths-filter
+        id: changes
+        with:
+          filters: |
+            go:
+              - '**.go'
+          working-directory: 'api'
+          list-files: shell
+    outputs:
+      matches: ${{ steps.changes.outputs.go }}
+      files: ${{ steps.changes.outputs.go_files }}
+
   golangci:
     runs-on: ubuntu-latest
+    needs: go-filter
+    if: needs.go-filter.outputs.matches == 'true'
     steps:
       - uses: actions/checkout@v2
 
-      - name: run lint
-        run: make go-lint
+      - name: golangci-lint
+        uses: golangci/golangci-lint-action@v2
+        with:
+          version: latest
+          working-directory: api
+          args: --tests=false
+          only-new-issues: true
 
   gofmt:
     runs-on: ubuntu-latest
+    needs: go-filter
+    if: needs.go-filter.outputs.matches == 'true'
     steps:
       - uses: actions/checkout@v2
       - name: setup go
         uses: actions/setup-go@v1
         with:
           go-version: '1.13'
+
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
       - name: check gofmt
-        working-directory: ./api
         run: |
-          diffs=`gofmt -l .`
+          diffs=`gofmt -l ${{ needs.go-filter.outputs.files }}`
           if [[ -n $diffs ]]; then
               echo "Files are not formatted by gofmt:"
               echo $diffs
diff --git a/.github/workflows/make-build.yaml b/.github/workflows/make-build.yaml
index 3ca3a56..21f2e18 100644
--- a/.github/workflows/make-build.yaml
+++ b/.github/workflows/make-build.yaml
@@ -42,12 +42,23 @@ jobs:
         uses: actions/setup-node@v2.4.0
         with:
           node-version: 14.x
+          cache: 'yarn'
+          cache-dependency-path: web/yarn.lock
 
       - name: Setup golang environment
         uses: actions/setup-go@v2.1.3
         with:
           go-version: '1.13'
 
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
       - name: make build
         run: make build
 
diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml
index f94edc6..bf4ee0c 100644
--- a/.github/workflows/release-test.yml
+++ b/.github/workflows/release-test.yml
@@ -5,12 +5,26 @@ on:
     branches:
       - master
     paths-ignore:
+      - '.github/**'
+      - '.git/**'
+      - '.gitattributes'
+      - '.vscode/**'
+      - '.gitignore'
       - 'docs/**'
+      - 'api/internal/core/store/validate_mock.go'
+      - 'api/internal/core/storage/storage_mock.go'
   pull_request:
     branches:
       - master
     paths-ignore:
+      - '.github/**'
+      - '.git/**'
+      - '.gitattributes'
+      - '.vscode/**'
+      - '.gitignore'
       - 'docs/**'
+      - 'api/internal/core/store/validate_mock.go'
+      - 'api/internal/core/storage/storage_mock.go'
 
 jobs:
   run-test:
@@ -33,6 +47,15 @@ jobs:
         with:
           go-version: '1.13'
 
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+
       - name: release and build
         run: |
           VERSION=$(cat ./api/VERSION)
diff --git a/.github/workflows/test-frontend-multiple-node-build.yml b/.github/workflows/test-frontend-multiple-node-build.yml
index d9775cf..e143c63 100644
--- a/.github/workflows/test-frontend-multiple-node-build.yml
+++ b/.github/workflows/test-frontend-multiple-node-build.yml
@@ -37,6 +37,8 @@ jobs:
         uses: actions/setup-node@v2.4.0
         with:
           node-version: ${{ matrix.node-version }}
+          cache: 'yarn'
+          cache-dependency-path: web/yarn.lock
 
       # Install dependencies
       - name: Install dependencies
diff --git a/.gitmodules b/.gitmodules
index 1ee15dc..c8b78ea 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
 [submodule ".github/actions/gitleaks-action"]
 	path = .github/actions/gitleaks-action
 	url = https://github.com/zricethezav/gitleaks-action
+[submodule ".github/actions/paths-filter"]
+	path = .github/actions/paths-filter
+	url = https://github.com/dorny/paths-filter.git