Skip to content
Merged
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
48 changes: 48 additions & 0 deletions .github/workflows/validate-openapi-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Validate OpenAPI Check Docker

# **What it does**: Tests building and running the OpenAPI check Docker container
# **Why we have it**: To ensure the Dockerfile and openapi-check script work correctly
# **Who does it impact**: Docs engineering.

on:
workflow_dispatch:
pull_request:
paths:
- 'Dockerfile.openapi_decorator'
- 'src/rest/scripts/openapi-check.ts'
- 'src/rest/scripts/utils/get-operations.ts'
- 'src/rest/scripts/utils/operation.ts'
# In case dependencies change
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
# Self-test
- '.github/workflows/validate-openapi-check.yml'

permissions:
contents: read

jobs:
validate-openapi-check:
runs-on: ubuntu-latest
if: github.repository == 'github/docs-internal'
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1

- name: Build Docker image
run: |
docker build -f Dockerfile.openapi_decorator -t openapi-decorator:test .
- name: Test Docker image with sample OpenAPI file
run: |
docker run --rm openapi-decorator:test -f "src/rest/data/fpt-2022-11-28/schema.json"
- name: Test Docker image with multiple OpenAPI files
run: |
docker run --rm openapi-decorator:test \
-f "src/rest/data/fpt-2022-11-28/schema.json" \
"src/rest/data/ghec-2022-11-28/schema.json"
7 changes: 3 additions & 4 deletions Dockerfile.openapi_decorator
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
FROM node:18.15-alpine

RUN apk add --no-cache git python make g++
FROM node:24-alpine

WORKDIR /openapi-check

Expand All @@ -10,10 +8,11 @@ USER node

COPY --chown=node:node package.json /openapi-check
COPY --chown=node:node package-lock.json /openapi-check
COPY --chown=node:node tsconfig.json /openapi-check
ADD --chown=node:node src /openapi-check/src
ADD --chown=node:node content /openapi-check/content
ADD --chown=node:node data /openapi-check/data

RUN npm ci -D

ENTRYPOINT ["node", "/openapi-check/src/rest/scripts/openapi-check.ts"]
ENTRYPOINT ["npx", "tsx", "/openapi-check/src/rest/scripts/openapi-check.ts"]
2 changes: 0 additions & 2 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ export default [
camelcase: 'off', // Many gh apis use underscores, 600+ uses

// Disabled rules to review
'github/no-then': 'off', // 30+
'@typescript-eslint/ban-ts-comment': 'off', // 50+
'no-shadow': 'off', // 150+
'github/array-foreach': 'off', // 250+
'no-console': 'off', // 800+
'@typescript-eslint/no-explicit-any': 'off', // 1000+
Expand Down
10 changes: 5 additions & 5 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ const config: NextConfig = {
}
})
},
webpack: (config) => {
config.experiments = config.experiments || {}
config.experiments.topLevelAwait = true
config.resolve.fallback = { fs: false, async_hooks: false }
return config
webpack: (webpackConfig) => {
webpackConfig.experiments = webpackConfig.experiments || {}
webpackConfig.experiments.topLevelAwait = true
webpackConfig.resolve.fallback = { fs: false, async_hooks: false }
return webpackConfig
},

// https://nextjs.org/docs/api-reference/next.config.js/compression
Expand Down
6 changes: 3 additions & 3 deletions src/assets/middleware/dynamic-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ export default async function dynamicAssets(
const buffer = await image.webp({ effort }).toBuffer()
assetCacheControl(res)
return res.type('image/webp').send(buffer)
} catch (error) {
if (error instanceof Error && (error as any).code !== 'ENOENT') {
throw error
} catch (catchError) {
if (catchError instanceof Error && (catchError as any).code !== 'ENOENT') {
throw catchError
}
}
}
Expand Down
51 changes: 27 additions & 24 deletions src/assets/tests/static-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function getNextStaticAsset(directory: string) {
return path.join(root, files[0])
}

function mockRequest(path: string, { headers }: { headers?: Record<string, string> } = {}) {
function mockRequest(requestPath: string, { headers }: { headers?: Record<string, string> } = {}) {
const _headers = Object.fromEntries(
Object.entries(headers || {}).map(([key, value]) => [key.toLowerCase(), value]),
)
return {
path,
url: path,
path: requestPath,
url: requestPath,
get: (header: string) => {
return _headers[header.toLowerCase()]
},
Expand Down Expand Up @@ -74,8 +74,8 @@ const mockResponse = () => {
if (typeof key === 'string') {
res.headers[key.toLowerCase()] = value
} else {
for (const [k, value] of Object.entries(key)) {
res.headers[k.toLowerCase()] = value
for (const [k, v] of Object.entries(key)) {
res.headers[k.toLowerCase()] = v
}
}
}
Expand Down Expand Up @@ -319,9 +319,9 @@ describe('archived enterprise static assets', () => {
},
])(
'should return $expectStatus for $name',
({ name, path, referrer, expectStatus, shouldCallNext }) => {
({ name, path: testPath, referrer, expectStatus, shouldCallNext }) => {
test(name, async () => {
const req = mockRequest(path, {
const req = mockRequest(testPath, {
headers: {
Referrer: referrer,
},
Expand Down Expand Up @@ -359,22 +359,25 @@ describe('archived enterprise static assets', () => {
expectStatus: undefined,
shouldCallNext: true,
},
])('should not suppress $name', ({ name, path, referrer, expectStatus, shouldCallNext }) => {
test(name, async () => {
const req = mockRequest(path, {
headers: {
Referrer: referrer,
},
])(
'should not suppress $name',
({ name, path: testPath, referrer, expectStatus, shouldCallNext }) => {
test(name, async () => {
const req = mockRequest(testPath, {
headers: {
Referrer: referrer,
},
})
const res = mockResponse()
let nexted = false
const next = () => {
nexted = true
}
setDefaultFastlySurrogateKey(req, res, () => {})
await archivedEnterpriseVersionsAssets(req as any, res as any, next)
expect(nexted).toBe(shouldCallNext)
expect(res.statusCode).toBe(expectStatus)
})
const res = mockResponse()
let nexted = false
const next = () => {
nexted = true
}
setDefaultFastlySurrogateKey(req, res, () => {})
await archivedEnterpriseVersionsAssets(req as any, res as any, next)
expect(nexted).toBe(shouldCallNext)
expect(res.statusCode).toBe(expectStatus)
})
})
},
)
})
4 changes: 2 additions & 2 deletions src/codeql-cli/scripts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ async function setupEnvironment() {

// copy the raw rst files to the temp directory and convert them
// to Markdownusing pandoc
async function rstToMarkdown(sourceDirectory: string) {
const sourceFiles = walk(sourceDirectory, {
async function rstToMarkdown(rstSourceDirectory: string) {
const sourceFiles = walk(rstSourceDirectory, {
includeBasePath: true,
globs: ['**/*.rst'],
})
Expand Down
12 changes: 6 additions & 6 deletions src/content-linter/lib/helpers/get-lintable-yml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export async function getLintableYml(dataFilePath: string): Promise<Record<strin
// back to a file in the data directory.
// The resulting key looks like:
// 'data/variables/product.yml /pat_v1_caps'
function addPathToKey(mdDict: Map<string, string>, dataFilePath: string): Map<string, string> {
const keys = Array.from(mdDict.keys())
function addPathToKey(mdDictMap: Map<string, string>, dataFilePath: string): Map<string, string> {
const keys = Array.from(mdDictMap.keys())
keys.forEach((key) => {
const newKey = `${dataFilePath} ${key}`
const value = mdDict.get(key)
const value = mdDictMap.get(key)
if (value !== undefined) {
mdDict.delete(key)
mdDict.set(newKey, value)
mdDictMap.delete(key)
mdDictMap.set(newKey, value)
}
})
return mdDict
return mdDictMap
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const frontmatterHeroImage: Rule = {

// Check if heroImage is an absolute path
if (!heroImage.startsWith('/')) {
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
const line = params.lines.find((ln: string) => ln.trim().startsWith('heroImage:'))
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
addError(
onError,
Expand All @@ -59,7 +59,7 @@ export const frontmatterHeroImage: Rule = {

// Check if heroImage points to banner-images directory
if (!heroImage.startsWith('/assets/images/banner-images/')) {
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
const line = params.lines.find((ln: string) => ln.trim().startsWith('heroImage:'))
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
addError(
onError,
Expand All @@ -74,7 +74,7 @@ export const frontmatterHeroImage: Rule = {
// Check if the file actually exists
const validHeroImages = getValidHeroImages()
if (validHeroImages.length > 0 && !validHeroImages.includes(heroImage)) {
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
const line = params.lines.find((ln: string) => ln.trim().startsWith('heroImage:'))
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
const availableImages = validHeroImages.join(', ')
addError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const frontmatterIntroLinks: Rule = {
for (const key of Object.keys(introLinks)) {
if (!validKeys.includes(key)) {
// Find the line with this key
const line = params.lines.find((line: string) => {
const trimmed = line.trim()
const line = params.lines.find((ln: string) => {
const trimmed = ln.trim()
return trimmed.startsWith(`${key}:`) && !trimmed.startsWith('introLinks:')
})
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
Expand Down
2 changes: 1 addition & 1 deletion src/content-linter/lib/linting-rules/frontmatter-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const frontmatterSchema: Rule = {
for (const key of deprecatedKeys) {
// Early access articles are allowed to have deprecated properties
if (params.name.includes('early-access')) continue
const line = params.lines.find((line: string) => line.trim().startsWith(key))
const line = params.lines.find((ln: string) => ln.trim().startsWith(key))
const lineNumber = params.lines.indexOf(line!) + 1
addError(
onError,
Expand Down
Loading
Loading