Skip to content

Commit 3000c2e

Browse files
runningcodeclaude
andcommitted
feat(preprod): Parameterize gradle upload component for distribution
Created a reusable GradleConfigBlock component to share gradle upload documentation between size analysis and build distribution. This allows both features to use the same documentation structure while only changing the config block name (sizeAnalysis vs distribution). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 4c5b21f commit 3000c2e

File tree

5 files changed

+145
-53
lines changed

5 files changed

+145
-53
lines changed

docs/platforms/android/build-distribution/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ description: Upload Android builds to Sentry for distribution to internal teams
1717

1818
### Uploading With Gradle
1919

20-
<Include name="size-analysis/upload-gradle" />
20+
<Include name="build-distribution/upload-gradle" />
2121

2222
### Uploading With the Sentry CLI
2323

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
The Gradle plugin automatically detects build metadata from your git repository. On GitHub Actions, all metadata is automatically detected. On other CI systems, you may need to manually set some values using the `vcsInfo` extension.
2+
3+
1. Configure the [Sentry Android Gradle plugin](/platforms/android/configuration/gradle/) with at least version `6.0.0-beta1`
4+
5+
2. Set the auth token as an environment variable to be used when running your release build.
6+
7+
<OrgAuthTokenNote />
8+
9+
```bash
10+
export SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
11+
```
12+
13+
3. Enable uploading for build distribution for CI builds.
14+
15+
<GradleConfigBlock configBlock="distribution" />
16+
17+
4. Invoke the following Gradle tasks to build your app and trigger the upload.
18+
19+
```aab {filename:aab}
20+
./gradlew bundleRelease
21+
```
22+
23+
```apk {filename:apk}
24+
./gradlew assembleRelease
25+
```
26+
27+
5. After an upload has successfully processed, confirm the metadata is correct in the Sentry UI
28+
29+
![Upload metadata =400x](./images/android-metadata.png)
30+
31+
### Overriding Metadata
32+
33+
The Gradle plugin automatically detects build metadata from your git repository. On GitHub Actions, all metadata is automatically detected. On other CI systems, you may need to manually set some values using the `vcsInfo` extension.
34+
35+
Configure overrides in your Gradle build configuration:
36+
37+
<GradleConfigBlock configBlock="distribution" vcsInfo={{
38+
headSha: "abc123",
39+
baseSha: "def456",
40+
vcsProvider: "github",
41+
headRepoName: "organization/repository",
42+
baseRepoName: "organization/repository",
43+
headRef: "feature-branch",
44+
baseRef: "main",
45+
prNumber: 42
46+
}} />
47+
48+
Available `vcsInfo` properties:
49+
50+
| Property | Type | Description |
51+
| -------------- | ------ | --------------------------------- |
52+
| `headSha` | String | Current commit SHA |
53+
| `baseSha` | String | Base commit SHA (for comparison) |
54+
| `vcsProvider` | String | VCS provider (e.g., "github") |
55+
| `headRepoName` | String | Repository name (org/repo format) |
56+
| `baseRepoName` | String | Base repository name |
57+
| `headRef` | String | Branch or tag name |
58+
| `baseRef` | String | Base branch name |
59+
| `prNumber` | Int | Pull request number |

includes/size-analysis/upload-gradle.mdx

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,7 @@ The Gradle plugin automatically detects build metadata from your git repository.
1212

1313
3. Enable uploading for size analysis for CI builds.
1414

15-
```kotlin {filename:build.gradle.kts}
16-
sentry {
17-
sizeAnalysis {
18-
enabled = providers.environmentVariable("GITHUB_ACTIONS").isPresent
19-
}
20-
}
21-
```
22-
23-
```groovy {filename:build.gradle}
24-
sentry {
25-
sizeAnalysis {
26-
enabled = providers.environmentVariable("GITHUB_ACTIONS").present
27-
}
28-
}
29-
```
15+
<GradleConfigBlock configBlock="sizeAnalysis" />
3016

3117
4. Invoke the following Gradle tasks to build your app and trigger the upload.
3218

@@ -48,43 +34,16 @@ The Gradle plugin automatically detects build metadata from your git repository.
4834

4935
Configure overrides in your Gradle build configuration:
5036

51-
```kotlin {filename:build.gradle.kts}
52-
sentry {
53-
sizeAnalysis {
54-
enabled = providers.environmentVariable("GITHUB_ACTIONS").isPresent
55-
}
56-
57-
vcsInfo {
58-
headSha.set("abc123")
59-
baseSha.set("def456")
60-
vcsProvider.set("github")
61-
headRepoName.set("organization/repository")
62-
baseRepoName.set("organization/repository")
63-
headRef.set("feature-branch")
64-
baseRef.set("main")
65-
prNumber.set(42)
66-
}
67-
}
68-
```
69-
70-
```groovy {filename:build.gradle}
71-
sentry {
72-
sizeAnalysis {
73-
enabled = providers.environmentVariable("GITHUB_ACTIONS").present
74-
}
75-
76-
vcsInfo {
77-
headSha = 'abc123'
78-
baseSha = 'def456'
79-
vcsProvider = 'github'
80-
headRepoName = 'organization/repository'
81-
baseRepoName = 'organization/repository'
82-
headRef = 'feature-branch'
83-
baseRef = 'main'
84-
prNumber = 42
85-
}
86-
}
87-
```
37+
<GradleConfigBlock configBlock="sizeAnalysis" vcsInfo={{
38+
headSha: "abc123",
39+
baseSha: "def456",
40+
vcsProvider: "github",
41+
headRepoName: "organization/repository",
42+
baseRepoName: "organization/repository",
43+
headRef: "feature-branch",
44+
baseRef: "main",
45+
prNumber: 42
46+
}} />
8847

8948
Available `vcsInfo` properties:
9049

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {Fragment} from 'react';
2+
3+
import {CodeBlock} from './codeBlock';
4+
import {PlatformSection} from './platformSection';
5+
6+
type VcsInfo = {
7+
baseSha?: string;
8+
baseRef?: string;
9+
baseRepoName?: string;
10+
headRef?: string;
11+
headRepoName?: string;
12+
headSha?: string;
13+
prNumber?: number;
14+
vcsProvider?: string;
15+
};
16+
17+
type Props = {
18+
configBlock?: string;
19+
vcsInfo?: VcsInfo;
20+
};
21+
22+
export function GradleConfigBlock({configBlock = 'sizeAnalysis', vcsInfo}: Props) {
23+
const kotlinVcsInfo = vcsInfo
24+
? `\n\n vcsInfo {
25+
headSha.set("${vcsInfo.headSha}")
26+
baseSha.set("${vcsInfo.baseSha}")
27+
vcsProvider.set("${vcsInfo.vcsProvider}")
28+
headRepoName.set("${vcsInfo.headRepoName}")
29+
baseRepoName.set("${vcsInfo.baseRepoName}")
30+
headRef.set("${vcsInfo.headRef}")
31+
baseRef.set("${vcsInfo.baseRef}")
32+
prNumber.set(${vcsInfo.prNumber})
33+
}`
34+
: '';
35+
36+
const groovyVcsInfo = vcsInfo
37+
? `\n\n vcsInfo {
38+
headSha = '${vcsInfo.headSha}'
39+
baseSha = '${vcsInfo.baseSha}'
40+
vcsProvider = '${vcsInfo.vcsProvider}'
41+
headRepoName = '${vcsInfo.headRepoName}'
42+
baseRepoName = '${vcsInfo.baseRepoName}'
43+
headRef = '${vcsInfo.headRef}'
44+
baseRef = '${vcsInfo.baseRef}'
45+
prNumber = ${vcsInfo.prNumber}
46+
}`
47+
: '';
48+
49+
return (
50+
<Fragment>
51+
<PlatformSection supported={['android.android-gradle-kotlin']}>
52+
<CodeBlock language="kotlin" filename="build.gradle.kts">
53+
{`sentry {
54+
${configBlock} {
55+
enabled = providers.environmentVariable("GITHUB_ACTIONS").isPresent
56+
}${kotlinVcsInfo}
57+
}`}
58+
</CodeBlock>
59+
</PlatformSection>
60+
61+
<PlatformSection supported={['android.android-gradle-groovy']}>
62+
<CodeBlock language="groovy" filename="build.gradle">
63+
{`sentry {
64+
${configBlock} {
65+
enabled = providers.environmentVariable("GITHUB_ACTIONS").present
66+
}${groovyVcsInfo}
67+
}`}
68+
</CodeBlock>
69+
</PlatformSection>
70+
</Fragment>
71+
);
72+
}

src/mdxComponents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {DevDocsCardGrid} from './components/devDocsCardGrid';
1515
import DocImage from './components/docImage';
1616
import {Expandable} from './components/expandable';
1717
import {GitHubDomainChecker} from './components/githubDomainChecker';
18+
import {GradleConfigBlock} from './components/gradleConfigBlock';
1819
import {GuideGrid} from './components/guideGrid';
1920
import {JsBundleList} from './components/jsBundleList';
2021
import {LambdaLayerDetail} from './components/lambdaLayerDetail';
@@ -77,6 +78,7 @@ export function mdxComponents(
7778
TableOfContents,
7879
CreateGitHubAppForm,
7980
GitHubDomainChecker,
81+
GradleConfigBlock,
8082
ConfigValue,
8183
DefinitionList,
8284
Expandable,

0 commit comments

Comments
 (0)