Skip to content

ci(NODE-5340): properly condition publish step on outcome of build:nightly #3706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 6, 2023
Merged
27 changes: 23 additions & 4 deletions .github/scripts/nightly.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ const pkgFilePath = path.join(__dirname, '..', '..', 'package.json');

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

async function shouldPublish(publish) {
const githubOutput = process.env.GITHUB_OUTPUT ?? '';
if (githubOutput.length === 0) {
console.log('output file does not exist');
process.exit(1);
}

const outputFile = await fs.open(githubOutput, 'a');
const output = publish ? 'publish=yes' : 'publish=no';
console.log('outputting:', output, 'to', githubOutput);
await outputFile.appendFile(output, { encoding: 'utf8' });
await outputFile.close();
}

/**
* FORMAT : M.M.P-dev.YYYYMMDD.sha.##########
* EXAMPLE: 5.6.0-dev.20230601.sha.0853c6957c
Expand Down Expand Up @@ -55,6 +69,7 @@ class NightlyVersion {
console.log('package.json version updated to:', pkg.version);

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

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

if (currentPublishedNightly.commit === currentCommit) {
console.log('Published nightly is up to date');
process.exit(1);
console.log('Published nightly is up to date, nothing to do');
await shouldPublish(false);
} else {
await NightlyVersion.generateNightlyVersion();
console.log('Published nightly is behind main, updated package.json');
await shouldPublish(true);
}
await NightlyVersion.generateNightlyVersion();
process.exit(0);

console.log('done.');
26 changes: 14 additions & 12 deletions .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
on:
schedule:
# Timezone is UTC
# https://crontab.guru/#0_0_*_*_*
# At 00:00 every day.
- cron: '0 0 * * *'
workflow_dispatch: {}
# TODO: We can reenable cron when needed
# schedule:
# # Timezone is UTC
# # https://crontab.guru/#0_0_*_*_*
# # At 00:00 every day.
# - cron: '0 0 * * *'

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

name: release-nightly

Expand All @@ -16,17 +20,15 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@v3
with:
ref: main
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- run: npm install -g npm
- run: npm clean-install
- run: npm run build:nightly
continue-on-error: true
- if: ${{ success() }}
run: npm publish --dry-run --provenance --tag=nightly
- id: build_nightly
run: npm run build:nightly
- if: ${{ steps.build_nightly.outputs.publish == 'yes' }}
run: npm publish --provenance --tag=nightly
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}