Skip to content

Commit 1bba531

Browse files
Copilotneilime
andcommitted
fix(release): use fs instead of glob for tarball matching, fix artifact download path
Co-authored-by: neilime <[email protected]>
1 parent 56b60f9 commit 1bba531

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

.github/workflows/release.yml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ jobs:
282282
if: inputs.build-artifact-id != ''
283283
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
284284
with:
285-
artifact-ids: ${{ inputs.build-artifact-id }}
286-
path: /
285+
name: ${{ inputs.build-artifact-id }}
286+
path: ${{ github.workspace }}
287287

288288
- id: package-info
289289
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
@@ -389,7 +389,6 @@ jobs:
389389
script: |
390390
const fs = require('node:fs');
391391
const path = require('node:path');
392-
const { glob } = require('glob');
393392
394393
let workingDirectory = process.env.WORKING_DIRECTORY || '.';
395394
if (!path.isAbsolute(workingDirectory)) {
@@ -409,25 +408,50 @@ jobs:
409408
const runScriptCommand = process.env.RUN_SCRIPT_COMMAND;
410409
const registryUrl = process.env.REGISTRY_URL;
411410
411+
// Simple glob matching function
412+
function matchGlob(pattern, filename) {
413+
const regexPattern = pattern
414+
.replace(/\./g, '\\.')
415+
.replace(/\*/g, '.*')
416+
.replace(/\?/g, '.');
417+
return new RegExp(`^${regexPattern}$`).test(filename);
418+
}
419+
412420
// Determine what to publish
413421
let publishTarget = null;
414422
415423
if (packageTarball) {
416424
// Publishing a specific tarball file
417-
const tarballPattern = path.isAbsolute(packageTarball)
418-
? packageTarball
419-
: path.join(workingDirectory, packageTarball);
420-
421-
const matches = await glob(tarballPattern, { nodir: true });
422-
425+
let searchDir = workingDirectory;
426+
let filePattern = packageTarball;
427+
428+
if (path.isAbsolute(packageTarball)) {
429+
searchDir = path.dirname(packageTarball);
430+
filePattern = path.basename(packageTarball);
431+
} else if (packageTarball.includes('/')) {
432+
searchDir = path.join(workingDirectory, path.dirname(packageTarball));
433+
filePattern = path.basename(packageTarball);
434+
}
435+
436+
if (!fs.existsSync(searchDir)) {
437+
return core.setFailed(`Search directory does not exist: ${searchDir}`);
438+
}
439+
440+
// Find matching files
441+
const allFiles = fs.readdirSync(searchDir);
442+
const matches = allFiles
443+
.filter(file => matchGlob(filePattern, file))
444+
.map(file => path.join(searchDir, file))
445+
.filter(file => fs.statSync(file).isFile());
446+
423447
if (matches.length === 0) {
424-
return core.setFailed(`No tarball found matching pattern: ${packageTarball}`);
448+
return core.setFailed(`No tarball found matching pattern: ${packageTarball} in ${searchDir}`);
425449
}
426-
450+
427451
if (matches.length > 1) {
428452
core.warning(`Multiple tarballs found: ${matches.join(', ')}. Using first match.`);
429453
}
430-
454+
431455
publishTarget = matches[0];
432456
core.info(`Publishing tarball: ${publishTarget}`);
433457
}

0 commit comments

Comments
 (0)