From a182e06aa5bf28ab51b9d1925543ec3b125e11d7 Mon Sep 17 00:00:00 2001 From: ChrisLiu Date: Wed, 21 Sep 2022 17:14:23 +0800 Subject: [PATCH] add github workflow Signed-off-by: ChrisLiu --- .github/workflows/ci.yaml | 107 ++++++++++++++++++ .github/workflows/license.yaml | 26 +++++ .../workflows/markdown-link-check.config.json | 10 ++ 3 files changed, 143 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/license.yaml create mode 100644 .github/workflows/markdown-link-check.config.json diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..31249a0c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,107 @@ +name: CI + +on: + push: + branches: + - master + - release-* + pull_request: {} + workflow_dispatch: {} + +env: + # Common versions + GO_VERSION: '1.18' + GOLANGCI_VERSION: 'v1.47' + DOCKER_BUILDX_VERSION: 'v0.4.2' + + # Common users. We can't run a step 'if secrets.AWS_USR != ""' but we can run + # a step 'if env.AWS_USR' != ""', so we copy these to succinctly test whether + # credentials have been provided before trying to run steps that need them. + DOCKER_USR: ${{ secrets.DOCKER_USR }} + AWS_USR: ${{ secrets.AWS_USR }} + +jobs: + + golangci-lint: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: true + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - name: Cache Go Dependencies + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - name: Code generate + run: | + make generate + - name: Lint golang code + uses: golangci/golangci-lint-action@v3.2.0 + with: + version: ${{ env.GOLANGCI_VERSION }} + args: --verbose + skip-pkg-cache: true + + markdownlint-misspell-shellcheck: + runs-on: ubuntu-18.04 + # this image is build from Dockerfile + # https://github.com/pouchcontainer/pouchlinter/blob/master/Dockerfile + container: pouchcontainer/pouchlinter:v0.1.2 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Run misspell + run: find ./* -name "*" | grep -v vendor | xargs misspell -error + - name: Run shellcheck + run: find ./ -name "*.sh" | grep -v vendor | xargs shellcheck + - name: Lint markdown files + run: find ./ -name "*.md" | grep -v vendor | grep -v commandline | grep -v .github | grep -v swagger | grep -v api | xargs mdl -r ~MD010,~MD013,~MD014,~MD022,~MD024,~MD029,~MD031,~MD032,~MD033,~MD036 + # - name: Check markdown links + # run: | + # set +e + # for name in $(find . -name \*.md | grep -v vendor | grep -v CHANGELOG); do + # if [ -f $name ]; then + # markdown-link-check -q $name -c .github/workflows/markdown-link-check.config.json; + # if [ $? -ne 0 ]; then + # code=1 + # fi + # fi + # done + # bash -c "exit $code"; + + unit-tests: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Fetch History + run: git fetch --prune --unshallow + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + - name: Cache Go Dependencies + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - name: Run Unit Tests + run: | + make test + git status + - name: Publish Unit Test Coverage + uses: codecov/codecov-action@v3 + with: + flags: unittests + file: cover.out + - name: Check diff + run: '[[ -z $(git status -s) ]] || (printf "Existing modified/untracked files.\nPlease run \"make generate manifests\" and push again.\n"; exit 1)' \ No newline at end of file diff --git a/.github/workflows/license.yaml b/.github/workflows/license.yaml new file mode 100644 index 00000000..210c7105 --- /dev/null +++ b/.github/workflows/license.yaml @@ -0,0 +1,26 @@ +name: License +on: + push: + branches: + - master + - release-* + workflow_dispatch: {} + pull_request: + branches: + - master + - release-* + +jobs: + license_check: + runs-on: ubuntu-latest + name: Check for unapproved licenses + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - name: Install dependencies + run: gem install license_finder + - name: Run tests + run: license_finder --decisions_file .license/dependency_decisions.yml \ No newline at end of file diff --git a/.github/workflows/markdown-link-check.config.json b/.github/workflows/markdown-link-check.config.json new file mode 100644 index 00000000..8b36bb1a --- /dev/null +++ b/.github/workflows/markdown-link-check.config.json @@ -0,0 +1,10 @@ +{ + "ignorePatterns": [ + { + "pattern": "^https://codecov.io" + }, + { + "pattern": "^https://openkruise.io" + } + ] +} \ No newline at end of file