Skip to content

Commit

Permalink
Merge branch 'main' into redirects-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gracepark authored Jun 17, 2021
2 parents 11d0a47 + 50fbcc6 commit 14bc81d
Show file tree
Hide file tree
Showing 23 changed files with 335 additions and 105 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/staging-deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Staging - Deploy PR

# **What it does**: To deploy PRs to a Heroku staging environment.
# **Why we have it**: To deploy with high visibility in case of failures.
# **Who does it impact**: All contributors.

on:
pull_request:
types:
- opened
- reopened
- synchronize
- unlocked

jobs:
deploy:
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 10
concurrency:
group: staging_${{ github.head_ref }}
cancel-in-progress: false
steps:
- name: Check out repo
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
# Enables cloning the Early Access repo later with the relevant PAT
persist-credentials: 'false'

- name: Setup node
uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e
with:
node-version: 16.x

- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Cache node modules
uses: actions/cache@0781355a23dac32fd3bac414512f4b903437991a
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci

- name: Deploy
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
DOCUBOT_REPO_PAT: ${{ secrets.DOCUBOT_REPO_PAT }}
HYDRO_ENDPOINT: ${{ secrets.HYDRO_ENDPOINT }}
HYDRO_SECRET: ${{ secrets.HYDRO_SECRET }}
with:
script: |
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
// Exit if GitHub Actions PAT is not found
if (!GITHUB_TOKEN) {
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
}
// Exit if Heroku API token is not found
if (!HEROKU_API_TOKEN) {
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
}
const getOctokit = require('./script/helpers/github')
const deployToStaging = require('./script/deployment/deploy-to-staging')
// This helper uses the `GITHUB_TOKEN` implicitly!
// We're using our usual version of Octokit vs. the provided `github`
// instance to avoid versioning discrepancies.
const octokit = getOctokit()
try {
await deployToStaging({
herokuToken: HEROKU_API_TOKEN,
octokit,
pullRequest: context.payload.pull_request,
runId: context.runId
})
} catch (error) {
console.error(`Failed to deploy to staging: ${error.message}`)
console.error(error)
throw error
}
88 changes: 88 additions & 0 deletions .github/workflows/staging-undeploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Staging - Undeploy PR

# **What it does**: To undeploy PRs from a Heroku staging environment, i.e. destroy the Heroku App.
# **Why we have it**: To save money spent on deployments for closed PRs.
# **Who does it impact**: All contributors.

on:
pull_request:
types:
- closed
- locked

jobs:
undeploy:
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
name: Undeploy
runs-on: ubuntu-latest
timeout-minutes: 2
concurrency:
group: staging_${{ github.head_ref }}
cancel-in-progress: true
steps:
- name: Check out repo
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
# Enables cloning the Early Access repo later with the relevant PAT
persist-credentials: 'false'

- name: Setup node
uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e
with:
node-version: 16.x

- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Cache node modules
uses: actions/cache@0781355a23dac32fd3bac414512f4b903437991a
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci

- name: Undeploy
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
with:
script: |
const { GITHUB_TOKEN, HEROKU_API_TOKEN } = process.env
// Exit if GitHub Actions PAT is not found
if (!GITHUB_TOKEN) {
throw new Error('You must supply a GITHUB_TOKEN environment variable!')
}
// Exit if Heroku API token is not found
if (!HEROKU_API_TOKEN) {
throw new Error('You must supply a HEROKU_API_TOKEN environment variable!')
}
const getOctokit = require('./script/helpers/github')
const undeployFromStaging = require('./script/deployment/undeploy-from-staging')
// This helper uses the `GITHUB_TOKEN` implicitly!
// We're using our usual version of Octokit vs. the provided `github`
// instance to avoid versioning discrepancies.
const octokit = getOctokit()
try {
await undeployFromStaging({
herokuToken: HEROKU_API_TOKEN,
octokit,
pullRequest: context.payload.pull_request,
runId: context.runId
})
} catch (error) {
console.error(`Failed to undeploy from staging: ${error.message}`)
console.error(error)
throw error
}
2 changes: 1 addition & 1 deletion .github/workflows/workflow-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Run linter
uses: cschleiden/actions-linter@0ff16d6ac5103cca6c92e6cbc922b646baaea5be
with:
workflows: '[".github/workflows/*.yml"]'
workflows: '[".github/workflows/*.yml", "!.github/workflows/staging-deploy-pr.yml", "!.github/workflows/staging-undeploy-pr.yml"]'
5 changes: 3 additions & 2 deletions components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Header = () => {
style={{ zIndex: 2 }}
>
{/* desktop header */}
<div className="d-none d-lg-flex flex-justify-end">
<div className="d-none d-lg-flex flex-justify-end" data-testid="desktop-header">
{showVersionPicker && (
<div className="py-2 mr-4">
<HomepageVersionPicker />
Expand All @@ -54,7 +54,7 @@ export const Header = () => {
</div>

{/* mobile header */}
<div className="d-lg-none">
<div className="d-lg-none" data-testid="mobile-header">
<div className="d-flex flex-justify-between">
<div className="d-flex flex-items-center" id="github-logo-mobile" role="banner">
<Link aria-hidden="true" tabIndex={-1} href={`/${router.locale}`}>
Expand All @@ -71,6 +71,7 @@ export const Header = () => {

<div>
<ButtonOutline
data-testid="mobile-menu-button"
css
onClick={() => setIsMenuOpen(!isMenuOpen)}
aria-label="Navigation Menu"
Expand Down
4 changes: 3 additions & 1 deletion components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from 'components/hooks/useTranslation'
import { sendEvent, EventType } from '../javascripts/events'
import { useMainContext } from './context/MainContext'
import { useVersion } from 'components/hooks/useVersion'
import cx from 'classnames'

type SearchResult = {
url: string
Expand Down Expand Up @@ -193,8 +194,9 @@ export function Search({ isStandalone = false, updateSearchParams = true, childr
<div className="ais-SearchBox">
<form role="search" className="ais-SearchBox-form" noValidate onSubmit={preventRefresh}>
<input
data-testid="site-search-input"
ref={inputRef}
className={'ais-SearchBox-input' + (isStandalone || query ? ' js-open' : '')}
className={cx('ais-SearchBox-input', isStandalone || query ? 'js-open' : '')}
type="search"
placeholder={t`placeholder`}
/* eslint-disable-next-line jsx-a11y/no-autofocus */
Expand Down
1 change: 1 addition & 0 deletions components/SidebarNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const SidebarNav = () => {
width: 280px;
height: 100vh;
flex-shrink: 0;
padding-bottom: 32px;
}
`}
</style>
Expand Down
2 changes: 1 addition & 1 deletion components/context/MainContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const getMainContextFromRequest = (req: any): MainContextT => {
currentProduct: req.context.productMap[req.context.currentProduct] || null,
currentLayoutName: req.context.currentLayoutName,
isHomepageVersion: req.context.currentVersion === 'homepage',
error: req.context.error || '',
error: req.context.error ? req.context.error.toString() : '',
data: {
ui: req.context.site.data.ui,
reusables: {
Expand Down
4 changes: 2 additions & 2 deletions components/context/ProductLandingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const getFeaturedLinksFromReq = (req: any): Record<string, Array<Featured
Object.entries(req.context.featuredLinks || {}).map(([key, entries]) => {
return [
key,
(entries as Array<any> || []).map((entry: any) => ({
((entries as Array<any>) || []).map((entry: any) => ({
href: entry.href,
title: entry.title,
intro: entry.intro,
Expand Down Expand Up @@ -144,7 +144,7 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
? req.context.page.featuredLinks.popularHeading || req.context.site.data.ui.toc[key]
: req.context.site.data.ui.toc[key],
viewAllHref:
key === 'guides' && !req.context.currentCategory && hasGuidesPage
key === 'guides' && !req.context.currentCategory && hasGuidesPage
? `${req.context.currentPath}/guides`
: '',
articles: links.map((link: any) => {
Expand Down
2 changes: 1 addition & 1 deletion components/landing/ArticleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ArticleList = ({
</div>
)}

<ul className="list-style-none">
<ul className="list-style-none" data-testid="article-list">
{articles.map((link) => {
return (
<li key={link.href} className={cx(variant === 'compact' && 'border-top')}>
Expand Down
1 change: 1 addition & 0 deletions components/landing/CodeExampleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const CodeExampleCard = ({ example }: Props) => {
return (
<a
className="Box d-flex flex-column flex-justify-between height-full color-shadow-medium hover-shadow-large no-underline color-text-primary"
data-testid="code-example-card"
href={`https://github.com/${example.href}`}
>
<div className="p-4">
Expand Down
7 changes: 6 additions & 1 deletion components/landing/CodeExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const CodeExamples = () => {
<div>
<div className="pr-lg-3 mb-5 mt-3">
<input
data-testid="code-examples-input"
className="input-lg py-2 px-3 col-12 col-lg-8 form-control"
placeholder={t('search_code_examples')}
type="search"
Expand All @@ -53,6 +54,7 @@ export const CodeExamples = () => {

{numVisible < productCodeExamples.length && !isSearching && (
<button
data-testid="code-examples-show-more"
className="btn btn-outline float-right"
onClick={() => setNumVisible(numVisible + PAGE_SIZE)}
>
Expand All @@ -61,7 +63,10 @@ export const CodeExamples = () => {
)}

{isSearching && searchResults.length === 0 && (
<div className="py-4 text-center color-text-secondary font-mktg">
<div
data-testid="code-examples-no-results"
className="py-4 text-center color-text-secondary font-mktg"
>
<div className="mb-3">
<SearchIcon size={24} />{' '}
</div>
Expand Down
8 changes: 7 additions & 1 deletion components/landing/LandingSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export const LandingSection = ({ title, children, className, sectionLink, descri
<div className={cx('container-xl px-3 px-md-6', className)} id={sectionLink}>
{title && (
<h2 className={cx('font-mktg h1 color-text-primary', !description ? 'mb-3' : 'mb-4')}>
{sectionLink ? <a className="color-unset" href={`#${sectionLink}`}>{title}</a> : title}
{sectionLink ? (
<a className="color-unset" href={`#${sectionLink}`}>
{title}
</a>
) : (
title
)}
</h2>
)}
{description && (
Expand Down
6 changes: 4 additions & 2 deletions components/landing/ProductArticlesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ProductArticlesList = () => {
}

return (
<div className="d-flex gutter flex-wrap">
<div className="d-flex gutter flex-wrap" data-testid="product-articles-list">
{currentProductTree.childPages.map((treeNode, i) => {
if (treeNode.page.documentType === 'article') {
return null
Expand All @@ -34,7 +34,9 @@ const ProductTreeNodeList = ({ treeNode }: { treeNode: ProductTreeNode }) => {
return (
<div className="col-12 col-lg-4 mb-6 height-full">
<h4 className="mb-3">
<Link className="color-unset" href={treeNode.href}>{treeNode.renderedFullTitle}</Link>
<Link className="color-unset" href={treeNode.href}>
{treeNode.renderedFullTitle}
</Link>
</h4>

<ul className="list-style-none">
Expand Down
8 changes: 6 additions & 2 deletions components/landing/ProductLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const ProductLanding = () => {
</LandingSection>

{productCodeExamples.length > 0 && (
<LandingSection title={t('code_examples')} sectionLink="code-examples" className="my-6 pb-6">
<LandingSection
title={t('code_examples')}
sectionLink="code-examples"
className="my-6 pb-6"
>
<CodeExamples />
</LandingSection>
)}
Expand Down Expand Up @@ -68,7 +72,7 @@ export const ProductLanding = () => {
</div>
)}

<LandingSection title={`All ${shortTitle} docs`} sectionLink="all-docs" className="pt-9">
<LandingSection title={`All ${shortTitle} docs`} sectionLink="all-docs" className="pt-9">
<ProductArticlesList />
</LandingSection>
</DefaultLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Alibaba Cloud | Alibaba Cloud Access Key ID and Access Key Secret pair
Amazon Web Services (AWS) | Amazon AWS Access Key ID and Secret Access Key pair
Atlassian | Atlassian API Token
Atlassian | Atlassian JSON Web Token
Azure | Azure Active Directory Application Secret
Azure | Azure DevOps Personal Access Token
Azure | Azure SAS Token
Azure | Azure Service Management Certificate
Expand Down
7 changes: 5 additions & 2 deletions javascripts/scroll-anchoring.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
declare module 'scroll-anchoring' {
export function findAnchorNode(document: Document): Node | undefined
export function preserveAnchorNodePosition<T>(document: Document, callback: () => Promise<T> | T): Promise<T>
export function preservePosition<T>(anchorNode: Node, callback: () => Promise<T> | T): Promise<T>
export function preserveAnchorNodePosition<T>(
document: Document,
callback: () => Promise<T> | T
): Promise<T>
export function preservePosition<T>(anchorNode: Node, callback: () => Promise<T> | T): Promise<T>
}
Loading

0 comments on commit 14bc81d

Please sign in to comment.