Skip to content

Commit c97d9d7

Browse files
Merge branch 'main' into feat-44725-followups
2 parents c24ff8a + a202ac3 commit c97d9d7

File tree

166 files changed

+2228
-1405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+2228
-1405
lines changed
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
name: 'Bump npm version'
2-
description: 'Increase the application version (JS and native), based on git tags'
1+
name: Bump npm version
2+
description: Increase the application version (JS and native), based on git tags
33
inputs:
4-
GITHUB_TOKEN:
5-
description: Auth token for New Expensify Github
6-
required: true
74
SEMVER_LEVEL:
85
description: Semantic Versioning Level
96
required: true
107
outputs:
118
NEW_VERSION:
129
description: The new semver version of the application, updated in the JS and native layers.
1310
runs:
14-
using: 'node20'
15-
main: './index.js'
11+
using: node20
12+
main: ./index.js
Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,26 @@
11
import * as core from '@actions/core';
2-
import {exec as originalExec} from 'child_process';
3-
import fs from 'fs';
4-
import type {PackageJson} from 'type-fest';
5-
import {promisify} from 'util';
6-
import {generateAndroidVersionCode, updateAndroidVersion, updateiOSVersion} from '@github/libs/nativeVersionUpdater';
2+
import bumpVersion from '@scripts/bumpVersion';
73
import * as versionUpdater from '@github/libs/versionUpdater';
8-
import type {SemverLevel} from '@github/libs/versionUpdater';
94

10-
const exec = promisify(originalExec);
11-
12-
/**
13-
* Update the native app versions.
14-
*/
15-
function updateNativeVersions(version: string) {
16-
console.log(`Updating native versions to ${version}`);
17-
18-
// Update Android
19-
const androidVersionCode = generateAndroidVersionCode(version);
20-
updateAndroidVersion(version, androidVersionCode)
21-
.then(() => {
22-
console.log('Successfully updated Android!');
23-
})
24-
.catch((err: string | Error) => {
25-
console.error('Error updating Android');
26-
core.setFailed(err);
27-
});
28-
29-
// Update iOS
5+
async function run() {
306
try {
31-
const cfBundleVersion = updateiOSVersion(version);
32-
if (typeof cfBundleVersion === 'string' && cfBundleVersion.split('.').length === 4) {
33-
core.setOutput('NEW_IOS_VERSION', cfBundleVersion);
34-
console.log('Successfully updated iOS!');
35-
} else {
36-
core.setFailed(`Failed to set NEW_IOS_VERSION. CFBundleVersion: ${cfBundleVersion}`);
7+
const semverLevel = core.getInput('SEMVER_LEVEL', {required: true});
8+
if (!versionUpdater.isValidSemverLevel(semverLevel)) {
9+
throw new Error(`Invalid SEMVER_LEVEL ${semverLevel}`);
3710
}
38-
} catch (err) {
39-
console.error('Error updating iOS');
40-
if (err instanceof Error) {
41-
core.setFailed(err);
11+
const newVersion = await bumpVersion(semverLevel);
12+
core.setOutput('NEW_VERSION', newVersion);
13+
} catch (e) {
14+
if (e instanceof Error) {
15+
core.setFailed(e);
16+
return;
4217
}
18+
core.setFailed('An unknown error occurred.');
4319
}
4420
}
4521

46-
let semanticVersionLevel = core.getInput('SEMVER_LEVEL', {required: true});
47-
if (!semanticVersionLevel || !versionUpdater.isValidSemverLevel(semanticVersionLevel)) {
48-
semanticVersionLevel = versionUpdater.SEMANTIC_VERSION_LEVELS.BUILD;
49-
console.log(`Invalid input for 'SEMVER_LEVEL': ${semanticVersionLevel}`, `Defaulting to: ${semanticVersionLevel}`);
22+
if (require.main === module) {
23+
run();
5024
}
5125

52-
const {version: previousVersion} = JSON.parse(fs.readFileSync('./package.json').toString()) as PackageJson;
53-
if (!previousVersion) {
54-
core.setFailed('Error: Could not read package.json');
55-
}
56-
57-
const newVersion = versionUpdater.incrementVersion(previousVersion ?? '', semanticVersionLevel as SemverLevel);
58-
console.log(`Previous version: ${previousVersion}`, `New version: ${newVersion}`);
59-
60-
updateNativeVersions(newVersion);
61-
62-
console.log(`Setting npm version to ${newVersion}`);
63-
exec(`npm --no-git-tag-version version ${newVersion} -m "Update version to ${newVersion}"`)
64-
.then(({stdout}) => {
65-
// NPM and native versions successfully updated, output new version
66-
console.log(stdout);
67-
core.setOutput('NEW_VERSION', newVersion);
68-
})
69-
.catch(({stdout, stderr}) => {
70-
// Log errors and retry
71-
console.log(stdout);
72-
console.error(stderr);
73-
core.setFailed('An error occurred in the `npm version` command');
74-
});
26+
export default run;

0 commit comments

Comments
 (0)