diff --git a/lib/util.js b/lib/util.js index e0b6110..a08e10d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -145,7 +145,11 @@ function getPmdVersionFromRelease(release) { } function getDownloadURL(release) { - const asset = release.data.assets.filter(a => a.name === `pmd-bin-${getPmdVersionFromRelease(release)}.zip`)[0]; + const asset = release.data.assets.filter(a => { + const version = getPmdVersionFromRelease(release); + return a.name === `pmd-bin-${version}.zip` + || a.name === `pmd-dist-${version}-bin.zip` + })[0]; core.debug(`url: ${asset.browser_download_url}`); return asset.browser_download_url; } diff --git a/tests/data/create-zips.sh b/tests/data/create-zips.sh index 2f70d8f..f01bc10 100755 --- a/tests/data/create-zips.sh +++ b/tests/data/create-zips.sh @@ -4,4 +4,5 @@ zip -r pmd-bin-6.39.0.zip pmd-bin-6.39.0 zip -r pmd-bin-6.40.0.zip pmd-bin-6.40.0 zip -r pmd-bin-6.41.0.zip pmd-bin-6.41.0 zip -r pmd-bin-7.0.0-rc1.zip pmd-bin-7.0.0-rc1 +zip -r pmd-dist-7.0.0-rc2-bin.zip pmd-bin-7.0.0-rc2 zip -r pmd-bin-7.0.0-SNAPSHOT.zip pmd-bin-7.0.0-SNAPSHOT diff --git a/tests/data/pmd-bin-7.0.0-rc2/bin/pmd b/tests/data/pmd-bin-7.0.0-rc2/bin/pmd new file mode 100755 index 0000000..9445fa3 --- /dev/null +++ b/tests/data/pmd-bin-7.0.0-rc2/bin/pmd @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +echo "Running PMD 7.0.0-rc2 with: $@" + +echo '{ + "runs": [ + { + "tool": { + "driver": { + "name": "PMD", + "version": "7.0.0-rc2" + } + } + } + ] +}' > pmd-report.sarif + diff --git a/tests/data/pmd-bin-7.0.0-rc2/bin/pmd.bat b/tests/data/pmd-bin-7.0.0-rc2/bin/pmd.bat new file mode 100644 index 0000000..e78124d --- /dev/null +++ b/tests/data/pmd-bin-7.0.0-rc2/bin/pmd.bat @@ -0,0 +1,17 @@ +@echo off +echo Running PMD 7.0.0-rc2 with: %* + +( + echo { + echo "runs": [ + echo { + echo "tool": { + echo "driver": { + echo "name": "PMD", + echo "version": "7.0.0-rc2" + echo } + echo } + echo } + echo ] + echo } +)>"pmd-report.sarif" diff --git a/tests/data/pmd-dist-7.0.0-rc2-bin.zip b/tests/data/pmd-dist-7.0.0-rc2-bin.zip new file mode 100644 index 0000000..5ae656a Binary files /dev/null and b/tests/data/pmd-dist-7.0.0-rc2-bin.zip differ diff --git a/tests/data/releases-7.0.0-rc2.json b/tests/data/releases-7.0.0-rc2.json new file mode 100644 index 0000000..880195f --- /dev/null +++ b/tests/data/releases-7.0.0-rc2.json @@ -0,0 +1,11 @@ +{ + "id": "2", + "name": "latest pmd release for test (7.0.0-rc2)", + "tag_name": "pmd_releases/7.0.0-rc2", + "assets": [ + { + "browser_download_url": "https://github.com/pmd/pmd/releases/download/pmd_releases/7.0.0-rc2/pmd-dist-7.0.0-rc2-bin.zip", + "name": "pmd-dist-7.0.0-rc2-bin.zip" + } + ] +} diff --git a/tests/util.test.js b/tests/util.test.js index e2a34ba..916cf8d 100644 --- a/tests/util.test.js +++ b/tests/util.test.js @@ -460,6 +460,24 @@ describe('pmd-github-action-util', function () { await expect(util.downloadPmd('latest', 'my-token', 'https://example.org/download')).rejects .toBe('Can\'t combine version=latest with custom downloadUrl=https://example.org/download'); }); + + it('use latest PMD 7.0.0-rc2 with new binary filename', async () => { + nock('https://api.github.com') + .get('/repos/pmd/pmd/releases/latest') + .replyWithFile(200, __dirname + '/data/releases-7.0.0-rc2.json', { + 'Content-Type': 'application/json', + }) + nock('https://github.com') + .get('/pmd/pmd/releases/download/pmd_releases/7.0.0-rc2/pmd-dist-7.0.0-rc2-bin.zip') + .replyWithFile(200, __dirname + '/data/pmd-dist-7.0.0-rc2-bin.zip') + + const pmdInfo = await util.downloadPmd('latest', 'my_test_token'); + + const toolCache = path.join(cachePath, 'pmd', '7.0.0-rc2', os.arch(), 'pmd-bin-7.0.0-rc2'); + expect(pmdInfo).toStrictEqual({ path: toolCache, version: '7.0.0-rc2' }); + await expect(fs.access(toolCache)).resolves.toBe(undefined); + }) + }); function setGlobal(key, value) {