Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add older versions to gh pages deploy #1697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
name: Deploy docs from master commit to gh pages
name: Deploy docs to gh-pages
on:
push:
branches:
- master
- v8_maintenance
- v9_maintenance
workflow_dispatch:
jobs:
deploy-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci && npm run bootstrap
# Conditional build depending on branch
- name: Set build directory based on branch
id: set-build-dir
run: |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then
echo "::set-output name=build_dir::./packages/__docs__/__build__"
echo "::set-output name=deploy_dir::./"
elif [ "${{ github.ref }}" == "refs/heads/v8_maintenance" ]; then
echo "::set-output name=build_dir::./packages/__docs__/__build__"
echo "::set-output name=deploy_dir::v8"
elif [ "${{ github.ref }}" == "refs/heads/v9_maintenance" ]; then
echo "::set-output name=build_dir::./packages/__docs__/__build__"
echo "::set-output name=deploy_dir::v9"
fi
- name: Build docs-app
run: npm run build:docs
- uses: JamesIves/github-pages-deploy-action@v4
- name: Copy redirects config file to the __build__ directory.
run: cp ./packages/__docs__/_redirects_gh_pages ./packages/__docs__/__build__
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./packages/__docs__/__build__
folder: ${{ steps.set-build-dir.outputs.build_dir }}
branch: gh-pages
target-folder: ${{ steps.set-build-dir.outputs.deploy_dir }}
clean-exclude: pr-preview
force: false
4 changes: 4 additions & 0 deletions packages/__docs__/_redirects_gh_pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/v6/* https://instructure.github.io/instructure-ui/v6:splat 200
/v7/* https://instructure.github.io/instructure-ui/v7:splat 200
/v8/* https://instructure.github.io/instructure-ui/v8:splat 200
/v9/* https://instructure.github.io/instructure-ui/v9:splat 200
7 changes: 5 additions & 2 deletions packages/__docs__/src/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@
// If we select the latest version from the dropdown,
// then navigate to the index (instructure.design/#currentHash).
// In every other case eg.: v6,v7 navigate to --> instructure.design/v6/#currentHash
const rootToAdd = window.location.origin.includes('github.io')

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
github.io
' can be anywhere in the URL, and arbitrary hosts may come before or after it.

Copilot Autofix AI 9 days ago

To fix the problem, we need to replace the substring check with a more secure method of validating the host of the URL. We will use the URL constructor to parse the URL and then check the host directly. This ensures that the check is performed on the correct part of the URL and cannot be bypassed by embedding the allowed host in an unexpected location.

  1. Parse the URL using the URL constructor.
  2. Check the hostname property of the parsed URL to determine if it matches github.io.
Suggested changeset 1
packages/__docs__/src/Header/index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/__docs__/src/Header/index.tsx b/packages/__docs__/src/Header/index.tsx
--- a/packages/__docs__/src/Header/index.tsx
+++ b/packages/__docs__/src/Header/index.tsx
@@ -71,3 +71,4 @@
     // In every other case eg.: v6,v7 navigate to --> instructure.design/v6/#currentHash
-    const rootToAdd = window.location.origin.includes('github.io')
+    const url = new URL(window.location.href);
+    const rootToAdd = url.hostname === 'github.io'
       ? '/instructure-ui'
EOF
@@ -71,3 +71,4 @@
// In every other case eg.: v6,v7 navigate to --> instructure.design/v6/#currentHash
const rootToAdd = window.location.origin.includes('github.io')
const url = new URL(window.location.href);
const rootToAdd = url.hostname === 'github.io'
? '/instructure-ui'
Copilot is powered by AI and may make mistakes. Always verify output.
? '/instructure-ui'
: ''
const versionToNavigate = isSelectedLatestVersion
? `/${window.location.hash}`
: `/${selectedVersion}/${window.location.hash}`
? `${rootToAdd}/${window.location.hash}`
: `${rootToAdd}/${selectedVersion}/${window.location.hash}`

return window.location.replace(versionToNavigate)
}
Expand Down
15 changes: 8 additions & 7 deletions packages/__docs__/src/versionData.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
const isLocalHost = window.location.hostname === 'localhost'

if (!isLocalHost) {
const result = await fetch(`${window.location.origin}/versions.json`, {
signal
})
const versionsData = await result.json()

return versionsData
let input = window.location.hostname.includes('github.io')

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
github.io
' can be anywhere in the URL, and arbitrary hosts may come before or after it.
? `${window.location.origin}/instructure-ui/versions.json`
: `${window.location.origin}/versions.json`
const result = await fetch(input, { signal })
return await result.json()
}

return null
Expand All @@ -51,7 +50,9 @@
* if we are on the docs page of a legacy version,
* the path includes the version number, e.g. `/v7` or `/v8`
*/
const [versionInPath] = window.location.pathname.split('/').filter(Boolean)
const lastSegment =
window.location.pathname.split('/').filter(Boolean).pop() || ''
const versionInPath = /v\d$/.test(lastSegment) ? lastSegment : undefined

export default fetchVersionData
export { fetchVersionData, versionInPath }
Loading