Skip to content

Commit 2b83ea4

Browse files
authored
ci(NODE-5340): properly condition publish step on outcome of build:nightly (#3706)
1 parent b3482f3 commit 2b83ea4

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

.github/scripts/nightly.mjs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ const pkgFilePath = path.join(__dirname, '..', '..', 'package.json');
1212

1313
process.env.TZ = 'Etc/UTC';
1414

15+
async function shouldPublish(publish) {
16+
const githubOutput = process.env.GITHUB_OUTPUT ?? '';
17+
if (githubOutput.length === 0) {
18+
console.log('output file does not exist');
19+
process.exit(1);
20+
}
21+
22+
const outputFile = await fs.open(githubOutput, 'a');
23+
const output = publish ? 'publish=yes' : 'publish=no';
24+
console.log('outputting:', output, 'to', githubOutput);
25+
await outputFile.appendFile(output, { encoding: 'utf8' });
26+
await outputFile.close();
27+
}
28+
1529
/**
1630
* FORMAT : M.M.P-dev.YYYYMMDD.sha.##########
1731
* EXAMPLE: 5.6.0-dev.20230601.sha.0853c6957c
@@ -55,6 +69,7 @@ class NightlyVersion {
5569
console.log('package.json version updated to:', pkg.version);
5670

5771
await fs.writeFile(pkgFilePath, JSON.stringify(pkg, undefined, 2), { encoding: 'utf8' });
72+
console.log('wrote package.json');
5873
}
5974
}
6075

@@ -64,8 +79,12 @@ const currentCommit = await NightlyVersion.currentCommit();
6479
console.log('current commit sha:', currentCommit);
6580

6681
if (currentPublishedNightly.commit === currentCommit) {
67-
console.log('Published nightly is up to date');
68-
process.exit(1);
82+
console.log('Published nightly is up to date, nothing to do');
83+
await shouldPublish(false);
84+
} else {
85+
await NightlyVersion.generateNightlyVersion();
86+
console.log('Published nightly is behind main, updated package.json');
87+
await shouldPublish(true);
6988
}
70-
await NightlyVersion.generateNightlyVersion();
71-
process.exit(0);
89+
90+
console.log('done.');

.github/workflows/release-nightly.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
on:
2-
schedule:
3-
# Timezone is UTC
4-
# https://crontab.guru/#0_0_*_*_*
5-
# At 00:00 every day.
6-
- cron: '0 0 * * *'
7-
workflow_dispatch: {}
2+
# TODO: We can reenable cron when needed
3+
# schedule:
4+
# # Timezone is UTC
5+
# # https://crontab.guru/#0_0_*_*_*
6+
# # At 00:00 every day.
7+
# - cron: '0 0 * * *'
88

9+
# Allows us to manually trigger a nightly
10+
# Since npm prevents duplicate releases we can run this at any time
11+
# As long as the commit hash has changed on main a release will be published
12+
workflow_dispatch: {}
913

1014
name: release-nightly
1115

@@ -16,17 +20,15 @@ jobs:
1620
id-token: write
1721
steps:
1822
- uses: actions/checkout@v3
19-
with:
20-
ref: main
2123
- uses: actions/setup-node@v3
2224
with:
2325
node-version: 'lts/*'
2426
registry-url: 'https://registry.npmjs.org'
2527
- run: npm install -g npm
2628
- run: npm clean-install
27-
- run: npm run build:nightly
28-
continue-on-error: true
29-
- if: ${{ success() }}
30-
run: npm publish --dry-run --provenance --tag=nightly
29+
- id: build_nightly
30+
run: npm run build:nightly
31+
- if: ${{ steps.build_nightly.outputs.publish == 'yes' }}
32+
run: npm publish --provenance --tag=nightly
3133
env:
3234
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)