Skip to content

Commit 7e1411a

Browse files
Dont use github app yet, more updates
1 parent d2adef0 commit 7e1411a

File tree

3 files changed

+137
-122
lines changed

3 files changed

+137
-122
lines changed

.github/workflows/changesets-version.yml

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,42 @@ on:
55
branches: [main]
66
workflow_dispatch:
77

8-
permissions:
9-
contents: write # for Git tags and commits
108

119
jobs:
1210
version:
1311
name: Create Version Bump PR
1412
runs-on: ubuntu-latest
15-
if: ${{ github.repository == 'microsoft/fluentui-react-native' }}
1613

14+
# Remove this once we setup react-native-sdk[bot] with this repo
15+
permissions:
16+
contents: write # for GH releases and Git tags (Changesets)
17+
pull-requests: write # version PRs (Changesets)
18+
19+
if: ${{ github.repository == 'microsoft/fluentui-react-native' }}
1720
steps:
1821
- name: Checkout
1922
uses: actions/checkout@v4
20-
with:
21-
fetch-depth: 0
22-
filter: blob:none
23-
24-
- name: Setup Node.js
25-
uses: actions/setup-node@v4
26-
with:
27-
node-version: '22'
28-
cache: 'yarn'
2923

30-
- name: Enable Corepack
31-
run: corepack enable
24+
- name: Set up toolchain
25+
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@5.0.14
3226

3327
- name: Install dependencies
3428
run: |
35-
yarn config set nodeLinker node-modules
3629
yarn install --immutable
3730
3831
- name: Build packages
3932
run: yarn buildci
4033

41-
- name: Generate token for version PR
42-
uses: actions/create-github-app-token@v2
43-
id: app-token
44-
with:
45-
app-id: ${{ vars.APP_ID }}
46-
private-key: ${{ secrets.PRIVATE_KEY }}
47-
permissions: |
48-
contents: write
49-
pull-requests: write
34+
# Bring this back once we setup react-native-sdk[bot] with this repo
35+
# - name: Generate token for version PR
36+
# uses: actions/create-github-app-token@v2
37+
# id: app-token
38+
# with:
39+
# app-id: ${{ vars.APP_ID }}
40+
# private-key: ${{ secrets.PRIVATE_KEY }}
41+
# permissions: |
42+
# contents: write
43+
# pull-requests: write
5044

5145
- name: Create Version Bump PR
5246
id: changesets
@@ -55,27 +49,12 @@ jobs:
5549
version: yarn changeset:version
5650
commit: 'chore(release): version packages'
5751
title: 'chore(release): version packages'
58-
createGithubReleases: false # We handle in Azure Pipelines
52+
createGithubReleases: false
5953
env:
60-
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
54+
# Switch token once we setup react-native-sdk[bot] with this repo
55+
# GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6157

6258
- name: Post-version hook for dependency-profiles
6359
if: steps.changesets.outputs.hasChangesets == 'true'
64-
run: |
65-
if [ -d "packages/libraries/dependency-profiles" ]; then
66-
echo "📦 Updating dependency-profiles"
67-
cd packages/libraries/dependency-profiles
68-
yarn update-profile
69-
cd ../../..
70-
71-
yarn install --mode update-lockfile
72-
73-
if [[ -n $(git status --porcelain) ]]; then
74-
git config user.name "github-actions[bot]"
75-
git config user.email "github-actions[bot]@users.noreply.github.com"
76-
git add .
77-
git commit -m "chore: update dependency-profiles and lockfile"
78-
git push
79-
echo "✅ Committed dependency-profiles updates"
80-
fi
81-
fi
60+
run: node scripts/update-dependency-profiles-postbump.mts

CHANGESETS_SETUP.md

Lines changed: 38 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ This guide explains how to set up the hybrid changesets workflow that uses GitHu
44

55
## Prerequisites
66

7-
- Organization admin access to configure GitHub App
8-
- Repository admin access to add secrets and variables
7+
- Repository admin access to configure GitHub Actions permissions
98
- Azure Pipelines already configured with NPM token
109

1110
## Architecture Overview
@@ -16,81 +15,36 @@ Developer → Changeset (markdown) → PR merged to main
1615
GitHub Actions (@changesets/action)
1716
- changeset version (bump package.json versions)
1817
- Create "Version Packages" PR
19-
- Use GitHub App token (bypasses org PR restrictions)
18+
- Use standard GITHUB_TOKEN with write permissions
2019
- Run dependency-profiles postbump hook
2120
2221
Version PR merged
2322
2423
Azure Pipelines
2524
- Build & test
2625
- changeset publish (to npm)
27-
- Create GitHub releases
28-
- Push git tags
26+
- Create git tags (automatic with changeset publish)
2927
```
3028

31-
## Phase 1: GitHub App Setup (REQUIRED)
29+
## Phase 1: GitHub Actions Permissions
3230

33-
### Step 1: Create or Configure GitHub App
31+
The workflow uses the standard `GITHUB_TOKEN` with elevated permissions to create version bump PRs.
3432

35-
**Option A: Use existing react-native-sdk-bot**
36-
1. Check if `react-native-sdk-bot` exists in your organization
37-
2. Verify it has the required permissions (see below)
38-
3. Install it on `microsoft/fluentui-react-native` repository
33+
### Workflow Permissions
3934

40-
**Option B: Create new GitHub App**
41-
1. Go to GitHub organization settings: https://github.com/organizations/microsoft/settings/apps
42-
2. Click "New GitHub App"
43-
3. Configure:
44-
- **Name**: `fluentui-react-native-release` (or similar unique name)
45-
- **Homepage URL**: `https://github.com/microsoft/fluentui-react-native`
46-
- **Webhook**: Uncheck "Active"
35+
The workflow is configured with the following permissions in [`.github/workflows/changesets-version.yml`](.github/workflows/changesets-version.yml):
4736

48-
4. **Permissions** (Repository permissions):
49-
- Contents: **Read and write**
50-
- Pull requests: **Read and write**
51-
52-
5. **Where can this GitHub App be installed?**: "Only on this account"
53-
54-
6. Click "Create GitHub App"
55-
56-
### Step 2: Install GitHub App on Repository
57-
58-
1. After creating the app, go to "Install App" in the left sidebar
59-
2. Click "Install" next to your organization
60-
3. Select "Only select repositories"
61-
4. Choose `microsoft/fluentui-react-native`
62-
5. Click "Install"
63-
64-
### Step 3: Generate Private Key
65-
66-
1. Go to your GitHub App settings
67-
2. Scroll to "Private keys" section
68-
3. Click "Generate a private key"
69-
4. A `.pem` file will download - **keep this secure!**
70-
71-
### Step 4: Get App ID
72-
73-
1. In GitHub App settings, find the "App ID" near the top
74-
2. It's a numeric value (e.g., `123456`)
75-
3. Copy this number
76-
77-
### Step 5: Add Repository Secrets and Variables
78-
79-
1. Go to repository settings: https://github.com/microsoft/fluentui-react-native/settings/secrets/actions
37+
```yaml
38+
permissions:
39+
contents: write # For creating commits and tags
40+
pull-requests: write # For creating version bump PRs
41+
```
8042
81-
2. Add **Repository Secret** `PRIVATE_KEY`:
82-
- Click "New repository secret"
83-
- Name: `PRIVATE_KEY`
84-
- Value: Paste the entire contents of the `.pem` file (including `-----BEGIN RSA PRIVATE KEY-----` and `-----END RSA PRIVATE KEY-----`)
85-
- Click "Add secret"
43+
**No additional setup required** - GitHub automatically provides the `GITHUB_TOKEN` secret to workflows with these scoped permissions.
8644

87-
3. Go to Variables tab: https://github.com/microsoft/fluentui-react-native/settings/variables/actions
45+
### Note on GitHub Apps (Alternative Approach)
8846

89-
4. Add **Repository Variable** `APP_ID`:
90-
- Click "New repository variable"
91-
- Name: `APP_ID`
92-
- Value: The numeric App ID from Step 4
93-
- Click "Add variable"
47+
If your organization has restrictions that prevent the standard `GITHUB_TOKEN` from creating PRs, you can optionally use a GitHub App token approach (like [rnx-kit does](https://github.com/microsoft/rnx-kit/commit/28e835365bdeed97e50ff8e7e68ea9ad531d3849)). However, this adds complexity and is not needed for this repository.
9448

9549
## Phase 2: Verify Azure Pipelines Configuration
9650

@@ -170,6 +124,22 @@ yarn changeset:status
170124
yarn changeset:status --verbose
171125
```
172126

127+
### Post-Version Hook (dependency-profiles)
128+
129+
After version bumps, the `dependency-profiles` package needs to be updated with the latest versions. This is handled automatically in GitHub Actions.
130+
131+
**What it does:**
132+
- Updates `packages/dependency-profiles` with latest package versions
133+
- Runs `yarn install --mode update-lockfile` to update yarn.lock
134+
- Commits and pushes changes (in CI only)
135+
136+
**Script location:** [`scripts/update-dependency-profiles-postbump.mts`](scripts/update-dependency-profiles-postbump.mts)
137+
138+
To manually run the script locally (for debugging):
139+
```bash
140+
node scripts/update-dependency-profiles-postbump.mts
141+
```
142+
173143
## Phase 4: Testing the Workflow
174144

175145
### Local Testing
@@ -220,28 +190,18 @@ yarn changeset:status --verbose
220190
4. **Verify Azure Pipelines**:
221191
- Check Azure Pipelines run
222192
- Verify packages published to npm
223-
- Check GitHub releases created
224-
- Verify git tags pushed
193+
- Verify git tags created (changesets creates them automatically)
225194

226195
## Troubleshooting
227196

228197
### GitHub Actions Fails with "Resource not accessible by integration"
229198

230-
**Problem**: GitHub App doesn't have correct permissions.
231-
232-
**Solution**:
233-
1. Go to GitHub App settings
234-
2. Verify permissions: Contents (read & write), Pull requests (read & write)
235-
3. If permissions were changed, reinstall the app on the repository
236-
237-
### GitHub Actions Fails with "Bad credentials"
238-
239-
**Problem**: PRIVATE_KEY or APP_ID is incorrect.
199+
**Problem**: The `GITHUB_TOKEN` doesn't have sufficient permissions.
240200

241201
**Solution**:
242-
1. Verify APP_ID matches the number in GitHub App settings
243-
2. Regenerate private key if needed
244-
3. Update repository secret with new key
202+
1. Verify the workflow has `permissions` section with `contents: write` and `pull-requests: write`
203+
2. Check repository settings → Actions → General → Workflow permissions
204+
3. Ensure "Read and write permissions" is selected (not "Read repository contents and packages permissions")
245205

246206
### Azure Pipelines "changeset publish" Fails
247207

@@ -290,8 +250,8 @@ Update any CI/CD rules that reference the old branch name.
290250
## References
291251

292252
- **Changesets docs**: https://github.com/changesets/changesets
293-
- **GitHub App tokens**: https://github.com/actions/create-github-app-token
294-
- **rnx-kit example**: https://github.com/microsoft/rnx-kit/.github/workflows/build.yml
253+
- **GitHub Actions permissions**: https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
254+
- **rnx-kit example** (uses GitHub App approach): https://github.com/microsoft/rnx-kit/.github/workflows/build.yml
295255

296256
## Support
297257

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Post-version hook for dependency-profiles package
4+
*
5+
* This script runs after changesets version bump to update dependency-profiles
6+
* with the latest package versions and commit the changes.
7+
*
8+
* Usage: node scripts/update-dependency-profiles-postbump.mts
9+
*/
10+
11+
import { execSync } from 'child_process';
12+
import { existsSync } from 'fs';
13+
import { resolve } from 'path';
14+
15+
const DEPENDENCY_PROFILES_DIR = 'packages/dependency-profiles';
16+
17+
function execCommand(command: string, cwd?: string): void {
18+
console.log(`> ${command}`);
19+
execSync(command, {
20+
stdio: 'inherit',
21+
cwd: cwd ? resolve(cwd) : undefined
22+
});
23+
}
24+
25+
function hasGitChanges(): boolean {
26+
try {
27+
const output = execSync('git status --porcelain', { encoding: 'utf8' });
28+
return output.trim().length > 0;
29+
} catch (error) {
30+
console.error('Failed to check git status:', error);
31+
return false;
32+
}
33+
}
34+
35+
function main(): void {
36+
console.log('🔍 Checking for dependency-profiles package...');
37+
38+
if (!existsSync(DEPENDENCY_PROFILES_DIR)) {
39+
console.log('⚠️ dependency-profiles directory not found, skipping');
40+
return;
41+
}
42+
43+
console.log('📦 Updating dependency-profiles');
44+
45+
// Run update-profile script
46+
execCommand('yarn update-profile', DEPENDENCY_PROFILES_DIR);
47+
48+
// Update lockfile at root
49+
console.log('🔄 Updating yarn.lock');
50+
execCommand('yarn install --mode update-lockfile');
51+
52+
// Check if there are changes to commit
53+
if (!hasGitChanges()) {
54+
console.log('✅ No changes to commit');
55+
return;
56+
}
57+
58+
console.log('💾 Committing dependency-profiles updates');
59+
60+
// Configure git
61+
execCommand('git config user.name "github-actions[bot]"');
62+
execCommand('git config user.email "github-actions[bot]@users.noreply.github.com"');
63+
64+
// Stage all changes
65+
execCommand('git add .');
66+
67+
// Commit
68+
execCommand('git commit -m "chore: update dependency-profiles and lockfile"');
69+
70+
// Push
71+
execCommand('git push');
72+
73+
console.log('✅ Committed dependency-profiles updates');
74+
}
75+
76+
main();

0 commit comments

Comments
 (0)