Skip to content

Commit

Permalink
[0.68] Fix binary versioning and add CommitId to version (#11321)
Browse files Browse the repository at this point in the history
* Update version logic to fix n-1 bug in version on binaries (#11275)

* Update Sign phase to do prepare-js-env instead of only yarn install (#11292)

* Add commitid to product version of binaries (#11316)

* Add commitid to product version of binaries

* Change files

* Undo the validation logic of the extra argument

* Change files
  • Loading branch information
dannyvv committed Mar 1, 2023
1 parent 74a47a1 commit 93b20e1
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ jobs:
steps:
- template: templates/checkout-shallow.yml

- template: templates/yarn-install.yml
- template: templates/prepare-js-env.yml

- template: templates/apply-published-version-vars.yml

Expand Down
11 changes: 11 additions & 0 deletions .ado/templates/apply-published-version-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ steps:
displayName: Apply version variables
inputs:
script: node $(Build.StagingDirectory)/versionEnvVars/versionEnvVars.js

# During the official publish (in publish.yml) The stamp-version script that updates the value
# runs during beachball. But this stayed on the machine that ran the Setup phase and doesn't make
# it to the machines that run the actual buld. This script does run on those machines
# and the previous step sets the environment/pipeline variables to the right version
# So we'll rerun the stamp-version script on each machine that builds native code so that the
# binaries are stamped with the right version.
- task: CmdLine@2
displayName: Update PackageVersion.g.props
inputs:
script: yarn stamp-version $(RNW_PKG_VERSION_STR)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add commitid to product version of binaries (#11316)",
"packageName": "react-native-windows",
"email": "dannyvv@microsoft.com",
"dependentChangeType": "patch"
}
2 changes: 2 additions & 0 deletions packages/@rnw-scripts/stamp-version/src/renderPropsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import semver from 'semver';
*/
export default async function renderPropsFile(
version: string,
commitId: string,
): Promise<string> {
const templatePath = path.join(
__dirname,
Expand All @@ -30,5 +31,6 @@ export default async function renderPropsFile(
minor: semver.minor(version),
patch: semver.patch(version),
canary: semver.prerelease(version)?.[0] === 'canary',
commitId: commitId,
});
}
6 changes: 5 additions & 1 deletion packages/@rnw-scripts/stamp-version/src/stampVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const {argv} = yargs
* Rewrites PackageVersion.g.props
*/
async function setPackageVersionProps(version: string) {
const propsStr = await renderPropsFile(version);
const commitId =
process.env.BUILD_SOURCEVERSION ?? // Azure DevOps Pipelines
process.env.GITHUB_SHA ?? // GitHub Actions
'developer-build';
const propsStr = await renderPropsFile(version, commitId);

const rnwPackage = await findRepoPackage('react-native-windows');
const propsPath = path.join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`0.0.0-canary.100 1`] = `
<ReactNativeWindowsMinor>0</ReactNativeWindowsMinor>
<ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
<ReactNativeWindowsCanary>true</ReactNativeWindowsCanary>
<ReactNativeWindowsCommitId>abc123</ReactNativeWindowsCommitId>
</PropertyGroup>
</Project>"
`;
Expand All @@ -40,6 +41,7 @@ exports[`0.66.5 1`] = `
<ReactNativeWindowsMinor>66</ReactNativeWindowsMinor>
<ReactNativeWindowsPatch>5</ReactNativeWindowsPatch>
<ReactNativeWindowsCanary>false</ReactNativeWindowsCanary>
<ReactNativeWindowsCommitId>123abc</ReactNativeWindowsCommitId>
</PropertyGroup>
</Project>"
`;
Expand All @@ -62,6 +64,7 @@ exports[`0.67.0-preview.1 1`] = `
<ReactNativeWindowsMinor>67</ReactNativeWindowsMinor>
<ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
<ReactNativeWindowsCanary>false</ReactNativeWindowsCanary>
<ReactNativeWindowsCommitId>def456</ReactNativeWindowsCommitId>
</PropertyGroup>
</Project>"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import renderPropsFile from '../renderPropsFile';

test('0.0.0-canary.100', async () => {
expect(await renderPropsFile('0.0.0-canary.100')).toMatchSnapshot();
expect(await renderPropsFile('0.0.0-canary.100', 'abc123')).toMatchSnapshot();
});

test('0.67.0-preview.1', async () => {
expect(await renderPropsFile('0.67.0-preview.1')).toMatchSnapshot();
expect(await renderPropsFile('0.67.0-preview.1', 'def456')).toMatchSnapshot();
});

test('0.66.5', async () => {
expect(await renderPropsFile('0.66.5')).toMatchSnapshot();
expect(await renderPropsFile('0.66.5', '123abc')).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<ReactNativeWindowsMinor>{{minor}}</ReactNativeWindowsMinor>
<ReactNativeWindowsPatch>{{patch}}</ReactNativeWindowsPatch>
<ReactNativeWindowsCanary>{{canary}}</ReactNativeWindowsCanary>
<ReactNativeWindowsCommitId>{{commitId}}</ReactNativeWindowsCommitId>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions vnext/Desktop.DLL/React.Windows.Desktop.DLL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
RNW_MAJOR=$(ReactNativeWindowsMajor);
RNW_MINOR=$(ReactNativeWindowsMinor);
RNW_PATCH=$(ReactNativeWindowsPatch);
RNW_COMMITID=$(ReactNativeWindowsCommitId);
_UNICODE;
UNICODE;
%(PreprocessorDefinitions)
Expand Down
7 changes: 5 additions & 2 deletions vnext/Desktop.DLL/Version.rc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
#define VER_FILEVERSION_STR XSTRINGIZE(RNW_VERSION)
#define VER_FILEVERSION RNW_MAJOR,RNW_MINOR,RNW_PATCH,RNW_PKG_VERSION_BUILD

#define VER_PRODUCTVERSION_STR XSTRINGIZE(RNW_VERSION+RNW_COMMITID)
#define VER_PRODUCTVERSION RNW_MAJOR,RNW_MINOR,RNW_PATCH,RNW_PKG_VERSION_BUILD

#ifndef DEBUG
#define VER_DEBUG 0
#else
#define VER_DEBUG VS_FF_DEBUG
#endif

VS_VERSION_INFO VERSIONINFO FILEVERSION VER_FILEVERSION PRODUCTVERSION
VS_VERSION_INFO VERSIONINFO FILEVERSION VER_PRODUCTVERSION PRODUCTVERSION
VER_FILEVERSION FILEFLAGSMASK(VS_FF_DEBUG) FILEFLAGS(VER_DEBUG) FILEOS
VOS__WINDOWS32 FILETYPE VFT_DLL FILESUBTYPE VFT2_UNKNOWN BEGIN BLOCK
"StringFileInfo" BEGIN BLOCK "040904E4" BEGIN VALUE "CompanyName",
Expand All @@ -27,7 +30,7 @@ VS_VERSION_INFO VERSIONINFO FILEVERSION VER_FILEVERSION PRODUCTVERSION
"(c) Microsoft Corporation. All rights reserved." VALUE "OriginalFilename",
"react-native-win32.dll" VALUE "ProductName",
"React-Native-Windows" VALUE "ProductVersion",
VER_FILEVERSION_STR END END
VER_PRODUCTVERSION_STR END END

BLOCK "VarFileInfo" BEGIN
/* The following line should only be modified for localized versions. */
Expand Down
1 change: 1 addition & 0 deletions vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@
RNW_MAJOR=$(ReactNativeWindowsMajor);
RNW_MINOR=$(ReactNativeWindowsMinor);
RNW_PATCH=$(ReactNativeWindowsPatch);
RNW_COMMITID=$(ReactNativeWindowsCommitId);
_UNICODE;
UNICODE;
%(PreprocessorDefinitions)
Expand Down
8 changes: 6 additions & 2 deletions vnext/Microsoft.ReactNative/Version.rc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#define VER_FILEVERSION_STR XSTRINGIZE(RNW_VERSION)
#define VER_FILEVERSION RNW_MAJOR,RNW_MINOR,RNW_PATCH,RNW_PKG_VERSION_BUILD

#define VER_PRODUCTVERSION_STR XSTRINGIZE(RNW_VERSION+RNW_COMMITID)
#define VER_PRODUCTVERSION RNW_MAJOR,RNW_MINOR,RNW_PATCH,RNW_PKG_VERSION_BUILD


#ifndef DEBUG
#define VER_DEBUG 0
#else
Expand All @@ -18,7 +22,7 @@

VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK (VS_FF_DEBUG)
FILEFLAGS(VER_DEBUG)
FILEOS VOS__WINDOWS32
Expand All @@ -36,7 +40,7 @@ VALUE "InternalName", "Microsoft.ReactNative.dll"
VALUE "LegalCopyright", "(c) Microsoft Corporation. All rights reserved."
VALUE "OriginalFilename", "Microsoft.ReactNative.dll"
VALUE "ProductName", "React-Native-Windows"
VALUE "ProductVersion", VER_FILEVERSION_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END

Expand Down
1 change: 1 addition & 0 deletions vnext/PropertySheets/Generated/PackageVersion.g.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<ReactNativeWindowsMinor>68</ReactNativeWindowsMinor>
<ReactNativeWindowsPatch>28</ReactNativeWindowsPatch>
<ReactNativeWindowsCanary>false</ReactNativeWindowsCanary>
<ReactNativeWindowsCommitId>273ca05330afdcf737326660e8c7e14d4dda0bd4</ReactNativeWindowsCommitId>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions vnext/PropertySheets/PackageVersionDefinitions.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
RNW_MAJOR=$(ReactNativeWindowsMajor);
RNW_MINOR=$(ReactNativeWindowsMinor);
RNW_PATCH=$(ReactNativeWindowsPatch);
RNW_COMMITID=$(ReactNativeWindowsCommitId);
%(PreprocessorDefinitions)
</PreprocessorDefinitions>

Expand All @@ -31,6 +32,7 @@
RNW_MAJOR=$(ReactNativeWindowsMajor);
RNW_MINOR=$(ReactNativeWindowsMinor);
RNW_PATCH=$(ReactNativeWindowsPatch);
RNW_COMMITID=$(ReactNativeWindowsCommitId);
%(PreprocessorDefinitions)
</PreprocessorDefinitions>

Expand Down

0 comments on commit 93b20e1

Please sign in to comment.