|
| 1 | +# Copyright (C) 2024 Intel Corporation |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: Check Paths and Hyperlinks |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + types: [opened, reopened, ready_for_review, synchronize] |
| 10 | + |
| 11 | +jobs: |
| 12 | + check-dockerfile-paths: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Clean Up Working Directory |
| 16 | + run: sudo rm -rf ${{github.workspace}}/* |
| 17 | + |
| 18 | + - name: Checkout Repo GenAIExamples |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Clone Repo GenAIComps |
| 22 | + run: | |
| 23 | + cd .. |
| 24 | + git clone https://github.com/opea-project/GenAIComps.git |
| 25 | +
|
| 26 | + - name: Check for Missing Dockerfile Paths in GenAIComps |
| 27 | + run: | |
| 28 | + cd ${{github.workspace}} |
| 29 | + miss="FALSE" |
| 30 | + while IFS=: read -r file line content; do |
| 31 | + dockerfile_path=$(echo "$content" | awk -F '-f ' '{print $2}' | awk '{print $1}') |
| 32 | + if [[ ! -f "../GenAIComps/${dockerfile_path}" ]]; then |
| 33 | + miss="TRUE" |
| 34 | + echo "Missing Dockerfile: GenAIComps/${dockerfile_path} (Referenced in GenAIExamples/${file}:${line})" |
| 35 | + fi |
| 36 | + done < <(grep -Ern 'docker build .* -f comps/.+/Dockerfile' --include='*.md' .) |
| 37 | +
|
| 38 | +
|
| 39 | + if [[ "$miss" == "TRUE" ]]; then |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + shell: bash |
| 44 | + |
| 45 | + check-the-validity-of-hyperlinks-in-README: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + steps: |
| 48 | + - name: Clean Up Working Directory |
| 49 | + run: sudo rm -rf ${{github.workspace}}/* |
| 50 | + |
| 51 | + - name: Checkout Repo GenAIExamples |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Check the Validity of Hyperlinks |
| 55 | + run: | |
| 56 | + cd ${{github.workspace}} |
| 57 | + fail="FALSE" |
| 58 | + url_lines=$(grep -Eo '\]\(http[s]?://[^)]+\)' --include='*.md' -r .) |
| 59 | + if [ -n "$url_lines" ]; then |
| 60 | + for url_line in $url_lines; do |
| 61 | + url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//') |
| 62 | + path=$(echo "$url_line"|cut -d':' -f1 | cut -d'/' -f2-) |
| 63 | + response=$(curl -L -s -o /dev/null -w "%{http_code}" "$url") |
| 64 | + if [ "$response" -ne 200 ]; then |
| 65 | + echo "**********Validation failed, try again**********" |
| 66 | + response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") |
| 67 | + if [ "$response_retry" -eq 200 ]; then |
| 68 | + echo "*****Retry successfully*****" |
| 69 | + else |
| 70 | + echo "Invalid link from ${{github.workspace}}/$path: $url" |
| 71 | + fail="TRUE" |
| 72 | + fi |
| 73 | + fi |
| 74 | + done |
| 75 | + fi |
| 76 | +
|
| 77 | + if [[ "$fail" == "TRUE" ]]; then |
| 78 | + exit 1 |
| 79 | + else |
| 80 | + echo "All hyperlinks are valid." |
| 81 | + fi |
| 82 | + shell: bash |
| 83 | + |
| 84 | + check-the-validity-of-relative-path: |
| 85 | + runs-on: ubuntu-latest |
| 86 | + steps: |
| 87 | + - name: Clean up Working Directory |
| 88 | + run: sudo rm -rf ${{github.workspace}}/* |
| 89 | + |
| 90 | + - name: Checkout Repo GenAIExamples |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Checking Relative Path Validity |
| 94 | + run: | |
| 95 | + cd ${{github.workspace}} |
| 96 | + fail="FALSE" |
| 97 | + link_head="https://github.com/opea-project/GenAIExamples/blob/main/" |
| 98 | + png_lines=$(grep -Eo '\]\([^)]+\)' -r -I .|grep -Ev 'http') |
| 99 | + if [ -n "$png_lines" ]; then |
| 100 | + for png_line in $png_lines; do |
| 101 | + refer_path=$(echo "$png_line"|cut -d':' -f1 | cut -d'/' -f2-) |
| 102 | + png_path=$(echo "$png_line"|cut -d '(' -f2 | cut -d ')' -f1) |
| 103 | + if [[ "${png_path:0:1}" == "/" ]]; then |
| 104 | + check_path=${{github.workspace}}$png_path |
| 105 | + else |
| 106 | + check_path=${{github.workspace}}/$(dirname "$refer_path")/$png_path |
| 107 | + fi |
| 108 | + real_path=$(realpath $check_path) |
| 109 | + if [ $? -ne 0 ]; then |
| 110 | + echo "Path $png_path in file ${{github.workspace}}/$refer_path does not exist" |
| 111 | + fail="TRUE" |
| 112 | + else |
| 113 | + url=$link_head$(echo "$real_path" | sed 's|.*/GenAIExamples/||') |
| 114 | + response=$(curl -I -L -s -o /dev/null -w "%{http_code}" "$url") |
| 115 | + if [ "$response" -ne 200 ]; then |
| 116 | + echo "**********Validation failed, try again**********" |
| 117 | + response_retry=$(curl -s -o /dev/null -w "%{http_code}" "$url") |
| 118 | + if [ "$response_retry" -eq 200 ]; then |
| 119 | + echo "*****Retry successfully*****" |
| 120 | + else |
| 121 | + echo "Invalid link from $check_path: $url" |
| 122 | + fail="TRUE" |
| 123 | + fi |
| 124 | + fi |
| 125 | + fi |
| 126 | + done |
| 127 | + fi |
| 128 | +
|
| 129 | + if [[ "$fail" == "TRUE" ]]; then |
| 130 | + exit 1 |
| 131 | + else |
| 132 | + echo "All hyperlinks are valid." |
| 133 | + fi |
| 134 | + shell: bash |
0 commit comments