Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add qase sync action #29

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion add-to-project-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ inputs:
required: true
runs:
using: 'node20'
main: '../lib/add-to-project-action.js'
main: '../lib/add-to-project-action.js'
5 changes: 3 additions & 2 deletions add-zenhub-release-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Add an issue to Zenhub release. If the release doesn't exist, it would be create
**Required** The Zenhub release name to be added/created.

## Example usage

```
steps:
- name: Get Repo Object
uses: octokit/[email protected]
Expand All @@ -36,4 +36,5 @@ steps:
zenhub_token: ${{ secrets.ZENHUB_TOKEN }}
repo_id: ${{ fromJSON(steps.repo.outputs.data).id }}
issue_number: ${{ github.event.issue.number }}
release_name: 1.4.0
release_name: 1.4.0
```
2 changes: 1 addition & 1 deletion add-zenhub-release-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ inputs:
required: true
runs:
using: 'node16'
main: '../lib/add-zenhub-release-action.js'
main: '../lib/add-zenhub-release-action.js'
2 changes: 2 additions & 0 deletions filter-org-members-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Get list of users belong to a specific organization from an input user list.

## Example usage

```
steps:
- name: Get Longhorn Members
uses: longhorn/bot/filter-org-members-action@master
Expand All @@ -26,3 +27,4 @@ steps:
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
organization: longhorn
usernames: ${{ github.event.issue.assignees.*.login }}
```
2 changes: 1 addition & 1 deletion filter-org-members-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ inputs:
required: true
runs:
using: 'node20'
main: '../lib/filter-org-members-action.js'
main: '../lib/filter-org-members-action.js'
24 changes: 24 additions & 0 deletions qase-sync-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Qase Sync composite action

Sync manual test cases between github and qase.

## Inputs

## `project-code`

**Required** Code of project, where to sync test cases.

## `token`

**Required** Qase API token.

## Example usage

```
steps:
- name: Qase Sync
uses: longhorn/bot/qase-sync-action@master
with:
project-code: ${{ secrets.PROJECT_CODE }}
token: ${{ secrets.QASE_TOKEN }}
```
175 changes: 175 additions & 0 deletions qase-sync-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: 'Qase Sync'
description: 'Sync manual test cases between github and qase'
inputs:
project-code:
description: 'Code of project, where to sync test cases.'
required: true
token:
description: 'Qase API token'
required: true
runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 3

- name: Fetch changed files
shell: bash
run: |
files=($(git diff --name-only HEAD HEAD^))
echo ${files[@]}
echo "files=${files[@]}" >> $GITHUB_ENV

- name: Filter changed test cases
shell: bash
env:
files: ${{ env.files }}
run: |
test_cases=()
files=(${files})
for file in "${files[@]}"; do
if [[ "${file}" == *"/manual/"* ]] && [[ "${file}" != *"_index"* ]]; then
test_case=$(echo "${file#*manual/}")
test_cases+=("${test_case}")
fi
done
echo "collected test cases: ${test_cases[@]}"
echo "test_cases=${test_cases[@]}" >> $GITHUB_ENV
echo "test_cases_length=${#test_cases[@]}" >> $GITHUB_ENV

- name: Create missing test suites
shell: bash
if: ${{ env.test_cases_length > 0 }}
env:
project_code: ${{ inputs.project-code }}
token: ${{ inputs.token }}
test_cases: ${{ env.test_cases }}
run: |
test_cases=(${test_cases})
for test_case in "${test_cases[@]}"; do

echo "processing test case: ${test_case}"
IFS='/' read -ra arr <<< "${test_case}"

parent_suite_id=""

for str in "${arr[@]}"; do
if [[ $str == *".md"* ]]; then
# only deal with test suite in this step
# test case will be processed in the next step
break
fi
str=${str//-/ } # replace - with whitespace
if [[ $str =~ ^v.+\..+\.+.+$ ]]; then
: # skip v*.*.*
elif [[ ${#str} -lt 4 ]]; then
# capitalize acronym like ha, eks, etc
str=${str^^}
else
str=($str)
str="${str[@]^}" # capitalize every word
fi

# check if the test suite already exists
res=$(curl -s --request GET --url "https://api.qase.io/v1/suite/${project_code}" --get --data-urlencode "search=${str}" --header "Token: ${token}" --header "accept: application/json")
echo "checked if test suite ${str} exists: ${res}"

# if not, create new test suite
if [[ $(echo "$res" | jq .result.count) == "0" ]]; then
echo "creating new test suite ${str} with parent id ${parent_suite_id}"
res=$(curl --request POST -s \
--url https://api.qase.io/v1/suite/${project_code} \
--header "Token: ${token}" \
--header "accept: application/json" \
--header "content-type: application/json" \
--data "{ \"title\": \"${str}\", \"parent_id\": \"${parent_suite_id}\" }")
echo "created new test suite ${str}: ${res}"
fi

# update parent suite id for the next iteration
res=$(curl -s --request GET --url "https://api.qase.io/v1/suite/${project_code}" --get --data-urlencode "search=${str}" --header "Token: ${token}" --header "accept: application/json")
parent_suite_id=$(echo "$res" | jq .result.entities[0].id)
echo "updated parent suite id to ${parent_suite_id}: ${res}"
done
done

- name: Create or update test cases
shell: bash
if: ${{ env.test_cases_length > 0 }}
env:
project_code: ${{ inputs.project-code }}
token: ${{ inputs.token }}
test_cases: ${{ env.test_cases }}
working-directory: ./docs/content/manual
run: |
test_cases=(${test_cases})

for file_path in "${test_cases[@]}"; do

delete_test_case=false
if [[ ! -e "${file_path}" ]]; then
echo "${file_path} has been deleted"
git checkout HEAD^ -- "${file_path}"
delete_test_case=true
fi

title=$(grep '^title:' ${file_path} | sed 's/title: //g' | sed 's/"/\\"/g')
echo "got test case title: ${title}"
description=$(sed -z 's/\n/\\n/g' ${file_path} | sed 's/ \\/ \\\\/g' | sed 's/"/\\"/g')
echo "got test case description: ${description}"

res=$(curl -s --request GET --url "https://api.qase.io/v1/case/${project_code}" --get --data-urlencode "search=${title}" --header "Token: ${token}" --header "accept: application/json")
if [[ $(echo $res | jq .result.count) -ne "0" ]] && [[ "${delete_test_case}" = true ]]; then
# delete existing test case
test_case_id=$(echo $res | jq .result.entities[0].id)

res=$(curl --request DELETE -s \
--url "https://api.qase.io/v1/case/${project_code}/${test_case_id}" \
--header "Token: ${token}" \
--header "accept: application/json")

echo "deleted existing test case: ${res}"
elif [[ $(echo $res | jq .result.count) -ne "0" ]]; then
# update existing test case
test_case_id=$(echo $res | jq .result.entities[0].id)

res=$(curl --request PATCH -s \
--url "https://api.qase.io/v1/case/${project_code}/${test_case_id}" \
--header "Token: ${token}" \
--header "accept: application/json" \
--header "content-type: application/json" \
--data "{ \"description\": \"${description}\", \"title\": \"${title}\" }")

echo "updated existing test case: ${res}"
else
# create new test case
parent_suite_name=$(basename $(dirname ${file_path}))

if [[ "${parent_suite_name}" == "manual" ]]; then
parent_suite_id=""
else
parent_suite_name=${parent_suite_name//-/ } # replace - with whitespace
if [[ $parent_suite_name =~ ^v.+\..+\.+.+$ ]]; then
: # skip v*.*.*
elif [[ ${#parent_suite_name} -lt 4 ]]; then
# capitalize acronym like ha, eks, etc
parent_suite_name=${parent_suite_name^^}
else
parent_suite_name=($parent_suite_name)
parent_suite_name="${parent_suite_name[@]^}" # capitalize every word
fi
res=$(curl -s --request GET --url "https://api.qase.io/v1/suite/${project_code}" --get --data-urlencode "search=${parent_suite_name}" --header "Token: ${token}" --header "accept: application/json")
parent_suite_id=$(echo "$res" | jq .result.entities[0].id)
fi
echo "creating new test case ${title} under test suite ${parent_suite_name}(${parent_suite_id})"
res=$(curl --request POST -s \
--url https://api.qase.io/v1/case/${project_code}/ \
--header "Token: ${token}" \
--header "accept: application/json" \
--header "content-type: application/json" \
--data "{ \"description\": \"${description}\", \"title\": \"${title}\", \"suite_id\": \"${parent_suite_id}\" }")
echo "created new test case ${title}: ${res}"
fi
done