Skip to content

Commit

Permalink
Support new asset names with PMD 7.0.0-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Apr 6, 2023
1 parent 40392a1 commit 13c47a4
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions tests/data/create-zips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions tests/data/pmd-bin-7.0.0-rc2/bin/pmd
Original file line number Diff line number Diff line change
@@ -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

17 changes: 17 additions & 0 deletions tests/data/pmd-bin-7.0.0-rc2/bin/pmd.bat
Original file line number Diff line number Diff line change
@@ -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"
Binary file added tests/data/pmd-dist-7.0.0-rc2-bin.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/data/releases-7.0.0-rc2.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
18 changes: 18 additions & 0 deletions tests/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 13c47a4

Please sign in to comment.