Skip to content

Commit

Permalink
repo sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Octomerger authored Oct 15, 2020
2 parents a70fe53 + a7d2a3f commit 9a0b8b6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/browser-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
cancel_others: 'false'
github_token: ${{ github.token }}
paths: '["assets/**", "content/**", "data/**", "includes/**", "javascripts/**", "jest-puppeteer.config.js", "jest.config.js", "layouts/**", "lib/**", "middleware/**", "package-lock.json", "package.json", "server.js", "translations/**", "webpack.config.js"]'
paths: '[".github/workflows/browser-test.yml","assets/**", "content/**", "data/**", "includes/**", "javascripts/**", "jest-puppeteer.config.js", "jest.config.js", "layouts/**", "lib/**", "middleware/**", "package-lock.json", "package.json", "server.js", "translations/**", "webpack.config.js"]'
build:
needs: see_if_should_skip
runs-on: ubuntu-latest
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ name: Crowdin Sync

on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: "33 2 * * *" # every day at 2:33 UTC at least until automerge is working

jobs:
sync_with_crowdin:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
cancel_others: 'false'
github_token: ${{ github.token }}
paths_ignore: '[".all-contributorsrc", ".env.example", ".gitattributes", ".vscode/**", "app.json", "assets/**", "CODE_OF_CONDUCT.md", "CONTRIBUTING.md", "contributing/**", "crowdin-actions-config.yml", "crowdin.yml", "docs", "javascripts/**", "jest-puppeteer.config.js", "LICENSE-CODE", "LICENSE", "nodemon.json", "ownership.yaml", "README.md", "script/**", "stylesheets/**"]'
paths: '[".github/workflows/test.yml",".node-version", ".npmrc", "app.json", "content/**", "data/**","lib/**", "Dockerfile", "feature-flags.json", "Gemfile", "Gemfile.lock", "middleware/**", "node_modules/**","package.json", "package-lock.json", "server.js", "tests/**", "translations/**", "Procfile", "webpack.config.js"]'
lint:
needs: see_if_should_skip
runs-on: ubuntu-latest
Expand Down
34 changes: 32 additions & 2 deletions lib/redirects/precompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ module.exports = async function precompileRedirects (pages) {
const developerRouteWithLanguage = `/en${developerRoute}`
allRedirects[developerRouteWithLanguage] = newPath

// TODO until we update all the old /v3 and /v4 links, we need to support redirects
// from the old /enterprise/<number>/v3 format to the new /enterprise-server@<number/rest format
// AS WELL AS /enterprise-server@<number/v3 to /enterprise-server@<number/rest.
// This is because the new format gets created dynamically even when the links point to /v3 or /v4.
// EXAMPLES:
// /en/enterprise/2.20/v3/pulls/comments -> /en/enterprise-server@2.20/rest/reference/pulls#comments
// /en/enterprise-server@2.20/v3/pulls/comments -> /en/enterprise-server@2.20/rest/reference/pulls#comments
// NOTE: after we update all the /v3 and /v4 links, we can yank the following block
if (developerRoute.includes('/enterprise/')) {
const developerRouteWithNewFormat = developerRoute.replace(/\/enterprise\/(\d.\d\d)\//, '/enterprise-server@$1/')
const developerRouteWithNewFormatWithLanguage = `/en${developerRouteWithNewFormat}`
allRedirects[developerRouteWithNewFormat] = newPath
allRedirects[developerRouteWithNewFormatWithLanguage] = newPath
}
// TODO ENDYANK

// although we only support developer Enterprise paths up to 2.21, we make
// an exception to always redirect versionless paths to the latest version
if (developerRoute.includes('/2.21/')) {
Expand All @@ -58,18 +74,32 @@ module.exports = async function precompileRedirects (pages) {
const developerRouteWithLanguageWithoutVersion = `/en${developerRouteWithoutVersion}`
allRedirects[developerRouteWithoutVersion] = newPathOnLatestVersion
allRedirects[developerRouteWithLanguageWithoutVersion] = newPathOnLatestVersion
// TODO after we update all the /v3 and /v4 links, we can yank the following
const developerRouteWithoutVersionWithNewFormat = developerRouteWithoutVersion
.replace('/enterprise/', 'enterprise-server')
const developerRouteWithoutVersionWithNewFormatWithLanguage = `/en${developerRouteWithoutVersionWithNewFormat}`
allRedirects[developerRouteWithoutVersionWithNewFormat] = newPathOnLatestVersion
allRedirects[developerRouteWithoutVersionWithNewFormatWithLanguage] = newPathOnLatestVersion
// TODO ENDYANK
}

// TODO: TEMPORARILY support explicit 2.22 redirects (created on page render by lib/rewrite-local-links)
// we should eventually yank this block because 2.22 never existed on developer site
// the better solution is to change `/v3` and `/v4` links in content to `/rest` and `/graphql`
// after we update `/v3` and `/v4` links everywhere to `/rest` and `/graphql`, we can
// yank this entire block because 2.22 never existed on developer site
if (developerRoute.includes('/2.21/')) {
const newPath222 = newPath.replace('@2.21/', '@2.22/')
const developerRoute222 = developerRoute.replace('/2.21/', '/2.22/')
const developerRouteWithLanguage222 = `/en${developerRoute222}`
allRedirects[developerRoute222] = newPath222
allRedirects[developerRouteWithLanguage222] = newPath222

const developerRouteWithNewFormat222 = developerRoute222
.replace('/enterprise/2.22/', '/enterprise-server@2.22/')
const developerRouteWithNewFormatWithLanguage222 = `/en${developerRouteWithNewFormat222}`
allRedirects[developerRouteWithNewFormat222] = newPath222
allRedirects[developerRouteWithNewFormatWithLanguage222] = newPath222
}
// TODO ENDYANK

// given a developer route like `/enterprise/2.19/v3/activity`,
// add a veriation like `/enterprise/2.19/user/v3/activity`;
Expand Down
47 changes: 47 additions & 0 deletions tests/routing/developer-site-redirects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { eachOfLimit } = require('async')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const { get } = require('../helpers')
const { getEnterpriseVersionNumber } = require('../../lib/patterns')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
const restRedirectFixtures = require('../fixtures/rest-redirects')
const graphqlRedirectFixtures = require('../fixtures/graphql-redirects')
Expand Down Expand Up @@ -125,6 +126,29 @@ describe('developer redirects', () => {
)
})

// TODO temprarily ensure we redirect old links using the new enterprise format
// for currently supported enterprise releases only
// EXAMPLE: /en/enterprise-server@2.20/v3/pulls/comments -> /en/enterprise-server@2.20/rest/reference/pulls#comments
// We can remove test after we update all the old `/v3` links to point to `/rest`
test('temporary rest reference enterprise redirects', async () => {
await eachOfLimit(
restRedirectFixtures,
MAX_CONCURRENT_REQUESTS,
async (newPath, oldPath) => {
const releaseNumber = oldPath.match(getEnterpriseVersionNumber)
if (!releaseNumber) return
if (!enterpriseServerReleases.supported.includes(releaseNumber[1])) return

oldPath = oldPath
.replace(/\/enterprise\/(\d.\d\d)\//, '/enterprise-server@$1/')
.replace('/user/', '/')
const res = await get(oldPath)
expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
expect(res.headers.location).toBe(newPath)
}
)
})

// this fixtures file includes /v4 and /enterprise/v4 paths
test('graphql reference redirects', async () => {
await eachOfLimit(
Expand All @@ -140,5 +164,28 @@ describe('developer redirects', () => {
}
)
})

// TODO temprarily ensure we redirect old links using the new enterprise format
// for currently supported enterprise releases only
// EXAMPLE: /en/enterprise-server@2.20/v4/interface/actor -> /en/enterprise-server@2.20/graphql/reference/interfaces#actor
// We can remove test after we update all the old `/v4` links to point to `/graphql`
test('temporary rest reference enterprise redirects', async () => {
await eachOfLimit(
graphqlRedirectFixtures,
MAX_CONCURRENT_REQUESTS,
async (newPath, oldPath) => {
const releaseNumber = oldPath.match(getEnterpriseVersionNumber)
if (!releaseNumber) return
if (!enterpriseServerReleases.supported.includes(releaseNumber[1])) return

oldPath = oldPath
.replace(/\/enterprise\/(\d.\d\d)\//, '/enterprise-server@$1/')
.replace('/user/', '/')
const res = await get(oldPath)
expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
expect(res.headers.location).toBe(newPath)
}
)
})
})
})

0 comments on commit 9a0b8b6

Please sign in to comment.