|
1 | 1 | #!/usr/bin/env node |
2 | | -// Resolves the app version for EAS builds and prints it to stdout. |
| 2 | +// Resolves the app version for EAS builds, writes it into |
| 3 | +// apps/polycentric/package.json, and prints it to stdout. |
3 | 4 | // |
4 | 5 | // * On a SemVer release tag (e.g. v2.0.0-alpha.1) -> that version |
5 | 6 | // (2.0.0-alpha.1). |
6 | 7 | // * Otherwise -> the latest GitLab release version with the patch bumped |
7 | 8 | // (e.g. latest 2.0.0 -> 2.0.1), so develop/MR builds sit one patch ahead |
8 | 9 | // of the last release. |
9 | 10 | // |
| 11 | +// The version is baked into package.json (not just exported as APP_VERSION) |
| 12 | +// because EAS evaluates app.config.ts on a remote build worker that does not |
| 13 | +// receive the CI runner's environment variables. app.config.ts reads the |
| 14 | +// version from package.json, which travels with the project upload. |
| 15 | +// |
10 | 16 | // Reads CI_COMMIT_TAG, CI_API_V4_URL, CI_PROJECT_ID and CI_JOB_TOKEN. |
11 | 17 |
|
| 18 | +const fs = require('fs'); |
| 19 | +const path = require('path'); |
| 20 | + |
| 21 | +const PKG_PATH = path.join( |
| 22 | + __dirname, |
| 23 | + '..', |
| 24 | + '..', |
| 25 | + 'apps', |
| 26 | + 'polycentric', |
| 27 | + 'package.json', |
| 28 | +); |
| 29 | + |
| 30 | +const apply = (version) => { |
| 31 | + const pkg = JSON.parse(fs.readFileSync(PKG_PATH, 'utf8')); |
| 32 | + pkg.version = version; |
| 33 | + fs.writeFileSync(PKG_PATH, `${JSON.stringify(pkg, null, 2)}\n`); |
| 34 | + process.stdout.write(version); |
| 35 | +}; |
| 36 | + |
12 | 37 | const tag = process.env.CI_COMMIT_TAG || ''; |
13 | 38 | const tagMatch = tag.match(/^v(\d+\.\d+\.\d+.*)$/); |
14 | 39 |
|
15 | 40 | if (tagMatch) { |
16 | | - process.stdout.write(tagMatch[1]); |
| 41 | + apply(tagMatch[1]); |
17 | 42 | } else { |
18 | 43 | const api = process.env.CI_API_V4_URL; |
19 | 44 | const projectId = process.env.CI_PROJECT_ID; |
@@ -41,6 +66,6 @@ if (tagMatch) { |
41 | 66 | } catch { |
42 | 67 | // Fall back to the default below. |
43 | 68 | } |
44 | | - process.stdout.write(bumpPatch(latest)); |
| 69 | + apply(bumpPatch(latest)); |
45 | 70 | })(); |
46 | 71 | } |
0 commit comments