|
| 1 | +# Copilot Instructions for setup-uv |
| 2 | + |
| 3 | +This document provides essential information for GitHub Copilot coding agents working on the `astral-sh/setup-uv` repository. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +**setup-uv** is a GitHub Action that sets up the [uv](https://docs.astral.sh/uv/) |
| 8 | +Python package installer in GitHub Actions workflows. |
| 9 | +It's a TypeScript-based action that downloads uv binaries, manages caching, handles version resolution, |
| 10 | +and configures the environment for subsequent workflow steps. |
| 11 | + |
| 12 | +### Key Features |
| 13 | + |
| 14 | +- Downloads and installs specific uv versions from GitHub releases |
| 15 | +- Supports version resolution from config files (pyproject.toml, uv.toml, .tool-versions) |
| 16 | +- Implements intelligent caching for both uv cache and Python installations |
| 17 | +- Provides cross-platform support (Linux, macOS, Windows, including ARM architectures) |
| 18 | +- Includes problem matchers for Python error reporting |
| 19 | +- Supports environment activation and custom tool directories |
| 20 | + |
| 21 | +## Repository Structure |
| 22 | + |
| 23 | +**Size**: Small-medium repository (~50 source files, ~400 total files including dependencies) |
| 24 | +**Languages**: TypeScript (primary), JavaScript (compiled output), JSON (configuration) |
| 25 | +**Runtime**: Node.js 24 (GitHub Actions runtime) |
| 26 | +**Key Dependencies**: @actions/core, @actions/cache, @actions/tool-cache, @octokit/core |
| 27 | + |
| 28 | +### Core Architecture |
| 29 | + |
| 30 | +``` |
| 31 | +src/ |
| 32 | +├── setup-uv.ts # Main entry point and orchestration |
| 33 | +├── save-cache.ts # Post-action cache saving logic |
| 34 | +├── update-known-versions.ts # Maintenance script for version updates |
| 35 | +├── cache/ # Cache management functionality |
| 36 | +├── download/ # Version resolution and binary downloading |
| 37 | +├── utils/ # Input parsing, platform detection, configuration |
| 38 | +└── version/ # Version resolution from various file formats |
| 39 | +``` |
| 40 | + |
| 41 | +### Key Files and Locations |
| 42 | + |
| 43 | +- **Action Definition**: `action.yml` - Defines all inputs/outputs and entry points |
| 44 | +- **Main Source**: `src/setup-uv.ts` - Primary action logic |
| 45 | +- **Configuration**: `biome.json` (linting), `tsconfig.json` (TypeScript), `jest.config.js` (testing) |
| 46 | +- **Compiled Output**: `dist/` - Contains compiled Node.js bundles (auto-generated, committed) |
| 47 | +- **Test Fixtures**: `__tests__/fixtures/` - Sample projects for different configuration scenarios |
| 48 | +- **Workflows**: `.github/workflows/test.yml` - Comprehensive CI/CD pipeline |
| 49 | + |
| 50 | +## Build and Development Process |
| 51 | + |
| 52 | +### Prerequisites |
| 53 | + |
| 54 | +- Node.js 24+ (matches GitHub Actions runtime) |
| 55 | +- npm (included with Node.js) |
| 56 | + |
| 57 | +### Essential Commands (ALWAYS run in this order) |
| 58 | + |
| 59 | +#### 1. Install Dependencies |
| 60 | + |
| 61 | +```bash |
| 62 | +npm install |
| 63 | +``` |
| 64 | + |
| 65 | +**Timing**: ~20-30 seconds |
| 66 | +**Note**: Always run this first after cloning or when package.json changes |
| 67 | + |
| 68 | +#### 2. Build TypeScript |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run build |
| 72 | +``` |
| 73 | + |
| 74 | +**Timing**: ~5-10 seconds |
| 75 | +**Purpose**: Compiles TypeScript source to JavaScript in `lib/` directory |
| 76 | + |
| 77 | +#### 3. Lint and Format Code |
| 78 | + |
| 79 | +```bash |
| 80 | +npm run check |
| 81 | +``` |
| 82 | + |
| 83 | +**Timing**: ~2-5 seconds |
| 84 | +**Tool**: Biome (replaces ESLint/Prettier) |
| 85 | +**Auto-fixes**: Formatting, import organization, basic linting issues |
| 86 | + |
| 87 | +#### 4. Package for Distribution |
| 88 | + |
| 89 | +```bash |
| 90 | +npm run package |
| 91 | +``` |
| 92 | + |
| 93 | +**Timing**: ~20-30 seconds |
| 94 | +**Purpose**: Creates bundled distributions in `dist/` using @vercel/ncc |
| 95 | +**Critical**: This step MUST be run before committing - the `dist/` files are used by GitHub Actions |
| 96 | + |
| 97 | +#### 5. Run Tests |
| 98 | + |
| 99 | +```bash |
| 100 | +npm test |
| 101 | +``` |
| 102 | + |
| 103 | +**Timing**: ~10-15 seconds |
| 104 | +**Framework**: Jest with TypeScript support |
| 105 | +**Coverage**: Unit tests for version resolution, input parsing, checksum validation |
| 106 | + |
| 107 | +#### 6. Complete Validation (Recommended) |
| 108 | + |
| 109 | +```bash |
| 110 | +npm run all |
| 111 | +``` |
| 112 | + |
| 113 | +**Timing**: ~60-90 seconds |
| 114 | +**Purpose**: Runs build → check → package → test in sequence |
| 115 | +**Use**: Before making pull requests or when unsure about build state |
| 116 | + |
| 117 | +### Important Build Notes |
| 118 | + |
| 119 | +**CRITICAL**: Always run `npm run package` after making code changes. The `dist/` directory contains the compiled bundles that GitHub Actions actually executes. Forgetting this step will cause your changes to have no effect. |
| 120 | + |
| 121 | +**TypeScript Warnings**: You may see ts-jest warnings about "isolatedModules" - these are harmless and don't affect functionality. |
| 122 | + |
| 123 | +**Biome**: This project uses Biome instead of ESLint/Prettier. Run `npm run check` to fix formatting and linting issues automatically. |
| 124 | + |
| 125 | +## Testing Strategy |
| 126 | + |
| 127 | +### Unit Tests |
| 128 | + |
| 129 | +- **Location**: `__tests__/` directory |
| 130 | +- **Framework**: Jest with ts-jest transformer |
| 131 | +- **Coverage**: Version resolution, input parsing, checksum validation, utility functions |
| 132 | + |
| 133 | +### Integration Tests |
| 134 | + |
| 135 | +- **Location**: `.github/workflows/test.yml` |
| 136 | +- **Scope**: Full end-to-end testing across multiple platforms and scenarios |
| 137 | +- **Key Test Categories**: |
| 138 | + - Version installation (specific, latest, semver ranges) |
| 139 | + - Cache behavior (setup, restore, invalidation) |
| 140 | + - Cross-platform compatibility (Ubuntu, macOS, Windows, ARM) |
| 141 | + - Configuration file parsing (pyproject.toml, uv.toml, requirements.txt) |
| 142 | + - Error handling and edge cases |
| 143 | + |
| 144 | +### Test Fixtures |
| 145 | + |
| 146 | +Located in `__tests__/fixtures/`, these provide sample projects with different configurations: |
| 147 | +- `pyproject-toml-project/` - Standard Python project with uv version specification |
| 148 | +- `uv-toml-project/` - Project using uv.toml configuration |
| 149 | +- `requirements-txt-project/` - Legacy requirements.txt format |
| 150 | +- `cache-dir-defined-project/` - Custom cache directory configuration |
| 151 | + |
| 152 | +## Continuous Integration |
| 153 | + |
| 154 | +### GitHub Workflows |
| 155 | + |
| 156 | +#### Primary Test Suite (`.github/workflows/test.yml`) |
| 157 | + |
| 158 | +- **Triggers**: PRs, pushes to main, manual dispatch |
| 159 | +- **Matrix**: Multiple OS (Ubuntu, macOS, Windows), architecture (x64, ARM), and configuration combinations |
| 160 | +- **Duration**: ~5 minutes for full matrix |
| 161 | +- **Key Validations**: |
| 162 | + - Cross-platform installation and functionality |
| 163 | + - Cache behavior and performance |
| 164 | + - Version resolution from various sources |
| 165 | + - Tool directory configurations |
| 166 | + - Problem matcher functionality |
| 167 | + |
| 168 | +#### Maintenance Workflows |
| 169 | + |
| 170 | +- **CodeQL Analysis**: Security scanning on pushes/PRs |
| 171 | +- **Update Known Versions**: Daily job to sync with latest uv releases |
| 172 | +- **Dependabot**: Automated dependency updates |
| 173 | + |
| 174 | +### Pre-commit Validation |
| 175 | + |
| 176 | +The CI runs these checks that you should run locally: |
| 177 | +1. `npm run all` - Complete build and test suite |
| 178 | +2. ActionLint - GitHub Actions workflow validation |
| 179 | +3. Change detection - Ensures no uncommitted build artifacts |
| 180 | + |
| 181 | +## Key Configuration Files |
| 182 | + |
| 183 | +### Action Configuration (`action.yml`) |
| 184 | + |
| 185 | +Defines 20+ inputs including version specifications, |
| 186 | +cache settings, tool directories, and environment options. |
| 187 | +This file is the authoritative source for understanding available action parameters. |
| 188 | + |
| 189 | +### TypeScript Configuration (`tsconfig.json`) |
| 190 | + |
| 191 | +- Target: ES2024 |
| 192 | +- Module: nodenext (Node.js modules) |
| 193 | +- Strict mode enabled |
| 194 | +- Output directory: `lib/` |
| 195 | + |
| 196 | +### Linting Configuration (`biome.json`) |
| 197 | + |
| 198 | +- Formatter and linter combined |
| 199 | +- Enforces consistent code style |
| 200 | +- Automatically organizes imports and sorts object keys |
| 201 | + |
| 202 | +## Common Development Patterns |
| 203 | + |
| 204 | +### Making Code Changes |
| 205 | + |
| 206 | +1. Edit TypeScript source files in `src/` |
| 207 | +2. Run `npm run build` to compile |
| 208 | +3. Run `npm run check` to format and lint |
| 209 | +4. Run `npm run package` to update distribution bundles |
| 210 | +5. Run `npm test` to verify functionality |
| 211 | +6. Commit all changes including `dist/` files |
| 212 | + |
| 213 | +### Adding New Features |
| 214 | + |
| 215 | +- Follow existing patterns in `src/utils/inputs.ts` for new action inputs |
| 216 | +- Update `action.yml` to declare new inputs/outputs |
| 217 | +- Add corresponding tests in `__tests__/` |
| 218 | +- Add a test in `.github/workflows/test.yml` if it affects integration |
| 219 | +- Update README.md with usage examples |
| 220 | + |
| 221 | +### Cache-Related Changes |
| 222 | + |
| 223 | +- Cache logic is complex and affects performance significantly |
| 224 | +- Test with multiple cache scenarios (hit, miss, invalidation) |
| 225 | +- Consider impact on both GitHub-hosted and self-hosted runners |
| 226 | +- Validate cache key generation and dependency detection |
| 227 | + |
| 228 | +### Version Resolution Changes |
| 229 | + |
| 230 | +- Version resolution supports multiple file formats and precedence rules |
| 231 | +- Test with fixtures in `__tests__/fixtures/` |
| 232 | +- Consider backward compatibility with existing projects |
| 233 | +- Validate semver and PEP 440 specification handling |
| 234 | + |
| 235 | +## Troubleshooting |
| 236 | + |
| 237 | +### Build Failures |
| 238 | + |
| 239 | +- **"Module not found"**: Run `npm install` to ensure dependencies are installed |
| 240 | +- **TypeScript errors**: Check `tsconfig.json` and ensure all imports are valid |
| 241 | +- **Test failures**: Check if test fixtures have been modified or if logic changes broke assumptions |
| 242 | + |
| 243 | +### Action Failures in Workflows |
| 244 | + |
| 245 | +- **Changes not taking effect**: Ensure `npm run package` was run and `dist/` files committed |
| 246 | +- **Version resolution issues**: Check version specification format and file existence |
| 247 | +- **Cache problems**: Verify cache key generation and dependency glob patterns |
| 248 | + |
| 249 | +### Common Gotchas |
| 250 | + |
| 251 | +- **Forgetting to package**: Code changes won't work without running `npm run package` |
| 252 | +- **Platform differences**: Windows paths use backslashes, test cross-platform behavior |
| 253 | +- **Cache invalidation**: Cache keys are sensitive to dependency file changes |
| 254 | +- **Tool directory permissions**: Some platforms require specific directory setups |
| 255 | + |
| 256 | +## Trust These Instructions |
| 257 | + |
| 258 | +These instructions are comprehensive and current. Only search for additional information if: |
| 259 | +- You encounter specific error messages not covered here |
| 260 | +- You need to understand implementation details of specific functions |
| 261 | +- The instructions appear outdated (check repository commit history) |
| 262 | + |
| 263 | +For most development tasks, following the build process and development patterns outlined above will be sufficient. |
0 commit comments