|
72 | 72 | echo "Git adding ${i}" |
73 | 73 | git add "${i}" |
74 | 74 | done |
| 75 | + - name: Check or create dot-no-jekyll file |
| 76 | + run: | |
| 77 | + if [ -f ".nojekyll" ]; then |
| 78 | + echo "The dot-no-jekyll file already exists." |
| 79 | + exit 0 |
| 80 | + fi |
| 81 | + touch .nojekyll |
| 82 | + git add .nojekyll |
| 83 | + - name: Check or create redirect page |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + run: | |
| 87 | + resp=$(grep 'http-equiv="refresh"' index.html 2>/dev/null) || true |
| 88 | + if [ -n "${resp}" ]; then |
| 89 | + echo "The redirect file already exists." |
| 90 | + exit 0 |
| 91 | + fi |
| 92 | + # If any of these commands fail, fail the build. |
| 93 | + def_branch=$(gh api "repos/${GITHUB_REPOSITORY}" --jq ".default_branch") |
| 94 | + html_url=$(gh api "repos/${GITHUB_REPOSITORY}/pages" --jq ".html_url") |
| 95 | + # Beware ugly quotation mark avoidance in the foll lines. |
| 96 | + echo '<!DOCTYPE html>' > index.html |
| 97 | + echo '<html>' >> index.html |
| 98 | + echo ' <head>' >> index.html |
| 99 | + echo ' <title>Redirect to documentation</title>' >> index.html |
| 100 | + echo ' <meta charset="utf-8">' >> index.html |
| 101 | + echo ' <meta http=equiv="refresh" content="3; URL='${html_url}${def_branch}'/index.html">' >> index.html |
| 102 | + echo ' <link rel="canonical" href="'${html_url}${def_branch}'/index.html">' >> index.html |
| 103 | + echo ' <script language="javascript">' >> index.html |
| 104 | + echo ' function redirect() {' >> index.html |
| 105 | + echo ' window.location.assign("'${html_url}${def_branch}'/index.html")' >> index.html |
| 106 | + echo ' }' >> index.html |
| 107 | + echo ' </script>' >> index.html |
| 108 | + echo ' </head>' >> index.html |
| 109 | + echo ' <body onload="redirect()">' >> index.html |
| 110 | + echo ' <p>Please follow the link to the <a href="'${html_url}${def_branch}'/index.html">' >> index.html |
| 111 | + echo ${def_branch}'</a> branch documentation.</p>' >> index.html |
| 112 | + echo ' </body>' >> index.html |
| 113 | + echo '</html>' >> index.html |
| 114 | + git add index.html |
75 | 115 | - name: Commit changes to the GitHub Pages branch |
76 | 116 | run: | |
77 | 117 | git status |
|
0 commit comments