|
| 1 | +# Azure Pipelines Agent Release Scripts |
| 2 | + |
| 3 | +This directory contains the release automation scripts for the Azure Pipelines Agent. These scripts are used in the Azure DevOps release pipelines to automate various aspects of the release process. |
| 4 | + |
| 5 | +## Scripts Overview |
| 6 | + |
| 7 | +| Script | Purpose | Dependencies Used | |
| 8 | +|--------|---------|-------------------| |
| 9 | +| `createReleaseBranch.js` | Creates release branches and generates release notes from PRs | `@octokit/rest`, `@octokit/graphql`, `azure-devops-node-api` | |
| 10 | +| `createAdoPrs.js` | Creates Azure DevOps pull requests for integration files | `azure-devops-node-api`, `azure-pipelines-task-lib` | |
| 11 | +| `fillReleaseNotesTemplate.js` | Fills release notes template with version and hash values | `util.js` (local) | |
| 12 | +| `rollrelease.js` | Manages GitHub releases (marks as non-prerelease) | `@octokit/rest` | |
| 13 | +| `util.js` | Utility functions for file operations and git commands | Node.js built-ins | |
| 14 | + |
| 15 | +## Testing Scripts After Dependency Updates |
| 16 | + |
| 17 | +When updating npm dependencies in `package.json`, follow these steps to ensure all scripts continue working: |
| 18 | + |
| 19 | +### 1. Update Dependencies |
| 20 | + |
| 21 | +```bash |
| 22 | +cd release/ |
| 23 | +npm update |
| 24 | +# or for major version updates: |
| 25 | +npm install package@latest |
| 26 | +npm audit fix --force |
| 27 | +``` |
| 28 | + |
| 29 | +### 2. Test Each Script |
| 30 | + |
| 31 | +#### A. Test `fillReleaseNotesTemplate.js` |
| 32 | + |
| 33 | +```bash |
| 34 | +# Create mock hash files for testing (required - scripts expect these to exist) |
| 35 | +# Note: In production builds, these are generated automatically by the build process |
| 36 | +mkdir -p ../_hashes/hash |
| 37 | +echo "abcd1234567890abcd1234567890abcd1234567890abcd1234567890abcd1234" > ../_hashes/hash/vsts-agent-win-x64-3.999.999.zip.sha256 |
| 38 | +echo "efgh1234567890efgh1234567890efgh1234567890efgh1234567890efgh1234" > ../_hashes/hash/vsts-agent-osx-x64-3.999.999.tar.gz.sha256 |
| 39 | + |
| 40 | +# Test the script |
| 41 | +node fillReleaseNotesTemplate.js 3.999.999 |
| 42 | + |
| 43 | +# Check if releaseNote.md was modified correctly |
| 44 | +git diff ../releaseNote.md |
| 45 | + |
| 46 | +# Restore original file |
| 47 | +git restore ../releaseNote.md |
| 48 | +``` |
| 49 | + |
| 50 | +#### B. Test `rollrelease.js` |
| 51 | + |
| 52 | +```bash |
| 53 | +# Test with dry-run and a real release version (requires GitHub PAT) |
| 54 | +PAT="your_github_pat" node rollrelease.js --dryrun --stage="Ring 5" --ghpat="${PAT}" 3.246.0 |
| 55 | + |
| 56 | +# Expected: Should connect to GitHub and show what it would do without errors |
| 57 | +``` |
| 58 | + |
| 59 | +#### C. Test `createReleaseBranch.js` |
| 60 | + |
| 61 | +```bash |
| 62 | +# Test with dry-run mode (requires GitHub PAT) |
| 63 | +PAT="your_github_pat" node createReleaseBranch.js 4.262.0 --derivedFrom=lastMinorRelease --targetCommitId=$(git rev-parse HEAD) --dryrun |
| 64 | + |
| 65 | +# Expected: Should execute git operations but skip the push step |
| 66 | +# Look for: "Dry run mode: skipping push" message |
| 67 | +``` |
| 68 | + |
| 69 | +#### D. Test `createAdoPrs.js` |
| 70 | + |
| 71 | +```bash |
| 72 | +# Test with dry-run mode (requires Azure DevOps PAT) |
| 73 | +PAT="your_azdo_pat" node createAdoPrs.js --dryrun=true 3.999.999 |
| 74 | + |
| 75 | +# Expected: Should create integration files and show "Dry run: Skipping Azure DevOps API calls" |
| 76 | +# Should NOT show authentication errors (401) |
| 77 | +``` |
| 78 | + |
| 79 | +### 3. Common Issues and Solutions |
| 80 | + |
| 81 | +#### Package Compatibility Issues |
| 82 | + |
| 83 | +**Symptom**: `TypeError: got.get is not a function` or similar method errors |
| 84 | +**Solution**: Check if the package changed its API. Update the code to use the new API. |
| 85 | + |
| 86 | +**Example**: `got` library changed from `got.get()` to `got()` in v12+ |
| 87 | +```javascript |
| 88 | +// Old (v11 and earlier) |
| 89 | +const response = await got.get(url, options); |
| 90 | + |
| 91 | +// New (v12+) |
| 92 | +const response = await got(url, options); |
| 93 | +``` |
| 94 | + |
| 95 | +#### Missing Dependencies |
| 96 | + |
| 97 | +**Symptom**: `Cannot find module 'package-name'` |
| 98 | +**Solution**: Ensure the package is listed in `package.json` and run `npm install` |
| 99 | + |
| 100 | +#### Authentication Issues |
| 101 | + |
| 102 | +**Symptom**: `401 Unauthorized` errors during dry-run |
| 103 | +**Solution**: Ensure API calls are properly wrapped in dry-run checks: |
| 104 | +```javascript |
| 105 | +if (dryrun) { |
| 106 | + console.log('Dry run: Skipping API calls'); |
| 107 | + return mockResponse; |
| 108 | +} |
| 109 | +// Make actual API calls here |
| 110 | +``` |
| 111 | + |
| 112 | +### 4. Required Environment Setup |
| 113 | + |
| 114 | +#### For Testing with Real APIs |
| 115 | + |
| 116 | +1. **GitHub PAT**: Required for `rollrelease.js` and `createReleaseBranch.js` |
| 117 | + - Set `PAT` environment variable |
| 118 | + - Needs `repo` scope permissions |
| 119 | + |
| 120 | +2. **Azure DevOps PAT**: Required for `createAdoPrs.js` |
| 121 | + - Set `PAT` environment variable |
| 122 | + - Needs `Code (read & write)` and `Pull Request (read & write)` permissions |
| 123 | + |
| 124 | +3. **Git Configuration**: Required for all scripts that make commits |
| 125 | + ```bash |
| 126 | + git config --global user.email "[email protected]" |
| 127 | + git config --global user.name "Your Name" |
| 128 | + ``` |
| 129 | + |
| 130 | +#### Mock Data Setup |
| 131 | + |
| 132 | +Some scripts expect certain directories/files to exist: |
| 133 | + |
| 134 | +```bash |
| 135 | +# For hash-related scripts (REQUIRED - scripts will fail without these) |
| 136 | +mkdir -p ../_hashes/hash |
| 137 | +# Create mock hash files for testing as shown in fillReleaseNotesTemplate.js section |
| 138 | + |
| 139 | +# For integration file generation |
| 140 | +mkdir -p ../_layout/integrations |
| 141 | +``` |
| 142 | + |
| 143 | +### 5. Validation Checklist |
| 144 | + |
| 145 | +After testing all scripts, verify: |
| 146 | + |
| 147 | +- [ ] All scripts run without syntax errors |
| 148 | +- [ ] Dry-run modes work correctly (no unintended API calls) |
| 149 | +- [ ] Scripts handle missing files/directories gracefully |
| 150 | +- [ ] Updated packages don't introduce security vulnerabilities (`npm audit`) |
| 151 | +- [ ] Git operations execute properly in dry-run mode |
| 152 | +- [ ] API authentication works with provided PATs |
| 153 | +- [ ] Generated files (integration files, release notes) are correct |
| 154 | + |
| 155 | +### 6. Pipeline Integration |
| 156 | + |
| 157 | +These scripts are used in `.vsts.release.yml`: |
| 158 | + |
| 159 | +- `fillReleaseNotesTemplate.js` - Line ~309 |
| 160 | +- `createAdoPrs.js` - Line ~450 |
| 161 | +- `createReleaseBranch.js` - Line ~200 |
| 162 | + |
| 163 | +After testing locally, verify the pipeline still works by running a test build. |
| 164 | + |
| 165 | +## Troubleshooting |
| 166 | + |
| 167 | +### Common Error Messages |
| 168 | + |
| 169 | +1. **"ENOENT: no such file or directory, scandir"** |
| 170 | + - Missing `_hashes` directory or hash files |
| 171 | + - **For testing**: Create mock hash files as shown above |
| 172 | + - **For production**: Hash files should be generated by the build process - this indicates a build failure |
| 173 | + |
| 174 | +2. **"got.get is not a function"** |
| 175 | + - Package API changed |
| 176 | + - Solution: Update code to use new API |
| 177 | + |
| 178 | +3. **"Failed request: (401)"** |
| 179 | + - Authentication issue or API calls in dry-run |
| 180 | + - Solution: Check PAT and dry-run logic |
| 181 | + |
| 182 | +4. **Node.js version warnings** |
| 183 | + - Using outdated Node.js version |
| 184 | + - Solution: Ensure Node.js 18+ for native fetch support |
| 185 | + |
| 186 | +### Getting Help |
| 187 | + |
| 188 | +- Check the Azure DevOps pipeline logs for real-world usage examples |
| 189 | +- Review git history to see how similar issues were resolved |
| 190 | +- Test with minimal reproduction cases before updating production dependencies |
0 commit comments