From c7d7cef65c3518bcf8c1a35452e2f2d8af7132a1 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 2 Jul 2020 17:54:41 +0900 Subject: [PATCH 1/5] :white_check_mark: exclude hack tests Signed-off-by: Rintaro Okamura --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++++++---- Makefile.d/test.mk | 29 +++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb716e763e..02b39f809e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,8 +16,8 @@ on: - 'cmd/**' jobs: - coverage: - name: Run tests + test-cmd: + name: Run tests for cmd packages runs-on: ubuntu-latest container: image: vdaas/vald-ci-container:nightly @@ -26,6 +26,32 @@ jobs: uses: actions/checkout@v1 with: fetch-depth: 1 - - name: Run tests + - name: Run tests for cmd packages run: | - make test + make test/cmd + test-internal: + name: Run tests for internal packages + runs-on: ubuntu-latest + container: + image: vdaas/vald-ci-container:nightly + steps: + - name: Check out code. + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Run tests for internal packages + run: | + make test/internal + test-pkg: + name: Run tests for pkg packages + runs-on: ubuntu-latest + container: + image: vdaas/vald-ci-container:nightly + steps: + - name: Check out code. + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Run tests for pkg packages + run: | + make test/pkg diff --git a/Makefile.d/test.mk b/Makefile.d/test.mk index 0719b0ea4b..f20d01753d 100644 --- a/Makefile.d/test.mk +++ b/Makefile.d/test.mk @@ -15,9 +15,34 @@ # .PHONY: test -## run tests +## run tests for cmd, internal, pkg test: - go test -json -cover ./... | tparse -top + go test -json -cover ./cmd/... ./internal/... ./pkg/... | tparse -notests + +.PHONY: test/cmd +## run tests for cmd +test/cmd: + go test -json -cover ./cmd/... | tparse -pass -notests + +.PHONY: test/internal +## run tests for internal +test/internal: + go test -json -cover ./internal/... | tparse -pass -notests + +.PHONY: test/pkg +## run tests for pkg +test/pkg: + go test -json -cover ./pkg/... | tparse -pass -notests + +.PHONY: test/hack +## run tests for hack +test/hack: + go test -json -cover ./hack/... | tparse -pass -notests + +.PHONY: test/all +## run tests for all Go codes +test/all: + go test -json -cover ./... | tparse -notests .PHONY: coverage ## calculate coverages From 60239b2590a2dba9b7cd2ede7d32511e73ad74ad Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 2 Jul 2020 18:20:19 +0900 Subject: [PATCH 2/5] :green_heart: add chatops help Signed-off-by: Rintaro Okamura --- .github/chatops_commands.md | 6 ++++++ .github/workflows/chatops-help.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/chatops.yml | 8 +++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .github/chatops_commands.md create mode 100644 .github/workflows/chatops-help.yml diff --git a/.github/chatops_commands.md b/.github/chatops_commands.md new file mode 100644 index 0000000000..d9f0408676 --- /dev/null +++ b/.github/chatops_commands.md @@ -0,0 +1,6 @@ +- :ok_woman: `/approve` - approve +- :love_letter: `/changelog` - add changelog comment +- :bento: `/format` - format codes and add licenses +- :white_check_mark: `/gen-test` - generate test codes +- :label: `/label` - add labels +- :rewind: `/rebase` - rebase master diff --git a/.github/workflows/chatops-help.yml b/.github/workflows/chatops-help.yml new file mode 100644 index 0000000000..f28a639812 --- /dev/null +++ b/.github/workflows/chatops-help.yml @@ -0,0 +1,30 @@ +name: "ChatOps help" +on: + pull_request: + types: [opened] +jobs: + print-help: + name: print help + runs-on: ubuntu-latest + steps: + - name: comment to PR + run: | + PR_COMMENTS=`curl ${API_URL}?per_page=10000` + COMMENT_BODY=`echo -E $PR_COMMENTS | jq 'last(.[] | select(.user.login == "vdaas-ci") | select(.body | test("^\\\\*\\\\*\\\\[CHATOPS:HELP")) | .body)' -r` + + if [ "$COMMENT_BODY" = "null" ]; then + # curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_commands.md + curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/ci/run-tests/exclude-hack-codes/.github/chatops_commands.md + BODY=`echo chatops_commands.md | sed ':a;N;$!ba;s/\n/\\\\n/g'` + curl --include --verbose --fail \ + -H "Accept: application/json" \ + -H "Content-Type:application/json" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + --request POST \ + --data "{\"body\": \"**[CHATOPS:HELP]** ChatOps commands.\\n${BODY}\"}" \ + $API_URL + fi + env: + GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }} + API_URL: ${{ github.event.pull_request.comments_url }} + PR_NUM: ${{ github.event.issue.number }} diff --git a/.github/workflows/chatops.yml b/.github/workflows/chatops.yml index c9d24f9b3d..f7b9c87ac2 100644 --- a/.github/workflows/chatops.yml +++ b/.github/workflows/chatops.yml @@ -8,6 +8,7 @@ jobs: label: name: Add labels runs-on: ubuntu-latest + if: steps.check_comments_label.outputs.COMMENTER_USERNAME != 'vdaas-ci' steps: - name: check PR Comments id: check_comments_label @@ -60,6 +61,7 @@ jobs: changelog: name: Add draft comment for a new CHANGELOG entry runs-on: ubuntu-latest + if: steps.check_comments_label.outputs.COMMENTER_USERNAME != 'vdaas-ci' steps: - name: check PR Comments id: check_comments_changelog @@ -102,7 +104,7 @@ jobs: run: | git checkout master PREVIOUS_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1)) - BODY=`git log --pretty=format:'- %s' ${PREVIOUS_VERSION}..master | grep "#[[:digit:]]\+" | sed -e "s/\[\(patch\|minor\|major\)\] *//g" | sed -e "s%#\([[:digit:]]\+\)%[&](https://github.com/vdaas/vald/pull/\1)%" | sed ':a;N;$!ba;s/\n/\\\\n/g'` + BODY=`git log --pretty=format:'- %s' ${PREVIOUS_VERSION}..master | grep "#[[:digit:]]\+" | sed -e "s/\[\(patch\|minor\|major\)\] *//g" | sed -e "s%#\([[:digit:]]\+\)%[&](https://github.com/vdaas/vald/pull/\1)%g" | sed ':a;N;$!ba;s/\n/\\\\n/g'` CURRENT="- ${PR_TITLE} ([#${PR_NUM}](https://github.com/vdaas/vald/pull/${PR_NUM}))" curl --include --verbose --fail \ -H "Accept: application/json" \ @@ -119,6 +121,7 @@ jobs: rebase: name: Rebase runs-on: ubuntu-latest + if: steps.check_comments_label.outputs.COMMENTER_USERNAME != 'vdaas-ci' steps: - name: check PR Comments id: check_comments_rebase @@ -192,6 +195,7 @@ jobs: needs: - rebase runs-on: ubuntu-latest + if: steps.check_comments_label.outputs.COMMENTER_USERNAME != 'vdaas-ci' steps: - name: check PR Comments id: check_comments_gen_test @@ -298,6 +302,7 @@ jobs: - rebase - gentest runs-on: ubuntu-latest + if: steps.check_comments_label.outputs.COMMENTER_USERNAME != 'vdaas-ci' steps: - name: check PR Comments id: check_comments_format @@ -428,6 +433,7 @@ jobs: - rebase - format runs-on: ubuntu-latest + if: steps.check_comments_label.outputs.COMMENTER_USERNAME != 'vdaas-ci' steps: - name: check PR Comments id: check_comments_approve From 591a245fa9b474d7613b4ac240856a53811d3836 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 2 Jul 2020 18:23:08 +0900 Subject: [PATCH 3/5] :green_heart: Fix Signed-off-by: Rintaro Okamura --- .github/workflows/chatops-help.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/chatops-help.yml b/.github/workflows/chatops-help.yml index f28a639812..9b8c9e7548 100644 --- a/.github/workflows/chatops-help.yml +++ b/.github/workflows/chatops-help.yml @@ -1,7 +1,7 @@ name: "ChatOps help" on: pull_request: - types: [opened] + types: [opened, reopened] jobs: print-help: name: print help @@ -15,7 +15,7 @@ jobs: if [ "$COMMENT_BODY" = "null" ]; then # curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_commands.md curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/ci/run-tests/exclude-hack-codes/.github/chatops_commands.md - BODY=`echo chatops_commands.md | sed ':a;N;$!ba;s/\n/\\\\n/g'` + BODY=`cat chatops_commands.md | sed ':a;N;$!ba;s/\n/\\\\n/g'` curl --include --verbose --fail \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ From 36871b03ed363a25d06ee5a69550cba85875316b Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 2 Jul 2020 18:25:36 +0900 Subject: [PATCH 4/5] :green_heart: ok Signed-off-by: Rintaro Okamura --- .github/workflows/chatops-help.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/chatops-help.yml b/.github/workflows/chatops-help.yml index 9b8c9e7548..01a402a0a5 100644 --- a/.github/workflows/chatops-help.yml +++ b/.github/workflows/chatops-help.yml @@ -1,7 +1,7 @@ name: "ChatOps help" on: pull_request: - types: [opened, reopened] + types: [opened] jobs: print-help: name: print help @@ -13,8 +13,7 @@ jobs: COMMENT_BODY=`echo -E $PR_COMMENTS | jq 'last(.[] | select(.user.login == "vdaas-ci") | select(.body | test("^\\\\*\\\\*\\\\[CHATOPS:HELP")) | .body)' -r` if [ "$COMMENT_BODY" = "null" ]; then - # curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_commands.md - curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/ci/run-tests/exclude-hack-codes/.github/chatops_commands.md + curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_commands.md BODY=`cat chatops_commands.md | sed ':a;N;$!ba;s/\n/\\\\n/g'` curl --include --verbose --fail \ -H "Accept: application/json" \ From 93a5db677595e898335f157b429834c1e6295602 Mon Sep 17 00:00:00 2001 From: Rintaro Okamura Date: Thu, 2 Jul 2020 18:29:33 +0900 Subject: [PATCH 5/5] :fire: remove redundant codes Signed-off-by: Rintaro Okamura --- .github/workflows/chatops-help.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/chatops-help.yml b/.github/workflows/chatops-help.yml index 01a402a0a5..6ed7e02d49 100644 --- a/.github/workflows/chatops-help.yml +++ b/.github/workflows/chatops-help.yml @@ -9,20 +9,15 @@ jobs: steps: - name: comment to PR run: | - PR_COMMENTS=`curl ${API_URL}?per_page=10000` - COMMENT_BODY=`echo -E $PR_COMMENTS | jq 'last(.[] | select(.user.login == "vdaas-ci") | select(.body | test("^\\\\*\\\\*\\\\[CHATOPS:HELP")) | .body)' -r` - - if [ "$COMMENT_BODY" = "null" ]; then - curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_commands.md - BODY=`cat chatops_commands.md | sed ':a;N;$!ba;s/\n/\\\\n/g'` - curl --include --verbose --fail \ - -H "Accept: application/json" \ - -H "Content-Type:application/json" \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - --request POST \ - --data "{\"body\": \"**[CHATOPS:HELP]** ChatOps commands.\\n${BODY}\"}" \ - $API_URL - fi + curl -o chatops_commands.md https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_commands.md + BODY=`cat chatops_commands.md | sed ':a;N;$!ba;s/\n/\\\\n/g'` + curl --include --verbose --fail \ + -H "Accept: application/json" \ + -H "Content-Type:application/json" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + --request POST \ + --data "{\"body\": \"**[CHATOPS:HELP]** ChatOps commands.\\n${BODY}\"}" \ + $API_URL env: GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }} API_URL: ${{ github.event.pull_request.comments_url }}