microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.45k stars 132 forks source link

[CI] Set and use `CIRCLE_TAG` in Azure pipelines publish job #2021

Closed Saadnajmi closed 8 months ago

Saadnajmi commented 8 months ago

Summary:

The "Javascript PR" CI checks were failing, because the jest tests would call an RNM-only JS function getPkgJsonVersion, which used some NodeJS built in modules like path and fs. Apparently, such modules need to be mocked out in jest. Rather than write the appropriate mocks (and further our diffs from upstream), let's instead retactor away the use of that extra JS function.

Upstream, the CircleCI publish job is triggered by a new tag getting pushed to the React Native repo. The tag would set the environment variable CIRCLE_TAG, and run the steps and scripts needed to publish a new React Native NPM package. The script publish-npm.js would reference this environment variable to find out the version to publish. In React Native macOS, because nothing set CIRCLE_TAG, we instead calculated the next version ourselves, wrote it to the package.json, and read it via the getPkgJsonVersion. This was done around https://github.com/microsoft/react-native-macos/pull/1777 timeframe.

Since we want to get rid of getPkgJsonVersion, and we already calculate the next version we want in our CI, let's just set that version to an environment variable in the CI job, and then pass that as the CIRCLE_TAG environment variable to the publish-npm.js. This is a trick we've done earlier, we also pass CIRCLE_BRANCH to prepare-package-for-release.js.

Test Plan:

The PR checks NPM Publish Dry Run and Javascript PR (Which tests publish-npm.js should both succeed, for this PR and the equivalent PR in 0.73-stable: #2022