Skip to content

Commit 710b0e6

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Port fixes to release scripts to use GITHUB_REF and GITHUB_REF_NAME variables (facebook#45066)
Summary: Pull Request resolved: facebook#45066 This changes ports in main the fixes we had to make to the release scripts to run properly in release mode. This includes the commits: * facebook@375c884 * facebook@609c7c0 * facebook#45062 ## Changelog: [Internal] - Fix release scripts to run properly in release mode Reviewed By: cortinico Differential Revision: D58782925 fbshipit-source-id: b096909d5f8281809ee3c2a01eefda1d19f32936
1 parent 90d4d55 commit 710b0e6

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

scripts/__tests__/npm-utils-test.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ describe('npm-utils', () => {
115115
});
116116

117117
describe('getNpmInfo', () => {
118+
beforeEach(() => {
119+
process.env.CIRCLE_TAG = '';
120+
process.env.GITHUB_REF = '';
121+
process.env.GITHUB_REF_NAME = '';
122+
});
123+
118124
it('return the expected format for prealpha', () => {
119125
const isoStringSpy = jest.spyOn(Date.prototype, 'toISOString');
120126
isoStringSpy.mockReturnValue('2023-10-04T15:43:55.123Z');
@@ -147,7 +153,29 @@ describe('npm-utils', () => {
147153
version: `0.74.1-rc.0`,
148154
tag: '--no-tag',
149155
});
150-
process.env.CIRCLE_TAG = null;
156+
});
157+
158+
it('return the expected format for patch-prereleases on GHA', () => {
159+
const isoStringSpy = jest.spyOn(Date.prototype, 'toISOString');
160+
isoStringSpy.mockReturnValue('2023-10-04T15:43:55.123Z');
161+
getCurrentCommitMock.mockImplementation(() => 'abcd1234');
162+
// exitIfNotOnGit takes a function as a param and it:
163+
// 1. checks if we are on git => if not it exits
164+
// 2. run the function passed as a param and return the output to the caller
165+
// For the mock, we are assuming we are on github and we are returning `false`
166+
// as the `getNpmInfo` function will pass a function that checks if the
167+
// current commit is a tagged with 'latest'.
168+
// In the Mock, we are assuming that we are on git (it does not exits) and the
169+
// checkIfLatest function returns `false`
170+
exitIfNotOnGitMock.mockImplementation(() => false);
171+
172+
process.env.GITHUB_REF = 'refs/tags/v0.74.1-rc.0';
173+
process.env.GITHUB_REF_NAME = 'v0.74.1-rc.0';
174+
const returnedValue = getNpmInfo('release');
175+
expect(returnedValue).toMatchObject({
176+
version: `0.74.1-rc.0`,
177+
tag: '--no-tag',
178+
});
151179
});
152180
});
153181

scripts/npm-utils.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,28 @@ function getNpmInfo(buildType /*: BuildType */) /*: NpmInfo */ {
8989
}
9090

9191
if (buildType === 'release') {
92-
if (process.env.CIRCLE_TAG == null) {
92+
let versionTag /*: string*/ = '';
93+
if (process.env.CIRCLE_TAG != null && process.env.CIRCLE_TAG !== '') {
94+
versionTag = process.env.CIRCLE_TAG;
95+
} else if (
96+
process.env.GITHUB_REF != null &&
97+
process.env.GITHUB_REF.includes('/tags/') &&
98+
process.env.GITHUB_REF_NAME != null &&
99+
process.env.GITHUB_REF_NAME !== ''
100+
) {
101+
// GITHUB_REF contains the fully qualified ref, for example refs/tags/v0.75.0-rc.0
102+
// GITHUB_REF_NAME contains the short name, for example v0.75.0-rc.0
103+
versionTag = process.env.GITHUB_REF_NAME;
104+
}
105+
106+
if (versionTag === '') {
93107
throw new Error(
94-
'CIRCLE_TAG is not set for release. This should only be run in CircleCI. See https://circleci.com/docs/variables/ for how CIRCLE_TAG is set.',
108+
'No version tag found in CI. It looks like this script is running in release mode, but the CIRCLE_TAG or the GITHUB_REF_NAME are missing.',
95109
);
96110
}
97111

98112
const {version, major, minor, patch, prerelease} = parseVersion(
99-
process.env.CIRCLE_TAG,
113+
versionTag,
100114
buildType,
101115
);
102116

0 commit comments

Comments
 (0)