Skip to content

Commit d07a8a7

Browse files
committed
Move the container registry reference out of code.
1 parent 5493fa1 commit d07a8a7

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

Gruntfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,11 +1468,15 @@ module.exports = function(grunt) {
14681468
} );
14691469

14701470
// Gutenberg integration tasks.
1471-
grunt.registerTask( 'gutenberg-download', 'Downloads the Gutenberg build artifact.', function() {
1471+
grunt.registerTask( 'gutenberg-download', 'Downloads the built Gutenberg artifact.', function() {
14721472
const done = this.async();
1473+
const args = [ 'tools/gutenberg/download-gutenberg.js' ];
1474+
if ( grunt.option( 'force' ) ) {
1475+
args.push( '--force' );
1476+
}
14731477
grunt.util.spawn( {
14741478
cmd: 'node',
1475-
args: [ 'tools/gutenberg/download-gutenberg.js' ],
1479+
args,
14761480
opts: { stdio: 'inherit' }
14771481
}, function( error ) {
14781482
done( ! error );

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"url": "https://develop.svn.wordpress.org/trunk"
88
},
99
"gutenberg": {
10-
"sha": "e0c5fc81de25a4f837c063ca2c2db32d74698a49"
10+
"sha": "e0c5fc81de25a4f837c063ca2c2db32d74698a49",
11+
"ghcrRepo": "Gdesrosj/gutenberg/gutenberg-build"
1112
},
1213
"engines": {
1314
"node": ">=20.10.0",

tools/gutenberg/download-gutenberg.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* The artifact is identified by the "gutenberg.sha" value in the root
1010
* package.json, which is used as the OCI image tag for the gutenberg-build
11-
* package on GHCR.
11+
* package on GitHub Container Registry.
1212
*
1313
* @package WordPress
1414
*/
@@ -22,9 +22,6 @@ const rootDir = path.resolve( __dirname, '../..' );
2222
const gutenbergDir = path.join( rootDir, 'gutenberg' );
2323
const packageJsonPath = path.join( rootDir, 'package.json' );
2424

25-
// GHCR configuration
26-
const GHCR_REPO = 'desrosj/gutenberg/gutenberg-build';
27-
2825
/**
2926
* Execute a command, streaming stdio directly so progress is visible.
3027
*
@@ -68,23 +65,31 @@ function exec( command, args, options = {} ) {
6865

6966
/**
7067
* Main execution function.
68+
*
69+
* @param {boolean} force - Whether to force a fresh download even if the gutenberg directory exists.
7170
*/
72-
async function main() {
71+
async function main( force ) {
7372
console.log( '🔍 Checking Gutenberg configuration...' );
7473

75-
// Read Gutenberg SHA from package.json.
76-
let sha;
74+
// Read Gutenberg configuration from package.json.
75+
let sha, ghcrRepo;
7776
try {
7877
const packageJson = JSON.parse(
7978
fs.readFileSync( packageJsonPath, 'utf8' )
8079
);
8180
sha = packageJson.gutenberg?.sha;
81+
ghcrRepo = packageJson.gutenberg?.ghcrRepo;
8282

8383
if ( ! sha ) {
8484
throw new Error( 'Missing "gutenberg.sha" in package.json' );
8585
}
8686

87+
if ( ! ghcrRepo ) {
88+
throw new Error( 'Missing "gutenberg.ghcrRepo" in package.json' );
89+
}
90+
8791
console.log( ` SHA: ${ sha }` );
92+
console.log( ` GHCR repository: ${ ghcrRepo }` );
8893
} catch ( error ) {
8994
console.error( '❌ Error reading package.json:', error.message );
9095
process.exit( 1 );
@@ -100,7 +105,7 @@ async function main() {
100105
const tokenJson = await exec( 'curl', [
101106
'--silent',
102107
'--fail',
103-
`https://ghcr.io/token?scope=repository:${ GHCR_REPO }:pull&service=ghcr.io`,
108+
`https://ghcr.io/token?scope=repository:${ ghcrRepo }:pull&service=ghcr.io`,
104109
], { captureOutput: true } );
105110
token = JSON.parse( tokenJson ).token;
106111
if ( ! token ) {
@@ -121,7 +126,7 @@ async function main() {
121126
'--fail',
122127
'--header', `Authorization: Bearer ${ token }`,
123128
'--header', 'Accept: application/vnd.oci.image.manifest.v1+json',
124-
`https://ghcr.io/v2/${ GHCR_REPO }/manifests/${ sha }`,
129+
`https://ghcr.io/v2/${ ghcrRepo }/manifests/${ sha }`,
125130
], { captureOutput: true } );
126131
const manifest = JSON.parse( manifestJson );
127132
digest = manifest?.layers?.[ 0 ]?.digest;
@@ -142,7 +147,7 @@ async function main() {
142147
'--location',
143148
'--header', `Authorization: Bearer ${ token }`,
144149
'--output', zipPath,
145-
`https://ghcr.io/v2/${ GHCR_REPO }/blobs/${ digest }`,
150+
`https://ghcr.io/v2/${ ghcrRepo }/blobs/${ digest }`,
146151
] );
147152
console.log( '✅ Download complete' );
148153
} catch ( error ) {

0 commit comments

Comments
 (0)