Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions scripts/release-build-plan.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function stateName(file, job, row, legacy = false) {
const platform=path.basename(file,'.yml').replace(/^build-/, '').replace(/-modular$/, '');
const part=value=>encodeURIComponent(String(value)).replace(/-/g,'%2D');
const parts=row.library ? [part(row.library),platform] : [platform];
const standardJobs=['build',`build-${platform}`,`build-${platform}-platforms`, 'build-vs2022-64', 'build-vs2026'];
const standardJobs=['build',`build-${platform}`,`build-${platform}-platforms`, 'build-vs2019-64', 'build-vs2022-64', 'build-vs2026'];
if(!standardJobs.includes(job))parts.push('job',part(job));
// These describe runner setup, not independent output variants. Their values
// still participate in profile/recipe fingerprints inside the record.
Expand Down Expand Up @@ -186,6 +186,16 @@ function channel(file, context) {
(context.payload.pull_request?.base.ref || context.ref.replace('refs/heads/','')) === 'master' ? 'nightly' : 'latest';
}
function publishedStateName(file, job, row, context, legacy = false) {return `${channel(file,context)}-${stateName(file,job,row,legacy)}`;}
// GitHub release asset names cannot contain '%'. Uploads of %2D names land as .2D,
// so replace never finds the previous record and the next upload 422s.
function githubSafeAssetName(name) {return String(name).replace(/%/g,'.');}
function publishedAssetNames(file, job, row, context) {
const names=[publishedStateName(file,job,row,context), publishedStateName(file,job,row,context,true)];
if (job === 'build-vs2019-64' && row && row.bundle != null) {
names.push(`${channel(file,context)}-vs2019-x64-job-build%2Dvs2019%2D64-bundle-${row.bundle}.pkl`);
}
return [...new Set(names.flatMap(name => [name, githubSafeAssetName(name)]))];
}
async function stateRelease(github, context, create = false) {
try {return (await github.rest.repos.getReleaseByTag({...context.repo,tag:'build-state'})).data;}
catch (error) {
Expand Down Expand Up @@ -221,8 +231,8 @@ async function plan({github,context,core,workflow: file,job:jobId}) {
let reason = 'missing or changed published output', wanted, published;
try {
wanted = inputs(file,jobId,row);
const asset = states.find(a => a.name === publishedStateName(file,jobId,row,context)) ||
states.find(a => a.name === publishedStateName(file,jobId,row,context,true));
const aliases = publishedAssetNames(file,jobId,row,context);
const asset = aliases.map(name => states.find(a => a.name === name)).find(Boolean);
if (asset && asset.size < 4*1024*1024) {
try {
const response = await github.rest.repos.getReleaseAsset({...context.repo,asset_id:asset.id,headers:{accept:'application/octet-stream'}});
Expand Down Expand Up @@ -333,16 +343,18 @@ exports.record = async ({github,context,core,workflow:file,job:jobId,matrix:row,
const old = states.find(a => a.name === name);
if (old) await github.rest.repos.deleteReleaseAsset({...context.repo,asset_id:old.id});
await github.rest.repos.uploadReleaseAsset({...context.repo,release_id:metadata.id,name,data,headers:{'content-type':'application/vnd.apple.pkl','content-length':data.length}});
// Retire the old verbose Android name only after the new record is durable.
const legacyName = publishedStateName(file,jobId,row,context,true);
const legacy = legacyName !== name && states.find(a => a.name === legacyName);
if (legacy) {
// Retire previous names only after the new record is durable.
const retired = publishedAssetNames(file,jobId,row,context).filter(alias => alias !== name);
for (const legacyName of retired) {
const legacy = states.find(a => a.name === legacyName);
if (!legacy) continue;
try {await github.rest.repos.deleteReleaseAsset({...context.repo,asset_id:legacy.id});}
catch (error) {core.warning(`Published ${name}, but could not remove ${legacyName}: ${error.message}`);}
}
core.info(`Recorded ${name}: ${Object.keys(state.formulas).length} formulas, ${published.length} verified outputs`);
};
exports.inputs=inputs;exports.matrixRows=matrixRows;exports.matches=matches;exports.stateName=stateName;
exports.githubSafeAssetName=githubSafeAssetName;exports.publishedAssetNames=publishedAssetNames;

exports.groupLibraries=groupLibraries;
exports.normalizePublished=normalizePublished;
17 changes: 17 additions & 0 deletions scripts/tests/test-release-build-plan.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ for (const file of Object.keys(matrices)) {
assert.equal(p.stateName(androidFile,androidJob,{...androidRow,SDK:'38.0.0',NDK:'30',API:'26'}),'android-arch-arm64.pkl','Android toolchain changes retain the friendly asset name');
assert.equal(p.stateName(androidFile,androidJob,androidRow,true),'android-api-25-arch-arm64-ndk-29.0.14206865-sdk-37.0.0.pkl','legacy name remains readable for migration');
assert.equal(new Set(['arm64','armv7','x86','x86_64'].map(ARCH=>p.stateName(androidFile,androidJob,{...androidRow,ARCH}))).size,4);
const vsFile='.github/workflows/build-vs2019-x64.yml', vsJob='build-vs2019-64', vsRow={bundle:1};
assert.equal(p.stateName(vsFile,vsJob,vsRow),'vs2019-x64-bundle-1.pkl');
assert.equal(p.stateName(vsFile,vsJob,{bundle:2}),'vs2019-x64-bundle-2.pkl');
assert.equal(p.githubSafeAssetName('latest-vs2019-x64-job-build%2Dvs2019%2D64-bundle-1.pkl'),'latest-vs2019-x64-job-build.2Dvs2019.2D64-bundle-1.pkl');
const vsAliases=p.publishedAssetNames(vsFile,vsJob,vsRow,{ref:'refs/heads/bleeding',payload:{}});
assert.ok(vsAliases.includes('latest-vs2019-x64-bundle-1.pkl'));
assert.ok(vsAliases.includes('latest-vs2019-x64-job-build.2Dvs2019.2D64-bundle-1.pkl'));
assert.ok(vsAliases.includes('latest-vs2019-x64-job-build%2Dvs2019%2D64-bundle-1.pkl'));

assert.equal(p.matrixRows({include:[{arch:'64'},{arch:'arm64'},{arch:'armv6l'}]}).length,3);
assert.equal(p.matrixRows({arch:['64','arm64'],bundle:[1,2]}).length,4);
Expand Down Expand Up @@ -199,5 +207,14 @@ for (const file of Object.keys(matrices)) {
androidAPI.rest.repos.uploadReleaseAsset=async()=>{throw Error('upload failed');};
await assert.rejects(p.record({github:androidAPI,context,core:recorderCore,workflow:androidFile,job:androidJob,matrix:androidRow}),/upload failed/);
assert.equal(migrationEvents.length,0,'failed publication preserves the legacy record');
write(path.join(process.env.RUNNER_TEMP,'build-plans',p.stateName(vsFile,vsJob,vsRow)),p.renderPkl(androidState));
write('out/openFrameworksLibs_latest_vs_2019_64_1.zip','vs2019 archive');
const vsBytes=fs.readFileSync('out/openFrameworksLibs_latest_vs_2019_64_1.zip');
const vsPublished={id:77,name:'openFrameworksLibs_latest_vs_2019_64_1.zip',size:vsBytes.length,digest:'sha256:'+require('node:crypto').createHash('sha256').update(vsBytes).digest('hex')};
const vsStale={id:88,name:'latest-vs2019-x64-job-build.2Dvs2019.2D64-bundle-1.pkl',size:12};
const vsEvents=[];
const vsAPI={rest:{repos:{getReleaseByTag:async args=>({data:{id:args.tag==='build-state'?20:10}}),listReleaseAssets:'assets',uploadReleaseAsset:async args=>{vsEvents.push(['upload',args.name]);return {data:{}};},deleteReleaseAsset:async args=>vsEvents.push(['delete',args.asset_id])}},paginate:async(_,args)=>args.release_id===20?[vsStale]:[vsPublished]};
await p.record({github:vsAPI,context:{...context,eventName:'push',ref:'refs/heads/bleeding',payload:{},sha:'abc',runId:1},core:recorderCore,workflow:vsFile,job:vsJob,matrix:vsRow});
assert.deepEqual(vsEvents,[['upload','latest-vs2019-x64-bundle-1.pkl'],['delete',88]],'VS2019 records replace GitHub-sanitized %2D asset names');
console.log('Release planning: dependency invalidation, platform isolation, SDK matrices, archive identity, age-independent reuse, tags and API fallback passed');
}finally{process.chdir(root);fs.rmSync(tmp,{recursive:true,force:true});}})().catch(error=>{console.error(error);process.exitCode=1;});
Loading