Docs checker #605
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docs checker | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
aka-validation: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
repo: | |
- TeamsFx | |
- TeamsFx.wiki | |
- TeamsFx-Samples | |
steps: | |
- name: Checkout TeamsFx.wiki | |
uses: actions/checkout@v3 | |
with: | |
repository: OfficeDev/${{ matrix.repo }} | |
- name: List akas | |
id: list-akas | |
run: | | |
links=`git grep -hEo "https://aka[a-zA-Z0-9./?=_%:-]*[a-zA-Z0-9]" | sort -nr | uniq` | |
white_list="https://aka.ms/teamsfx-plugin-api;https://aka.ms/dotnet;https://aka.ms/teamsfx-migrate-v1" | |
while IFS= read -r link; | |
do | |
if [[ $white_list == *"$link"* ]]; then | |
echo $link "=>" "white list" >> akas.data | |
continue | |
fi | |
redirect=`curl -LIs -o /dev/null -w %{url_effective} $link` | |
echo $link "=>" $redirect >> akas.data | |
done <<< $links | |
- name: Upload akas to artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.repo }} | |
path: akas.data | |
output-link-result: | |
runs-on: ubuntu-latest | |
needs: aka-validation | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
path: artifacts | |
- name: List akas | |
id: list-akas | |
working-directory: artifacts | |
run: | | |
files=(*) | |
lists="" | |
touch result.txt | |
for file in "${files[@]}"; | |
do | |
echo $file | |
while IFS= read -r line | |
do | |
aka=`echo $line | awk -F '=>' '{print $1}'` | |
redirect=`echo $line | awk -F '=>' '{print $2}'` | |
label="" | |
if [[ $redirect == *"bing.com"* ]]; | |
then | |
label="INVALID" | |
elif [[ $redirect == *"white list"* ]]; | |
then | |
label="SKIPPED" | |
else | |
httpcode=`curl -s -o /dev/null -w %{http_code} $redirect` | |
if [[ $httpcode == 404 ]]; | |
then | |
label="INVALID" | |
else | |
label="VALID" | |
fi | |
fi | |
row="$file $aka $label" | |
echo $row >> result.txt | |
done < $file/akas.data | |
done | |
- name: upload result to artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: result | |
path: artifacts/result.txt | |
report: | |
runs-on: ubuntu-latest | |
needs: aka-validation | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
path: artifacts | |
- name: List akas | |
id: list-akas | |
working-directory: artifacts | |
run: | | |
files=(*) | |
lists="" | |
emails="[email protected]" | |
valid=0 | |
invalid=0 | |
for file in "${files[@]}"; | |
do | |
echo $file | |
while IFS= read -r line | |
do | |
aka=`echo $line | awk -F '=>' '{print $1}'` | |
redirect=`echo $line | awk -F '=>' '{print $2}'` | |
label="" | |
invalid_url=false | |
if [[ $redirect == *"bing.com"* ]]; | |
then | |
invalid_url=true | |
invalid=$((invalid+1)) | |
label="<span style=\\\"background-color: #dc322f;color:white;font-weight:bold;\\\">INVALID</span>" | |
elif [[ $redirect == *"white list"* ]]; | |
then | |
valid=$((valid+1)) | |
label="<span style=\\\"background-color:#b58900;color:white;font-weight:bold;\\\">SKIPPED</span>" | |
else | |
httpcode=`curl -s -o /dev/null -w %{http_code} $redirect` | |
if [[ $httpcode == 404 ]]; | |
then | |
invalid_url=true | |
invalid=$((invalid+1)) | |
label="<span style=\\\"background-color: #dc322f;color:white;font-weight:bold;\\\">INVALID</span>" | |
else | |
valid=$((valid+1)) | |
label="<span style=\\\"background-color:#2aa198;color:white;font-weight:bold;\\\">VALID</span>" | |
fi | |
fi | |
row="<tr> <td style=\\\"text-align: left;\\\">$file</td> <td style=\\\"text-align: left;\\\">$aka</td> <td style=\\\"text-align: center;\\\">$label</td> </tr>" | |
echo $row | |
if [[ $invalid_url == true ]]; | |
then | |
lists="$row $lists" | |
else | |
lists="$lists $row" | |
fi | |
done < $file/akas.data | |
done | |
body="Dashboard App: <a href=\\\"https:\/\/teams.microsoft.com\/l\/entity\/c439ae8d-3ab3-4efd-9223-87366d8c170c\/_djb2_msteams_prefix_1252604900?context=%7B%22channelId%22%3A%2219%3A79488ced607f4fbf8d8433e931cad176%40thread.tacv2%22%7D&tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47\\\">Click Here to Open Dashboard App</a> <table class=\\\"w3-table w3-striped w3-bordered\\\"> <tr> <th>REPO</th> <th>AKA</th> <th>STATUS</th> </tr> $lists </table> <br />" | |
total=$((valid+invalid)) | |
subject="TeamsFx AKA Link Report ($valid/$total Passed)" | |
if [ $invalid -gt 0 ]; then | |
subject="[FAILED] $subject" | |
emails="$emails;[email protected]" | |
else | |
subject="[PASSED] $subject" | |
fi | |
echo "body=$body" >> $GITHUB_OUTPUT | |
echo "to=$emails" >> $GITHUB_OUTPUT | |
echo "subject=$subject" >> $GITHUB_OUTPUT | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Send E-mail to the whole team | |
uses: ./.github/actions/send-email-report | |
env: | |
TO: ${{ steps.list-akas.outputs.to }} | |
BODY: '"${{ steps.list-akas.outputs.body }}"' | |
SUBJECT: ${{ steps.list-akas.outputs.subject }} | |
MAIL_CLIENT_ID: ${{ secrets.TEST_CLEAN_CLIENT_ID }} | |
MAIL_CLIENT_SECRET: ${{ secrets.TEST_CLEAN_CLIENT_SECRET }} | |
MAIL_TENANT_ID: ${{ secrets.TEST_CLEAN_TENANT_ID }} |