Skip to content

Commit 2dd103a

Browse files
authored
Merge pull request #41813 from github/repo-sync
Repo sync
2 parents 373231d + e199a94 commit 2dd103a

File tree

6 files changed

+183
-45
lines changed

6 files changed

+183
-45
lines changed

content/actions/how-tos/manage-runners/larger-runners/use-custom-images.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ product: '{% data variables.actions.github_hosted_larger_runners %} are only ava
88

99
---
1010

11+
{% data reusables.actions.custom-images-public-preview-note %}
12+
1113
## Custom images
1214

1315
You can create a custom image to define the exact environment that your {% data variables.actions.github_hosted_larger_runners %} use. Custom images let you preinstall tools, dependencies, and configurations to speed up workflows and improve consistency across jobs.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> [!NOTE]
2+
> Custom images are in {% data variables.release-phases.public_preview %} and subject to change.

package-lock.json

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"mdast-util-to-hast": "^13.2.1",
214214
"mdast-util-to-markdown": "2.1.2",
215215
"mdast-util-to-string": "^4.0.0",
216-
"next": "^16.0.7",
216+
"next": "^16.0.9",
217217
"ora": "^9.0.0",
218218
"parse5": "7.1.2",
219219
"quick-lru": "7.0.1",

src/assets/README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
11
# Assets
22

3-
Assets are files such as images and CSV data that we serve statically to run the docs.github.com application.
3+
This directory contains the logic for serving, processing, and validating static assets used in the GitHub Docs application. While the actual asset files (images, CSVs, etc.) reside in the root `assets/` directory, `src/assets` houses the code that manages how these assets are delivered to the user.
4+
5+
## Purpose & Scope
6+
7+
The primary responsibilities of this module are:
8+
- **Dynamic Image Processing**: Converting PNGs to WebP on-the-fly and resizing images based on URL parameters.
9+
- **Caching Strategy**: Setting appropriate cache headers and surrogate keys for assets, especially those with checksums in their URLs.
10+
- **Validation & Maintenance**: Scripts to ensure assets are used correctly, identifying orphaned files, and validating image dimensions.
11+
12+
## Architecture
13+
14+
### Middleware
15+
16+
The core logic resides in `src/assets/middleware`:
17+
18+
- **`dynamic-assets.ts`**: Intercepts requests for `/assets/`. It handles:
19+
- **WebP Conversion**: If a request ends in `.webp` but the source is a `.png`, it converts the image using `sharp`.
20+
- **Resizing**: Supports virtual path segments like `/mw-1000/` to resize images to a maximum width (e.g., 1000px).
21+
- **Security**: Validates requested widths against an allowed list (`VALID_MAX_WIDTHS`) to prevent DoS attacks.
22+
- **`static-asset-caching.ts`**: Detects if an asset URL contains a checksum (e.g., `/assets/cb-12345/...`) and sets aggressive caching headers (`Surrogate-Key: manual-purge`) because the content is immutable.
23+
24+
### Scripts
25+
26+
Located in `src/assets/scripts`, these tools help maintain the asset library:
27+
- `find-orphaned-assets.ts`: Identifies assets present in the disk but not referenced in the content or code.
28+
- `validate-asset-images.ts`: Checks for issues like invalid file types or corruption.
29+
- `list-image-sizes.ts`: Utility for analyzing image dimensions.
30+
31+
### Library
32+
33+
- `src/assets/lib/image-density.ts`: Utilities for handling high-density (Retina) images.
34+
35+
## Setup & Usage
36+
37+
### Adding New Assets
38+
39+
Place static files (images, PDFs, etc.) in the root `assets/` directory.
40+
- **Images**: `assets/images`
41+
- **Data**: `assets/` (e.g., CSV files)
42+
43+
### URL Structure
44+
45+
The application (via `src/frame`) often rewrites asset URLs to include a checksum for cache busting.
46+
- **Source**: `/assets/images/foo.png`
47+
- **Served**: `/assets/cb-123456/images/foo.png` (The `cb-xxxxx` part is ignored by the file system lookup but used for caching).
48+
49+
### Dynamic Transformations
50+
51+
To request a WebP version of a PNG:
52+
`GET /assets/images/foo.webp` (Server looks for `foo.png` and converts it).
53+
54+
To request a resized version:
55+
`GET /assets/mw-1000/images/foo.webp` (Resizes to max-width 1000px).
56+
57+
## Dependencies
58+
59+
- **`sharp`**: Used for high-performance image processing (resizing, format conversion).
60+
- **`assets/` directory**: The source of truth for static files.
61+
62+
## Ownership
63+
64+
- **Team**: `@github/docs-engineering`
65+
- **Escalation**: If image serving fails or performance degrades, check the `dynamic-assets` middleware and `sharp` processing.
66+
67+
## Current State & Known Issues
68+
69+
- **On-the-fly Processing**: We currently process images on request (cached by CDN). This avoids a massive build-time step but requires CPU resources on the server for uncached requests.
70+
- **WebP**: We prefer WebP for performance but maintain PNGs as the source of truth.

src/color-schemes/README.md

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
1-
# Color schemes
1+
# Color Schemes
22

3-
Color schemes are user preferences regarding which type of colors they would like the site to use. Currently we support a number of mode, including light, dark, and several accessibility options.
3+
This module manages the application of color themes (light, dark, high contrast, etc.) to the GitHub Docs site. It ensures that the documentation matches the user's preferred color scheme as configured on GitHub.com.
44

5-
We chose the name "schemes" instead of modes or themes because that is what the HTML specification calls them.
5+
## Purpose & Scope
6+
7+
The primary goal is to read the user's color preference from a cookie and apply the correct theme context to the React application. This supports:
8+
- **Modes**: Light, Dark, Auto (system preference).
9+
- **Themes**: Specific variations like "Dark Dimmed" or "Dark High Contrast".
10+
- **Compatibility**: Bridging the gap between raw CSS class names and Primer React component props.
11+
12+
## Architecture
13+
14+
The core logic is contained within `src/color-schemes/components/useTheme.ts`.
15+
16+
### The `color_mode` Cookie
17+
18+
The site relies on a cookie named `color_mode` to determine the user's preference. This cookie is typically set by the main GitHub application and shared with the docs subdomains. The cookie value is a JSON string containing:
19+
- `color_mode`: The overall mode (`light`, `dark`, `auto`).
20+
- `light_theme`: The specific theme to use when in light mode.
21+
- `dark_theme`: The specific theme to use when in dark mode.
22+
23+
### `useTheme` Hook
24+
25+
The `useTheme` hook is the main entry point. It performs the following steps:
26+
1. **Reads the Cookie**: Parses the `color_mode` cookie safely.
27+
2. **Normalizes Data**: Validates the values against supported enums (`SupportedTheme`, `CssColorMode`).
28+
3. **Formats for Consumers**: Returns two distinct theme objects:
29+
- `css`: For applying global CSS classes (uses `light`/`dark`).
30+
- `component`: For passing to Primer React's `ThemeProvider` (uses `day`/`night`).
31+
32+
### Mapping Logic
33+
34+
Primer React uses slightly different terminology than the underlying CSS or the cookie schema. The module handles this translation:
35+
- CSS `light` -> Component `day`
36+
- CSS `dark` -> Component `night`
37+
38+
## Setup & Usage
39+
40+
To access the current theme in a component:
41+
42+
```typescript
43+
import { useTheme } from '@/color-schemes/components/useTheme'
44+
45+
const MyComponent = () => {
46+
const { theme } = useTheme()
47+
48+
// Access CSS-friendly values
49+
console.log(theme.css.colorMode)
50+
51+
// Access Primer-friendly values
52+
console.log(theme.component.dayScheme)
53+
}
54+
```
55+
56+
This hook is primarily used at the root of the application (e.g., in `src/frame/components/Page.tsx` or `_app.tsx`) to wrap the content in a `ThemeProvider`.
57+
58+
## Dependencies
59+
60+
- **`js-cookie`**: Used via `src/frame/components/lib/cookies` to read the browser cookie.
61+
- **Primer React**: The output format is specifically designed to satisfy Primer React's theming requirements.
62+
63+
## Ownership
64+
65+
- **Team**: `@github/docs-engineering`
66+
67+
## Current State & Known Issues
68+
69+
- **Hydration Mismatch / Flash of Unstyled Content**: Since the theme is read from a cookie on the client side (in `useEffect`), there can be a brief moment where the default theme is applied before the user's preference loads.
70+
- **Race Condition Workaround**: There is a `setTimeout` hack in `useTheme.ts` to delay the theme application. This is necessary to prevent Primer React's internal logic from overriding the user's preference with `auto` on initial load.
71+
- *Reference*: [Primer React Issue #2229](https://github.com/primer/react/issues/2229)
72+
- **Future**: The long-term goal is to rely entirely on CSS variables, removing the need for complex JavaScript state management for theming.

0 commit comments

Comments
 (0)