From a954a55011e0de227141d6261c0f3865248c21e0 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Tue, 22 Oct 2024 08:41:00 +0200 Subject: [PATCH] Release tools: mark v43.0.0 as latest on GitHub after publishing a new release. --- package.json | 1 + scripts/publishpackages.js | 43 +++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index c855e5c18..424efcce6 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@ckeditor/ckeditor5-dev-bump-year": "^44.2.1", "@inquirer/prompts": "^6.0.0", "@listr2/prompt-adapter-inquirer": "^2.0.16", + "@octokit/rest": "^21.0.0", "eslint": "^8.21.0", "eslint-config-ckeditor5": "^8.0.0", "fs-extra": "^11.0.0", diff --git a/scripts/publishpackages.js b/scripts/publishpackages.js index dc3af8af9..c4d2af3be 100644 --- a/scripts/publishpackages.js +++ b/scripts/publishpackages.js @@ -10,6 +10,7 @@ import { Listr } from 'listr2'; import { ListrInquirerPromptAdapter } from '@listr2/prompt-adapter-inquirer'; import { confirm } from '@inquirer/prompts'; +import { Octokit } from '@octokit/rest'; import * as releaseTools from '@ckeditor/ckeditor5-dev-release-tools'; import parseArguments from './utils/parsearguments.js'; import getListrOptions from './utils/getlistroptions.js'; @@ -19,7 +20,7 @@ const cliArguments = parseArguments( process.argv.slice( 2 ) ); const latestVersion = releaseTools.getLastFromChangelog(); const versionChangelog = releaseTools.getChangesForVersion( latestVersion ); -let githubToken; +const githubToken = await getGitHubToken(); if ( !cliArguments.npmTag ) { cliArguments.npmTag = releaseTools.getNpmTagFromVersion( latestVersion ); @@ -68,21 +69,39 @@ const tasks = new Listr( [ options: { persistentOutput: true } - } -], getListrOptions( cliArguments ) ); + }, + { + title: 'Mark v43.0.0 as "latest" (GitHub)', + task: async () => { + const github = new Octokit( { + version: '3.0.0', + auth: `token ${ githubToken }` + } ); -( async () => { - try { - if ( process.env.CKE5_RELEASE_TOKEN ) { - githubToken = process.env.CKE5_RELEASE_TOKEN; - } else { - githubToken = await releaseTools.provideToken(); + return github.request( 'PATCH /repos/{owner}/{repo}/releases/{release_id}', { + owner: 'ckeditor', + repo: 'ckeditor5-dev', + release_id: 174058828, // v43.0.0 + make_latest: true + } ); } + } +], getListrOptions( cliArguments ) ); - await tasks.run(); - } catch ( err ) { +tasks.run() + .catch( err => { process.exitCode = 1; console.error( err ); + } ); + +/** + * @returns {Promise.} + */ +async function getGitHubToken() { + if ( process.env.CKE5_RELEASE_TOKEN ) { + return process.env.CKE5_RELEASE_TOKEN; } -} )(); + + return releaseTools.provideToken(); +}