From 2e44675bd565fbbb7d11e9658f5d74fcbbc1795b Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Tue, 24 Sep 2024 19:31:53 +0800 Subject: [PATCH 01/11] Change search scope to diff.(WIP) Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 251 +++++++++++++----------- 1 file changed, 133 insertions(+), 118 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 928b5a61d..9556d97c8 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -9,38 +9,38 @@ on: types: [opened, reopened, ready_for_review, synchronize] jobs: - check-dockerfile-paths: - runs-on: ubuntu-latest - steps: - - name: Clean Up Working Directory - run: sudo rm -rf ${{github.workspace}}/* - - - name: Checkout Repo GenAIExamples - uses: actions/checkout@v4 - - - name: Clone Repo GenAIComps - run: | - cd .. - git clone https://github.com/opea-project/GenAIComps.git - - - name: Check for Missing Dockerfile Paths in GenAIComps - run: | - cd ${{github.workspace}} - miss="FALSE" - while IFS=: read -r file line content; do - dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}') - if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then - miss="TRUE" - echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})" - fi - done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .) - - - if [[ "$miss" == "TRUE" ]]; then - exit 1 - fi - - shell: bash + # check-dockerfile-paths: + # runs-on: ubuntu-latest + # steps: + # - name: Clean Up Working Directory + # run: sudo rm -rf ${{github.workspace}}/* + + # - name: Checkout Repo GenAIExamples + # uses: actions/checkout@v4 + + # - name: Clone Repo GenAIComps + # run: | + # cd .. + # git clone https://github.com/opea-project/GenAIComps.git + + # - name: Check for Missing Dockerfile Paths in GenAIComps + # run: | + # cd ${{github.workspace}} + # miss="FALSE" + # while IFS=: read -r file line content; do + # dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}') + # if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then + # miss="TRUE" + # echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})" + # fi + # done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .) + + + # if [[ "$miss" == "TRUE" ]]; then + # exit 1 + # fi + + # shell: bash check-the-validity-of-hyperlinks-in-README: runs-on: ubuntu-latest @@ -53,97 +53,32 @@ jobs: - name: Check the Validity of Hyperlinks run: | + set -x cd ${{github.workspace}} fail="FALSE" - url_lines=$(grep -Eo '\]\(http[s]?://[^)]+\)' --include='*.md' -r .) - if [ -n "$url_lines" ]; then - for url_line in $url_lines; do - url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//') - path=$(echo "$url_line"|cut -d':' -f1 | cut -d'/' -f2-) - response=$(curl -L -s -o /dev/null -w "%{http_code}" "$url") - if [ "$response" -ne 200 ]; then - echo "**********Validation failed, try again**********" - response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") - if [ "$response_retry" -eq 200 ]; then - echo "*****Retry successfully*****" - else - echo "Invalid link from ${{github.workspace}}/$path: $url" - fail="TRUE" - fi - fi - done - fi - - if [[ "$fail" == "TRUE" ]]; then - exit 1 - else - echo "All hyperlinks are valid." - fi - shell: bash - - check-the-validity-of-relative-path: - runs-on: ubuntu-latest - steps: - - name: Clean up Working Directory - run: sudo rm -rf ${{github.workspace}}/* - - - name: Checkout Repo GenAIExamples - uses: actions/checkout@v4 - - - name: Checking Relative Path Validity - run: | - cd ${{github.workspace}} - fail="FALSE" - repo_name=${{ github.event.pull_request.head.repo.full_name }} - if [ "$(echo "$repo_name"|cut -d'/' -f1)" != "opea-project" ]; then - owner=$(echo "${{ github.event.pull_request.head.repo.full_name }}" |cut -d'/' -f1) - branch="https://github.com/$owner/GenAIExamples/tree/${{ github.event.pull_request.head.ref }}" - else - branch="https://github.com/opea-project/GenAIExamples/blob/${{ github.event.pull_request.head.ref }}" - fi - link_head="https://github.com/opea-project/GenAIExamples/blob/main" - png_lines=$(grep -Eo '\]\([^)]+\)' --include='*.md' -r .|grep -Ev 'http') - if [ -n "$png_lines" ]; then - for png_line in $png_lines; do - refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-) - png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) - if [[ "${png_path:0:1}" == "/" ]]; then - check_path=${{github.workspace}}$png_path - elif [[ "${png_path:0:1}" == "#" ]]; then - check_path=${{github.workspace}}/$refer_path$png_path - else - check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path - fi - real_path=$(realpath $check_path) - if [ $? -ne 0 ]; then - echo "Path $png_path in file ${{github.workspace}}/$refer_path does not exist" - fail="TRUE" - else - url=$link_head$(echo "$real_path" | sed 's|.*/GenAIExamples||') - response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url") - if [ "$response" -ne 200 ]; then - echo "**********Validation failed, try again**********" - response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") - if [ "$response_retry" -eq 200 ]; then - echo "*****Retry successfully*****" - else - echo "Retry failed. Check branch ${{ github.event.pull_request.head.ref }}" - url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||') - response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") - if [ "$response" -ne 200 ]; then - echo "**********Validation failed, try again**********" - response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url_dev") - if [ "$response_retry" -eq 200 ]; then - echo "*****Retry successfully*****" - else - echo "Invalid path from ${{github.workspace}}/$refer_path: $png_path" - fail="TRUE" - fi + merged_commit=$(git log -1 --format='%H') + changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$'| awk '{print $NF}')" + if [ -n "changed_files" ]; then + for changed_file in $changed_files; do + echo $changed_file + url_lines=$(grep -H -Eo '\]\(http[s]?://[^)]+\)' "$changed_file" | grep -Ev 'GenAIExamples/blob/main') + if [ -n "$url_lines" ]; then + for url_line in $url_lines; do + echo $url_line + url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//') + path=$(echo "$url_line"|cut -d':' -f1 | cut -d'/' -f2-) + response=$(curl -L -s -o /dev/null -w "%{http_code}" "$url") + if [ "$response" -ne 200 ]; then + echo "**********Validation failed, try again**********" + response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") + if [ "$response_retry" -eq 200 ]; then + echo "*****Retry successfully*****" else - echo "Check branch ${{ github.event.pull_request.head.ref }} successfully." + echo "Invalid link from ${{github.workspace}}/$path: $url" + fail="TRUE" fi fi - fi + done fi done fi @@ -154,3 +89,83 @@ jobs: echo "All hyperlinks are valid." fi shell: bash + + # check-the-validity-of-relative-path: + # runs-on: ubuntu-latest + # steps: + # - name: Clean up Working Directory + # run: sudo rm -rf ${{github.workspace}}/* + + # - name: Checkout Repo GenAIExamples + # uses: actions/checkout@v4 + + # - name: Checking Relative Path Validity + # run: | + # cd ${{github.workspace}} + # fail="FALSE" + # repo_name=${{ github.event.pull_request.head.repo.full_name }} + # if [ "$(echo "$repo_name"|cut -d'/' -f1)" != "opea-project" ]; then + # owner=$(echo "${{ github.event.pull_request.head.repo.full_name }}" |cut -d'/' -f1) + # branch="https://github.com/$owner/GenAIExamples/tree/${{ github.event.pull_request.head.ref }}" + # else + # branch="https://github.com/opea-project/GenAIExamples/blob/${{ github.event.pull_request.head.ref }}" + # fi + # link_head="https://github.com/opea-project/GenAIExamples/blob/main" + # merged_commit=$(git log -1 --format='%H') + # changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$'| awk '{print $NF}')" + # if [ -n "changed_files" ]; then + # for changed_file in $changed_files; do + # png_lines=$(grep -H -Eo '\]\([^)]+\)' "$changed_file" |grep -Ev 'http') + # if [ -n "$png_lines" ]; then + # for png_line in $png_lines; do + # refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-) + # png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) + # if [[ "${png_path:0:1}" == "/" ]]; then + # check_path=${{github.workspace}}$png_path + # elif [[ "${png_path:0:1}" == "#" ]]; then + # check_path=${{github.workspace}}/$refer_path$png_path + # else + # check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path + # fi + # real_path=$(realpath $check_path) + # if [ $? -ne 0 ]; then + # echo "Path $png_path in file ${{github.workspace}}/$refer_path does not exist" + # fail="TRUE" + # else + # url=$link_head$(echo "$real_path" | sed 's|.*/GenAIExamples||') + # response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url") + # if [ "$response" -ne 200 ]; then + # echo "**********Validation failed, status code: $response, try again**********" + # response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") + # if [ "$response_retry" -eq 200 ]; then + # echo "*****Retry successfully*****" + # else + # echo "Retry failed. Check branch ${{ github.event.pull_request.head.ref }}" + # url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||') + # response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") + # if [ "$response" -ne 200 ]; then + # echo "**********Validation failed, status code: $response_retry, try again**********" + # response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url_dev") + # if [ "$response_retry" -eq 200 ]; then + # echo "*****Retry successfully*****" + # else + # echo "Invalid path from ${{github.workspace}}/$refer_path: $png_path status code: $response_retry" + # fail="TRUE" + # fi + # else + # echo "Check branch ${{ github.event.pull_request.head.ref }} successfully." + # fi + # fi + # fi + # fi + # done + # fi + # done + # fi + + # if [[ "$fail" == "TRUE" ]]; then + # exit 1 + # else + # echo "All hyperlinks are valid." + # fi + # shell: bash From 00ca6a1238c06bccc50cd1ce63f2d7ac0a706379 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Tue, 24 Sep 2024 20:13:46 +0800 Subject: [PATCH 02/11] test Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 9556d97c8..20ebaf849 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -50,6 +50,8 @@ jobs: - name: Checkout Repo GenAIExamples uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Check the Validity of Hyperlinks run: | @@ -57,7 +59,7 @@ jobs: cd ${{github.workspace}} fail="FALSE" merged_commit=$(git log -1 --format='%H') - changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$'| awk '{print $NF}')" + changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$' || true | awk '{print $NF}')" if [ -n "changed_files" ]; then for changed_file in $changed_files; do echo $changed_file From 05ead5b2a43beb53cd4391e335d86378c745bb33 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Tue, 24 Sep 2024 21:19:39 +0800 Subject: [PATCH 03/11] enable check relative path. Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 155 ++++++++++++------------ 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 20ebaf849..316055fe0 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -55,7 +55,6 @@ jobs: - name: Check the Validity of Hyperlinks run: | - set -x cd ${{github.workspace}} fail="FALSE" merged_commit=$(git log -1 --format='%H') @@ -83,6 +82,8 @@ jobs: done fi done + else + echo "No changed .md file." fi if [[ "$fail" == "TRUE" ]]; then @@ -92,82 +93,82 @@ jobs: fi shell: bash - # check-the-validity-of-relative-path: - # runs-on: ubuntu-latest - # steps: - # - name: Clean up Working Directory - # run: sudo rm -rf ${{github.workspace}}/* + check-the-validity-of-relative-path: + runs-on: ubuntu-latest + steps: + - name: Clean up Working Directory + run: sudo rm -rf ${{github.workspace}}/* - # - name: Checkout Repo GenAIExamples - # uses: actions/checkout@v4 + - name: Checkout Repo GenAIExamples + uses: actions/checkout@v4 + with: + fetch-depth: 0 - # - name: Checking Relative Path Validity - # run: | - # cd ${{github.workspace}} - # fail="FALSE" - # repo_name=${{ github.event.pull_request.head.repo.full_name }} - # if [ "$(echo "$repo_name"|cut -d'/' -f1)" != "opea-project" ]; then - # owner=$(echo "${{ github.event.pull_request.head.repo.full_name }}" |cut -d'/' -f1) - # branch="https://github.com/$owner/GenAIExamples/tree/${{ github.event.pull_request.head.ref }}" - # else - # branch="https://github.com/opea-project/GenAIExamples/blob/${{ github.event.pull_request.head.ref }}" - # fi - # link_head="https://github.com/opea-project/GenAIExamples/blob/main" - # merged_commit=$(git log -1 --format='%H') - # changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$'| awk '{print $NF}')" - # if [ -n "changed_files" ]; then - # for changed_file in $changed_files; do - # png_lines=$(grep -H -Eo '\]\([^)]+\)' "$changed_file" |grep -Ev 'http') - # if [ -n "$png_lines" ]; then - # for png_line in $png_lines; do - # refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-) - # png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) - # if [[ "${png_path:0:1}" == "/" ]]; then - # check_path=${{github.workspace}}$png_path - # elif [[ "${png_path:0:1}" == "#" ]]; then - # check_path=${{github.workspace}}/$refer_path$png_path - # else - # check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path - # fi - # real_path=$(realpath $check_path) - # if [ $? -ne 0 ]; then - # echo "Path $png_path in file ${{github.workspace}}/$refer_path does not exist" - # fail="TRUE" - # else - # url=$link_head$(echo "$real_path" | sed 's|.*/GenAIExamples||') - # response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url") - # if [ "$response" -ne 200 ]; then - # echo "**********Validation failed, status code: $response, try again**********" - # response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") - # if [ "$response_retry" -eq 200 ]; then - # echo "*****Retry successfully*****" - # else - # echo "Retry failed. Check branch ${{ github.event.pull_request.head.ref }}" - # url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||') - # response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") - # if [ "$response" -ne 200 ]; then - # echo "**********Validation failed, status code: $response_retry, try again**********" - # response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url_dev") - # if [ "$response_retry" -eq 200 ]; then - # echo "*****Retry successfully*****" - # else - # echo "Invalid path from ${{github.workspace}}/$refer_path: $png_path status code: $response_retry" - # fail="TRUE" - # fi - # else - # echo "Check branch ${{ github.event.pull_request.head.ref }} successfully." - # fi - # fi - # fi - # fi - # done - # fi - # done - # fi + - name: Checking Relative Path Validity + run: | + cd ${{github.workspace}} + fail="FALSE" + repo_name=${{ github.event.pull_request.head.repo.full_name }} + if [ "$(echo "$repo_name"|cut -d'/' -f1)" != "opea-project" ]; then + owner=$(echo "${{ github.event.pull_request.head.repo.full_name }}" |cut -d'/' -f1) + branch="https://github.com/$owner/GenAIExamples/tree/${{ github.event.pull_request.head.ref }}" + else + branch="https://github.com/opea-project/GenAIExamples/blob/${{ github.event.pull_request.head.ref }}" + fi + link_head="https://github.com/opea-project/GenAIExamples/blob/main" - # if [[ "$fail" == "TRUE" ]]; then - # exit 1 - # else - # echo "All hyperlinks are valid." - # fi - # shell: bash + merged_commit=$(git log -1 --format='%H') + changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$' || true | awk '{print $NF}')" + png_lines=$(grep -Eo '\]\([^)]+\)' --include='*.md' -r .|grep -Ev 'http') + if [ -n "$png_lines" ]; then + for png_line in $png_lines; do + refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-) + png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) + + if [[ "${png_path:0:1}" == "/" ]]; then + check_path=${{github.workspace}}$png_path + elif [[ "${png_path:0:1}" == "#" ]]; then + check_path=${{github.workspace}}/$refer_path$png_path + else + check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path + fi + real_path=$(realpath $check_path) + if [ $? -ne 0 ]; then + echo "${{github.workspace}}/$refer_path:$png_path does not exist" + fail="TRUE" + fi + if [[ "$png_line" == *#* ]]; then + if [ -e "$real_path" ]; then + if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${real_path}$"; then + url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||') + response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") + if [ "$response" -ne 200 ]; then + echo "**********Validation failed, try again**********" + response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url_dev") + if [ "$response_retry" -eq 200 ]; then + echo "*****Retry successfully*****" + else + echo "Invalid path from ${{github.workspace}}/$refer_path: $png_path" + fail="TRUE" + fi + fi + fi + else + echo "$real_path could not be found." + fail="TRUE" + fi + else + if [ ! -e "$real_path" ]; then + echo "$png_path referenced in file $refer_path could not be found." + fail="TRUE" + fi + fi + done + fi + + if [[ "$fail" == "TRUE" ]]; then + exit 1 + else + echo "All hyperlinks are valid." + fi + shell: bash From d94c4f2367067308d97db090f2867aca19982e79 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Tue, 24 Sep 2024 23:22:03 +0800 Subject: [PATCH 04/11] Change field processing Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 316055fe0..0fcd32aa9 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -128,7 +128,8 @@ jobs: if [[ "${png_path:0:1}" == "/" ]]; then check_path=${{github.workspace}}$png_path elif [[ "${png_path:0:1}" == "#" ]]; then - check_path=${{github.workspace}}/$refer_path$png_path + check_path=${{github.workspace}}/$refer_path + # $png_path else check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path fi @@ -140,7 +141,7 @@ jobs: if [[ "$png_line" == *#* ]]; then if [ -e "$real_path" ]; then if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${real_path}$"; then - url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||') + url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||')$png_path response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") if [ "$response" -ne 200 ]; then echo "**********Validation failed, try again**********" From 4cf137b4eab70c754220c68034e371615395c306 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Tue, 24 Sep 2024 23:24:55 +0800 Subject: [PATCH 05/11] test Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 6 ++++-- ChatQnA/benchmark/{performance => }/README.md | 0 2 files changed, 4 insertions(+), 2 deletions(-) rename ChatQnA/benchmark/{performance => }/README.md (100%) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 0fcd32aa9..3804d263a 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -58,7 +58,7 @@ jobs: cd ${{github.workspace}} fail="FALSE" merged_commit=$(git log -1 --format='%H') - changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$' || true | awk '{print $NF}')" + changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | awk '/\.md$/ {print $NF}')" if [ -n "changed_files" ]; then for changed_file in $changed_files; do echo $changed_file @@ -118,7 +118,7 @@ jobs: link_head="https://github.com/opea-project/GenAIExamples/blob/main" merged_commit=$(git log -1 --format='%H') - changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | grep '\.md$' || true | awk '{print $NF}')" + changed_files="$(git diff --name-status --diff-filter=ARM ${{ github.event.pull_request.base.sha }} ${merged_commit} | awk '/\.md$/ {print $NF}')" png_lines=$(grep -Eo '\]\([^)]+\)' --include='*.md' -r .|grep -Ev 'http') if [ -n "$png_lines" ]; then for png_line in $png_lines; do @@ -152,6 +152,8 @@ jobs: echo "Invalid path from ${{github.workspace}}/$refer_path: $png_path" fail="TRUE" fi + else + echo "Validation succeed $png_line" fi fi else diff --git a/ChatQnA/benchmark/performance/README.md b/ChatQnA/benchmark/README.md similarity index 100% rename from ChatQnA/benchmark/performance/README.md rename to ChatQnA/benchmark/README.md From aa7a5679c2b2b19b8974441228c935c647299c7a Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Wed, 25 Sep 2024 00:38:24 +0800 Subject: [PATCH 06/11] test Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 3804d263a..0129e2979 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -133,7 +133,7 @@ jobs: else check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path fi - real_path=$(realpath $check_path) + real_path=$(realpath $check_path 2>/dev/null) if [ $? -ne 0 ]; then echo "${{github.workspace}}/$refer_path:$png_path does not exist" fail="TRUE" From d413bf8e8b49e5f3865f22d63691b87a9cc92d98 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Wed, 25 Sep 2024 00:56:15 +0800 Subject: [PATCH 07/11] Optimize code structure Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 0129e2979..7a2830b8d 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -133,14 +133,13 @@ jobs: else check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path fi - real_path=$(realpath $check_path 2>/dev/null) - if [ $? -ne 0 ]; then - echo "${{github.workspace}}/$refer_path:$png_path does not exist" - fail="TRUE" - fi - if [[ "$png_line" == *#* ]]; then - if [ -e "$real_path" ]; then + + if [ -e "$check_path" ]; then + real_path=$(realpath $check_path) + if [[ "$png_line" == *#* ]]; then + echo "#" $png_line if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${real_path}$"; then + echo "Is in diff" url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||')$png_path response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") if [ "$response" -ne 200 ]; then @@ -153,18 +152,14 @@ jobs: fail="TRUE" fi else - echo "Validation succeed $png_line" + echo "Validation succeed $png_line" fi fi - else - echo "$real_path could not be found." - fail="TRUE" fi else - if [ ! -e "$real_path" ]; then - echo "$png_path referenced in file $refer_path could not be found." - fail="TRUE" - fi + echo $png_line + echo "${{github.workspace}}/$refer_path:$png_path does not exist" + fail="TRUE" fi done fi From 09f85b11d6483cb0daaac5611f499f9c51db5585 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Wed, 25 Sep 2024 01:01:02 +0800 Subject: [PATCH 08/11] test Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 7a2830b8d..333cd6052 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -137,8 +137,8 @@ jobs: if [ -e "$check_path" ]; then real_path=$(realpath $check_path) if [[ "$png_line" == *#* ]]; then - echo "#" $png_line - if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${real_path}$"; then + echo "$changed_files" + if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${refer_path}$"; then echo "Is in diff" url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||')$png_path response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") From 6d17d9033239ab36c1e4bc10d6f58107980da8e4 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Wed, 25 Sep 2024 01:10:20 +0800 Subject: [PATCH 09/11] Remove debug output Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 333cd6052..eeb9e5496 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -137,9 +137,7 @@ jobs: if [ -e "$check_path" ]; then real_path=$(realpath $check_path) if [[ "$png_line" == *#* ]]; then - echo "$changed_files" if [ -n "changed_files" ] && echo "$changed_files" | grep -q "^${refer_path}$"; then - echo "Is in diff" url_dev=$branch$(echo "$real_path" | sed 's|.*/GenAIExamples||')$png_path response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url_dev") if [ "$response" -ne 200 ]; then @@ -157,7 +155,6 @@ jobs: fi fi else - echo $png_line echo "${{github.workspace}}/$refer_path:$png_path does not exist" fail="TRUE" fi From f9c0e715c756018301def27cecc57ccf394b0441 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Wed, 25 Sep 2024 01:11:49 +0800 Subject: [PATCH 10/11] Restore test file Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 64 +++++++++---------- ChatQnA/benchmark/{ => performance}/README.md | 0 2 files changed, 32 insertions(+), 32 deletions(-) rename ChatQnA/benchmark/{ => performance}/README.md (100%) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index eeb9e5496..6768c67fc 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -9,38 +9,38 @@ on: types: [opened, reopened, ready_for_review, synchronize] jobs: - # check-dockerfile-paths: - # runs-on: ubuntu-latest - # steps: - # - name: Clean Up Working Directory - # run: sudo rm -rf ${{github.workspace}}/* - - # - name: Checkout Repo GenAIExamples - # uses: actions/checkout@v4 - - # - name: Clone Repo GenAIComps - # run: | - # cd .. - # git clone https://github.com/opea-project/GenAIComps.git - - # - name: Check for Missing Dockerfile Paths in GenAIComps - # run: | - # cd ${{github.workspace}} - # miss="FALSE" - # while IFS=: read -r file line content; do - # dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}') - # if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then - # miss="TRUE" - # echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})" - # fi - # done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .) - - - # if [[ "$miss" == "TRUE" ]]; then - # exit 1 - # fi - - # shell: bash + check-dockerfile-paths: + runs-on: ubuntu-latest + steps: + - name: Clean Up Working Directory + run: sudo rm -rf ${{github.workspace}}/* + + - name: Checkout Repo GenAIExamples + uses: actions/checkout@v4 + + - name: Clone Repo GenAIComps + run: | + cd .. + git clone https://github.com/opea-project/GenAIComps.git + + - name: Check for Missing Dockerfile Paths in GenAIComps + run: | + cd ${{github.workspace}} + miss="FALSE" + while IFS=: read -r file line content; do + dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}') + if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then + miss="TRUE" + echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})" + fi + done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .) + + + if [[ "$miss" == "TRUE" ]]; then + exit 1 + fi + + shell: bash check-the-validity-of-hyperlinks-in-README: runs-on: ubuntu-latest diff --git a/ChatQnA/benchmark/README.md b/ChatQnA/benchmark/performance/README.md similarity index 100% rename from ChatQnA/benchmark/README.md rename to ChatQnA/benchmark/performance/README.md From c9d02d88d97699d3c5b247c22db26e8397f6cc44 Mon Sep 17 00:00:00 2001 From: ZePan110 Date: Fri, 27 Sep 2024 22:49:32 +0800 Subject: [PATCH 11/11] Fix issue. Signed-off-by: ZePan110 --- .github/workflows/pr-path-detection.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-path-detection.yml b/.github/workflows/pr-path-detection.yml index 6768c67fc..0b38b05e6 100644 --- a/.github/workflows/pr-path-detection.yml +++ b/.github/workflows/pr-path-detection.yml @@ -126,12 +126,17 @@ jobs: png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) if [[ "${png_path:0:1}" == "/" ]]; then - check_path=${{github.workspace}}$png_path - elif [[ "${png_path:0:1}" == "#" ]]; then - check_path=${{github.workspace}}/$refer_path - # $png_path + check_path=$png_path + elif [[ "$png_path" == *#* ]]; then + relative_path=$(echo "$png_path" | cut -d '#' -f1) + if [ -n "$relative_path" ]; then + check_path=$(dirname "$refer_path")/$relative_path + png_path=$(echo "$png_path" | awk -F'#' '{print "#" $2}') + else + check_path=$refer_path + fi else - check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path + check_path=$(dirname "$refer_path")/$png_path fi if [ -e "$check_path" ]; then