Skip to content

Commit

Permalink
Merge pull request #418 from keymanapp/chore/b17s1-merge-staging-into…
Browse files Browse the repository at this point in the history
…-master

chore: b17s1 merge staging into master
  • Loading branch information
mcdurdin authored Feb 12, 2024
2 parents ab3d0a4 + af1a9b7 commit c99d3aa
Show file tree
Hide file tree
Showing 85 changed files with 2,095 additions and 1,721 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Dockerfile text eol=lf
*.sh eol=lf
117 changes: 24 additions & 93 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,26 @@
name: CI

on: [pull_request]

on:
[pull_request]
jobs:

build-test:
runs-on: windows-latest
runs-on: ubuntu-20.04
env:
KEYMANHOSTS_TIER: TIER_TEST

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3.5.2

- name: Setup PHP 7.4
uses: shivammathur/setup-php@6972aed899fa2dd4016a7e314c46e6902bcafb7b
with:
php-version: '7.4'
extensions: curl, intl, mbstring, openssl
coverage: none
- name: Build the docker image for keyman.com app
shell: bash
run: |
echo "TIER_TEST" > tier.txt
./build.sh build start
env:
fail-fast: true

#
# Configure IIS and setup site for running unit tests
# * Installs IIS, CGI extensions, URLRewrite and configures to connect to PHP
# * Sets up http://127.0.0.1:8888 as host for tests
# * Enables detailed error reporting
#
- name: Download and install IIS and setup a local website
shell: powershell
run: |
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CGI -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DirectoryBrowsing -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors -NoRestart
choco install --no-progress urlrewrite
Import-Module WebAdministration
New-WebAppPool -name "NewWebSiteAppPool" -force
New-WebSite -name "NewWebSite" -PhysicalPath "$ENV:GITHUB_WORKSPACE" -ApplicationPool "NewWebSiteAppPool" -port 8888 -force
Set-WebConfigurationproperty -filter "system.webServer/httpErrors" -pspath "MACHINE/WEBROOT/APPHOST" -name errorMode -value Detailed
Add-WebConfigurationProperty //defaultDocument/files "IIS:\sites\NewWebSite" -AtIndex 0 -Name collection -Value "index.php"
Add-WebConfigurationProperty //defaultDocument/files "IIS:\sites\NewWebSite" -AtIndex 0 -Name collection -Value "index.md"
mkdir c:\tools\php\tmp
Add-Content -path c:\tools\php\php.ini -value '',"error_log = $ENV:GITHUB_WORKSPACE\php_errors.log","session.save_path = $ENV:GITHUB_WORKSPACE\.phpsessions","error_reporting = E_ALL","display_errors = On","display_startup_errors = On","html_errors = Off","sys_temp_dir = c:\tools\php\tmp","upload_tmp_dir = c:\tools\php\tmp"
mkdir $ENV:GITHUB_WORKSPACE\.phpsessions
#
# This step configures FastCGI according to the documentation at https://www.php.net/manual/en/install.windows.manual.php
# This alternative doesn't work: New-WebHandler -name "PHP" -Path *.php -Modules FastCgiModule -ScriptProcessor "c:\tools\php\php-cgi.exe" -Verb 'GET,POST' -Force
#
- name: Setup FastCGI
shell: cmd
run: |
set phpdir=c:\tools
set phppath=php
REM Clear current PHP handlers
%windir%\system32\inetsrv\appcmd clear config /section:system.webServer/fastCGI
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /-[name='PHP_via_FastCGI']
REM Set up the PHP handler
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+[fullPath='%phpdir%\%phppath%\php-cgi.exe']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='%phpdir%\%phppath%\php-cgi.exe',resourceType='Unspecified']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /accessPolicy:Read,Script
REM Configure FastCGI Variables
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi /[fullPath='%phpdir%\%phppath%\php-cgi.exe'].instanceMaxRequests:10000
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phpdir%\%phppath%\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']"
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phpdir%\%phppath%\php-cgi.exe'].environmentVariables.[name='PHPRC',value='%phpdir%\%phppath%\php.ini']"
#
# Install website PHP dependencies
#
- name: Install dependencies
shell: cmd
run: |
echo TIER_TEST > tier.txt
composer install --no-progress
npm install
#
# Finally, run the tests
#
Expand All @@ -99,24 +32,22 @@ jobs:
- name: Check broken links
shell: bash
run: |
( set +e; set +o pipefail; npx broken-link-checker http://localhost:8888 --ordered --recursive --host-requests 50 -e --filter-level 3 | grep -E "BROKEN|Getting links from" | grep -B 1 "BROKEN"; exit ${PIPESTATUS[0]} )
set +e;
set +o pipefail;
npx broken-link-checker http://localhost:8053/_test --ordered --recursive --host-requests 50 -e --filter-level 3 | \
grep -E "BROKEN|Getting links from" | \
grep -B 1 "BROKEN"
exit ${PIPESTATUS[0]}
- name: Check PHP errors
shell: bash
run: |
( set +e; set +o pipefail; [ -f php_errors.log ] && echo 'PHP reported errors or warnings; see log below' && exit 1 || ( echo 'No PHP errors found' && exit 0 ) )
#
# If any of the tests fail, let's grab a bit more detail on the environment
#
- name: Report errors
if: ${{ failure() }}
shell: bash
run: |
echo "--- tier.txt ---"
cat tier.txt
echo "--- PHP Errors ---"
[ -f php_errors.log ] && cat php_errors.log
echo "--- Contents of /keyboards/khmer_angkor ---"
curl http://localhost:8888/keyboards/khmer_angkor
echo "--- PHPInfo ---"
php -r 'phpinfo();'
CONTAINER=`docker container ls -l -q`
if docker container logs $CONTAINER 2>&1 | grep -q 'php7'; then
echo 'PHP reported errors or warnings:'
docker container logs $CONTAINER 2>&1 | grep 'php7'
exit 1
else
echo 'No PHP errors found'
exit 0
fi
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
/.vscode
cdn/deploy/

/vendor/
tier.txt

vendor*
/node_modules/

# Shared files are bootstrapped:
resources/bootstrap.inc.sh
resources/.bootstrap-version
_common/
211 changes: 211 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# This file is used when running with Apache. Adapted from web.config.
# NOTE: this is not very well tested...

# We turn off automatic addition of slashes for directories because it
# interferes with the file extension removal for .php files. At the bottom of
# this file, we have a redirect rule to mimic the same behaviour, _after_ the
# relevant rewrite rules have been applied
DirectorySlash off

RewriteEngine on
RewriteBase /

# Add mime type for apple-app-site-association
AddType application/json apple-app-site-association

# Custom error messages
# ErrorDocument 404 /_includes/errors/404.php

# apple-app-site-association
RewriteRule "^.well-known/apple-app-site-association$" "/.well-known/apple-app-site-association.json" [L]

# macosx and macos to mac (ignore case)
RedirectMatch 301 "^(?i)/(macosx|macos)\b(.*)$" "/mac$2"

# Redirect deprecated Google Plus link
RedirectMatch 301 "^(?i)/plus.*" "/"

# /donate -> donate.keyman.com
RedirectMatch 301 "^(?i)/donate(\/.*)?" "https://donate.keyman.com"

# /privacy -> SIL Privacy policy
RedirectMatch 301 "^(?i)/privacy(\/.*)?" "https://software.sil.org/language-software-privacy-policy/"

# desktop to windows
RedirectMatch 301 "^(?i)/desktop(\/.*)?" "/windows$1"

# releases-tier/download
# note: the tier is currently ignored
RewriteRule "^downloads/releases/(alpha|beta|stable)/(.+)$" "/downloads/releases/_version_downloads.php?tier=$1&version=$2" [R,END]

# releases-download
RewriteRule "^downloads/releases/(?!_version_downloads\b)(.+)$" "/downloads/releases/_version_downloads.php?version=$1" [R,END]

# index
RewriteRule "^downloads/releases(\/)?$" "/downloads" [R,END]

# Ready
RewriteRule "^_control/ready$" "_control/ready.php" [END]

#
# Keyboard landing pages (TODO)
#

# Cleanup various URLS with permanent redirects

# /keyboards/{install|download|share}/{id}/ to /keyboards/x/id
# Remove final /
RewriteRule "^keyboards/(install|download|share)/([^/]+)/$" "/keyboards/$1/$2" [R=301,END,QSA]

# /keyboards/{id}/ to /keyboards/id
# Remove final /
RewriteRule "^keyboards/([^/]+)/$" "/keyboards/$1" [R=301,END,QSA]

# /keyboards/ to /keyboards (Handled by other redirect)
# Remove final /

# Old share url /keyboards/{id}/share[/] to /keyboards/share/id
RewriteRule "^keyboards/(.*)/share(/?)$" "/keyboards/share/$1" [R=301]

# /keyboard/{content} to /keyboards/...
RewriteRule "^keyboard(/.*)$" "/keyboards$1" [R,END]

#
# Install | Download | Share | bare | .json -->
#

# /keyboards/install/[id] to /keyboards/install.php
RewriteRule "^keyboards/install/([^/]+)$" "/keyboards/install.php?id=$1" [END,QSA]

# /keyboards/download/[id] to /keyboards/keyboard.php
# This formerly redirected to a download, but we no longer need it; keep it for
# legacy links
RewriteRule "^keyboards/download/([^/]+)$" "/keyboards/keyboard.php?id=$1" [END,QSA]

# /keyboards/share/[id] to /keyboards/share.php
# if the keyboard exists in the repo, then share.php will redirect to /keyboards/<id>
RewriteRule "^keyboards/share/([^/]+)$" "/keyboards/share.php?id=$1" [END]

# /keyboards/{id}.json to /keyboards/keyboard.json.php
RewriteRule "^keyboards/(?!keyboard.json)(.*)\.json$" "/keyboards/keyboard.json.php?id=$1" [END]

# /keyboards/{id} to /keyboards/keyboard.php
RewriteRule "^keyboards/(?!index\.php|install|keyboard|session|share)([^/]+)$" "/keyboards/keyboard.php?id=$1" [END,QSA]


#
# Search
#

# /keyboards?q=... to /keyboards/index.php
# RewriteRule "^keyboards$" "/keyboards/index.php" [L]

# /keyboards/languages to /keyboards/index.php
RewriteRule "^keyboards/languages/(.*)" "/keyboards/index.php?q=l:id:$1" [END]

# /keyboards/download to /keyboards/download.php
RewriteRule "^keyboards/download(.php)?" "/keyboards/download.php" [END,QSA]

# /keyboards/legacy to /keyboards/keyboard.php
RewriteRule "^keyboards/legacy/(.*)" "/keyboards/keyboard.php?legacy=$1" [END]

# /keyboards/countries to /keyboards/index.php
RewriteRule "^keyboards/countries/(.*)" "/keyboards/index.php?q=c:id:$1" [END]

# Synonym paths

# 10.0 to 15.0
# /1X.0 to /1X landing page
RedirectMatch "^/1([0-5])(\.0)\/?" "/1$1/"

# ios
RedirectMatch "^/(?!iphone-and-ipad)(ios|iphone|ipad)(\/.*)?" "/iphone-and-ipad$2"

# Connect With Art landing page
RedirectMatch "/connectwithart(\/|$)" "https://sites.google.com/sil.org/connectwithart/home"

# per-language landing pages
RedirectMatch "^/albanian(/?)$" "/keyboards/basic_kbdal"
RedirectMatch "^/ancient-egyptian(/?)$" "/keyboards/hieroglyphic"
RedirectMatch "^/ancient-hebrew(/?)$" "/keyboards/galaxie_greek_hebrew_mnemonic"
RedirectMatch "^/arabic(/?)$" "/keyboards/basic_kbda1"
RedirectMatch "^/assamese(/?)$" "/keyboards/isis_bangla"
RedirectMatch "^/basic_kbdsn1(/?)$" "/keyboards/basic_kbdsn1"
RedirectMatch "^/bengali(/?)$" "/keyboards/basic_kbdinbe2"
RedirectMatch "^/cherokee(/?)$" "/keyboards/cherokee6"
RedirectMatch "^/cheyenne(/?)$" "/keyboards/sil_cheyenne"
RedirectMatch "^/dinka(/?)$" "/keyboards/el_dinka"
RedirectMatch "^/dutch(/?)$" "/keyboards/basic_kbdne"
RedirectMatch "^/farsi(/?)$" "/keyboards/farsi_unicode"
RedirectMatch "^/hebrew(/?)$" "/keyboards/basic_kbdheb"
RedirectMatch "^/hindi(/?)$" "/keyboards/basic_kbdindev"
RedirectMatch "^/igbo(/?)$" "/keyboards/sil_nigeria_dot"
RedirectMatch "^/khmer(/?)$" "/keyboards/khmer_angkor"
RedirectMatch "^/lao(/?)$" "/keyboards/basic_kbdlao"
RedirectMatch "^/malayalam(/?)$" "/keyboards/basic_kbdinmal"
RedirectMatch "^/maltese(/?)$" "/keyboards/maltese"
RedirectMatch "^/marathi(/?)$" "/keyboards/basic_kbdinmar"
RedirectMatch "^/mongolian(/?)$" "/keyboards/basic_kbdmon"
RedirectMatch "^/nepali(/?)$" "/keyboards/basic_kbdnepr"
RedirectMatch "^/oriya(/?)$" "/keyboards/basic_kbdinori"
RedirectMatch "^/rawang(/?)$" "/keyboards/rawang"
RedirectMatch "^/russian(/?)$" "/keyboards/basic_kbdru"
RedirectMatch "^/serbian(/?)$" "/keyboards/basic_kbdycc"
RedirectMatch "^/sindhi(/?)$" "/keyboards/mbsindhi"
RedirectMatch "^/thai(/?)$" "/keyboards/thai-uni"
RedirectMatch "^/yiddish(/?)$" "/keyboards/yiddish_pasekh"
RedirectMatch "^/yoruba(/?)$" "/keyboards/sil_yoruba8"

RedirectMatch "^/ancient-greek(/?)$" "/keyboards/h/greek"
RedirectMatch "^/(french|german|italian|spanish|swedish)(/?)$" "/keyboards/h/eurolatin"

# dedicated-keyboard-landing pages
RedirectMatch 301 "^/(amharic|burmese|cameroon|ethiopic|eurolatin|greek|ipa|sinhala|tamil|tibetan|tigrigna|urdu)(/.*)?$" "/keyboards/h/$1$2"

#
# PHP and Markdown rewriting
#

# Remove index or index.php and redirect (and stop processing)
RewriteCond "$1" -d
RewriteRule "^((.+)/)?index(\.php)?$" "$1" [R,L]

# Remove .php extension and redirect
RewriteCond "$1.php" -f
RewriteCond "$1" !-d
RewriteRule "^(.+)\.php$" "$1" [R,L]

# Redirect folder without / to include /
RewriteCond "{DOCUMENT_ROOT}/$1" -d
RewriteCond "{DOCUMENT_ROOT}/$1.php" !-f
RewriteCond "{DOCUMENT_ROOT}/$1.md" !-f
RewriteRule "^(.+[^/])$" "$1/" [R,END]

#
# PHP rewriting
#

# TODO: mdhost currently in a different path than help.keyman

# Rewrite file to file.md
RewriteCond "%{DOCUMENT_ROOT}/$1.md" -f
RewriteRule "^(.+)$" "/_includes/includes/md/mdhost.php?file=$1.md" [END]

# Rewrite file to file.php
RewriteCond "%{DOCUMENT_ROOT}/$1.php" -f
RewriteCond "%{DOCUMENT_ROOT}/$1.md" !-f
RewriteRule "^(.+)$" "$1.php" [END]

# Rewrite folder/ to folder/index.md
RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" -f
RewriteRule "^(.+)/$" "/_includes/includes/md/mdhost.php?file=$1/index.md" [END]

# Rewrite folder/ to folder/index.php
RewriteCond "%{DOCUMENT_ROOT}/$1/index.php" -f
RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" !-f
RewriteRule "^(.+)/$" "$1/index.php" [END]

# Finally, append the terminating slash for folders, given it is no longer
# done automatically because we put DirectorySlash off
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule "^(.*)([^/])$" "$1$2/" [R]
25 changes: 0 additions & 25 deletions .well-known/web.config

This file was deleted.

Loading

0 comments on commit c99d3aa

Please sign in to comment.