Adopt new paths filter and refactor CI (#181)

diff --git a/.asf.yaml b/.asf.yaml
index 1c4989d..b8c92c6 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -28,3 +28,12 @@
     squash: true
     merge: false
     rebase: false
+  protected_branches:
+    master:
+      required_status_checks:
+        strict: true
+        contexts:
+          - Required
+      required_pull_request_reviews:
+        dismiss_stale_reviews: true
+        required_approving_review_count: 1
\ No newline at end of file
diff --git a/.github/file-filters.txt b/.github/file-filters.txt
new file mode 100644
index 0000000..7714dff
--- /dev/null
+++ b/.github/file-filters.txt
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+**/*.go
+go.mod
+.golangci.yml
+.github/**/*
\ No newline at end of file
diff --git a/.github/file-filters.yml b/.github/file-filters.yml
deleted file mode 100644
index 601bc07..0000000
--- a/.github/file-filters.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-src:
-  - '**/*.go'
-  - 'go.mod'
-  - '.golangci.yml'
-  - '.github/*.yml'
-  - '.github/*.yaml'
diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml
new file mode 100644
index 0000000..9b0f2d0
--- /dev/null
+++ b/.github/workflows/CI.yaml
@@ -0,0 +1,199 @@
+#

+# Licensed to the Apache Software Foundation (ASF) under one

+# or more contributor license agreements.  See the NOTICE file

+# distributed with this work for additional information

+# regarding copyright ownership.  The ASF licenses this file

+# to you under the Apache License, Version 2.0 (the

+# "License"); you may not use this file except in compliance

+# with the License.  You may obtain a copy of the License at

+#

+#   http://www.apache.org/licenses/LICENSE-2.0

+#

+# Unless required by applicable law or agreed to in writing,

+# software distributed under the License is distributed on an

+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+# KIND, either express or implied.  See the License for the

+# specific language governing permissions and limitations

+# under the License.

+#

+name: CI

+

+on:

+  pull_request:

+  push:

+    branches:

+      - master

+  schedule:

+    - cron: "0 18 * * *" # TimeZone: UTC 0

+

+concurrency:

+  group: skywalking-cli-${{ github.event.pull_request.number || github.ref }}

+  cancel-in-progress: true

+

+jobs:

+  check-license:

+    name: License header

+    if: (github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || (github.event_name != 'schedule')

+    runs-on: ubuntu-latest

+    steps:

+      - uses: actions/checkout@v3

+

+      - name: Check License Header

+        uses: apache/skywalking-eyes@5dfa68f93380a5e57259faaf95088b7f133b5778

+        env:

+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+

+      - name: Setup Go

+        uses: actions/setup-go@v4

+        with:

+          go-version: "1.18"

+

+      - name: Check Dependencies License

+        run: make dependency-license

+

+

+  changes:

+    runs-on: ubuntu-latest

+    if: github.event_name != 'schedule'

+    timeout-minutes: 10

+    outputs:

+      cli: ${{ steps.filter-cli.outputs.any_modified }}

+    steps:

+      - uses: actions/checkout@v3 # required for push event

+        with:

+          fetch-depth: 0

+      - name: Check for CLI source changes

+        id: filter-cli

+        # The GHA version is pinned by infra

+        uses: tj-actions/changed-files@v35.9.2

+        with:

+          files_from_source_file: .github/file-filters.txt

+      - name: List all modified files

+        if: steps.filter-cli.outputs.any_modified == 'true'

+        run: |

+          echo "Files that have changed or modified:"

+          echo "Filter-cli: ${{ steps.filter-cli.outputs.all_changed_and_modified_files }}"

+  

+

+  golang-lint:

+    name: Golang Lint

+    runs-on: ubuntu-latest

+    needs: [changes]

+    if: |

+      ( always() && ! cancelled() ) &&

+      ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true')

+    steps:

+      - uses: actions/checkout@v3

+      - name: Set up Go

+        uses: actions/setup-go@v4

+        with:

+          go-version: 1.18

+

+      - name: golangci-lint

+        uses: golangci/golangci-lint-action@v3

+        with:

+          version: v1.50.0

+          args: --timeout 5m

+

+

+  build:

+    name: Build

+    needs: [changes]

+    runs-on: ubuntu-latest

+    if: |

+      ( always() && ! cancelled() ) &&

+      ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true')

+    steps:

+      - uses: actions/checkout@v3

+      - name: Set up Go

+        uses: actions/setup-go@v4

+        with:

+          go-version: 1.18

+

+      - name: Check code generation

+        run: make check-codegen

+

+      - uses: actions/upload-artifact@v3

+        if: failure()

+        with:

+          name: check-diff

+          path: /tmp/swctl/check.diff

+

+      - name: Build

+        run: make build -j3

+

+      - name: Build Docker images

+        run: make docker

+

+

+  command-tests:

+    name: Command Tests

+    runs-on: ubuntu-latest

+    needs: [changes]

+    if: |

+      ( always() && ! cancelled() ) &&

+      ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true')

+    strategy:

+      matrix:

+        oap:

+          - 6fa89c79917cb10dbf48591c46abee3b513a2bab # March 28th

+    steps:

+      - uses: actions/checkout@v3

+      - name: Set up Go

+        uses: actions/setup-go@v4

+        with:

+          go-version: 1.18

+

+      - name: Test commands

+        uses: apache/skywalking-infra-e2e@2b3aa53dbba73909730b211d5b8065abc74b56ad

+        env:

+          OAP_TAG: ${{ matrix.oap }}

+        with:

+          e2e-file: test/cases/basic/test.yaml

+

+

+  unit-tests:

+    name: Unit Tests

+    runs-on: ubuntu-latest

+    needs: [changes]

+    if: |

+      ( always() && ! cancelled() ) &&

+      ((github.event_name == 'schedule' && github.repository == 'apache/skywalking-cli') || needs.changes.outputs.cli == 'true')

+    steps:

+      - uses: actions/checkout@v3

+      - name: setup go

+        uses: actions/setup-go@v4

+        with:

+          go-version: '1.18'

+

+      - name: run unit tests and report coverage

+        working-directory: ./

+        run: |

+          make coverage

+

+  required:

+    if: always()

+    name: Required

+    needs:

+      - check-license

+      - golang-lint

+      - build

+      - command-tests

+      - unit-tests

+    runs-on: ubuntu-latest

+    timeout-minutes: 10

+    steps:

+      - name: Merge Requirement

+        run: |

+          execute=${{ needs.changes.outputs.cli }}

+          checkLicense=${{ needs.check-license.result }}

+          [[ ${checkLicense} == 'success' ]] || exit -1;

+          golangLint=${{ needs.golang-lint.result }};

+          build=${{ needs.build.result }};

+          commandTests=${{ needs.command-tests.result }};

+          unitTests=${{ needs.unit-tests.result }};

+          [[ ${golangLint} == 'success' ]] || [[ ${execute} != 'true' && ${golangLint} == 'skipped' ]] || exit -2;

+          [[ ${build} == 'success' ]] || [[ ${execute} != 'true' && ${build} == 'skipped' ]] || exit -3;

+          [[ ${commandTests} == 'success' ]] || [[ ${execute} != 'true' && ${commandTests} == 'skipped' ]] || exit -4;

+          [[ ${unitTests} == 'success' ]] || [[ ${execute} != 'true' && ${unitTests} == 'skipped' ]] || exit -5;

+          exit 0;
\ No newline at end of file
diff --git a/.github/workflows/command-tests.yml b/.github/workflows/command-tests.yml
deleted file mode 100644
index 26c9c26..0000000
--- a/.github/workflows/command-tests.yml
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-name: command-test
-
-on:
-  pull_request:
-  push:
-    branches:
-      - master
-
-jobs:
-  command-test:
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        oap:
-          - 6fa89c79917cb10dbf48591c46abee3b513a2bab
-    steps:
-      - uses: actions/checkout@v2
-      - name: Check for go file changes
-        uses: getsentry/paths-filter@v2
-        id: changes
-        with:
-          token: ${{ github.token }}
-          filters: .github/file-filters.yml
-
-      - name: Set up Go
-        uses: actions/setup-go@v2
-        with:
-          go-version: 1.18
-
-      - name: Test commands
-        if: steps.changes.outputs.src == 'true'
-        uses: apache/skywalking-infra-e2e@964ede199fe199e166920169dc5f8c9b214cfac5
-        env:
-          OAP_TAG: ${{ matrix.oap }}
-        with:
-          e2e-file: test/cases/basic/test.yaml
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
deleted file mode 100644
index 1b832cb..0000000
--- a/.github/workflows/go.yml
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-name: Build
-
-on:
-  pull_request:
-  push:
-    branches:
-      - master
-
-jobs:
-  build:
-    name: Build
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - name: Check for go file changes
-        uses: getsentry/paths-filter@v2
-        id: changes
-        with:
-          token: ${{ github.token }}
-          filters: .github/file-filters.yml
-
-      - name: Set up Go
-        uses: actions/setup-go@v2
-        with:
-          go-version: 1.18
-
-      - name: Check code generation
-        run: make check-codegen
-
-      - uses: actions/upload-artifact@v2
-        if: failure()
-        with:
-          name: check-diff
-          path: /tmp/swctl/check.diff
-
-      - name: Build
-        run: make build -j3
-
-      - name: Build Docker images
-        run: make docker
diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml
deleted file mode 100644
index ab1450a..0000000
--- a/.github/workflows/golangci-lint.yml
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-name: golangci-lint
-
-on:
-  pull_request:
-  push:
-    branches:
-      - master
-
-jobs:
-  golangci:
-    name: lint
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - name: Check for go file changes
-        uses: getsentry/paths-filter@v2
-        id: changes
-        with:
-          token: ${{ secrets.GITHUB_TOKEN }}
-          filters: .github/file-filters.yml
-
-      - name: Set up Go
-        uses: actions/setup-go@v2
-        with:
-          go-version: 1.18
-
-      - name: golangci-lint
-        if: steps.changes.outputs.src == 'true'
-        uses: golangci/golangci-lint-action@v3
-        with:
-          version: v1.50.0
-          args: --timeout 5m
diff --git a/.github/workflows/license-checker.yml b/.github/workflows/license-checker.yml
deleted file mode 100644
index da4d393..0000000
--- a/.github/workflows/license-checker.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-name: license-checker
-
-on:
-  pull_request:
-  push:
-    branches:
-      - master
-
-jobs:
-  check-license:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - name: Check License Header
-        uses: apache/skywalking-eyes@d38fe0561d1140b010bddccb5fbfa3db7c12caf1
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-      - name: Setup Go
-        uses: actions/setup-go@v3
-        with:
-          go-version: "1.18"
-      - name: Check Dependencies License
-        run: make dependency-license
diff --git a/.github/workflows/publish-docker.yaml b/.github/workflows/publish-docker.yaml
index 7225ce4..1ebca1c 100644
--- a/.github/workflows/publish-docker.yaml
+++ b/.github/workflows/publish-docker.yaml
@@ -1,54 +1,54 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-name: publish-docker
-
-on:
-  push:
-    branches:
-      - master
-
-env:
-  SKIP_TEST: true
-  HUB: ghcr.io/apache/skywalking-cli
-
-jobs:
-  build:
-    if: github.repository == 'apache/skywalking-cli'
-    runs-on: ubuntu-latest
-    permissions:
-      contents: read
-      packages: write
-    timeout-minutes: 30
-    env:
-      VERSION: ${{ github.sha }}
-      APP_NAME: skywalking-cli
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-      - name: Set up Go
-        uses: actions/setup-go@v2
-        with:
-          go-version: 1.18
-      - name: Log in to the Container registry
-        uses: docker/login-action@v1.10.0
-        with:
-          registry: ${{ env.HUB }}
-          username: ${{ github.actor }}
-          password: ${{ secrets.GITHUB_TOKEN }}
-      - name: Build and push docker images
-        run: make docker.push || make docker.push
+# Licensed to the Apache Software Foundation (ASF) under one

+# or more contributor license agreements.  See the NOTICE file

+# distributed with this work for additional information

+# regarding copyright ownership.  The ASF licenses this file

+# to you under the Apache License, Version 2.0 (the

+# "License"); you may not use this file except in compliance

+# with the License.  You may obtain a copy of the License at

+#

+#     http://www.apache.org/licenses/LICENSE-2.0

+#

+# Unless required by applicable law or agreed to in writing, software

+# distributed under the License is distributed on an "AS IS" BASIS,

+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+# See the License for the specific language governing permissions and

+# limitations under the License.

+

+name: publish-docker

+

+on:

+  push:

+    branches:

+      - master

+

+env:

+  SKIP_TEST: true

+  HUB: ghcr.io/apache/skywalking-cli

+

+jobs:

+  build:

+    if: github.repository == 'apache/skywalking-cli'

+    runs-on: ubuntu-latest

+    permissions:

+      contents: read

+      packages: write

+    timeout-minutes: 30

+    env:

+      VERSION: ${{ github.sha }}

+      APP_NAME: skywalking-cli

+    steps:

+      - uses: actions/checkout@v3

+        with:

+          submodules: true

+      - name: Set up Go

+        uses: actions/setup-go@v4

+        with:

+          go-version: 1.18

+      - name: Log in to the Container registry

+        uses: docker/login-action@v1.10.0

+        with:

+          registry: ${{ env.HUB }}

+          username: ${{ github.actor }}

+          password: ${{ secrets.GITHUB_TOKEN }}

+      - name: Build and push docker images

+        run: make docker.push || make docker.push
\ No newline at end of file
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
deleted file mode 100644
index d8fd0ac..0000000
--- a/.github/workflows/unit-tests.yml
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-name: unit-test
-
-on:
-  pull_request:
-  push:
-    branches:
-      - master
-
-jobs:
-  unit-tests:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - name: Check for go file changes
-        uses: getsentry/paths-filter@v2
-        id: changes
-        with:
-          token: ${{ github.token }}
-          filters: .github/file-filters.yml
-
-      - name: setup go
-        if: steps.changes.outputs.src == 'true'
-        uses: actions/setup-go@v2
-        with:
-          go-version: '1.18'
-
-      - name: run unit tests and report coverage
-        if: steps.changes.outputs.src == 'true'
-        working-directory: ./
-        run: |
-          make coverage