Skip to content

Commit b4ff15b

Browse files
authored
Support new asset names with PMD 7.0.0-rc3 (#180)
1 parent 6403816 commit b4ff15b

File tree

8 files changed

+72
-4
lines changed

8 files changed

+72
-4
lines changed

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ function getPmdVersionFromRelease(release) {
145145
}
146146

147147
function getDownloadURL(release) {
148-
const asset = release.data.assets.filter(a => a.name === `pmd-bin-${getPmdVersionFromRelease(release)}.zip`)[0];
148+
const asset = release.data.assets.filter(a => {
149+
const version = getPmdVersionFromRelease(release);
150+
return a.name === `pmd-bin-${version}.zip`
151+
|| a.name === `pmd-dist-${version}-bin.zip`
152+
})[0];
149153
core.debug(`url: ${asset.browser_download_url}`);
150154
return asset.browser_download_url;
151155
}

tests/data/create-zips.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ zip -r pmd-bin-6.39.0.zip pmd-bin-6.39.0
44
zip -r pmd-bin-6.40.0.zip pmd-bin-6.40.0
55
zip -r pmd-bin-6.41.0.zip pmd-bin-6.41.0
66
zip -r pmd-bin-7.0.0-rc1.zip pmd-bin-7.0.0-rc1
7+
zip -r pmd-dist-7.0.0-rc3-bin.zip pmd-bin-7.0.0-rc3
78
zip -r pmd-bin-7.0.0-SNAPSHOT.zip pmd-bin-7.0.0-SNAPSHOT
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Running PMD 7.0.0-rc3 with: $@"
4+
5+
echo '{
6+
"runs": [
7+
{
8+
"tool": {
9+
"driver": {
10+
"name": "PMD",
11+
"version": "7.0.0-rc3"
12+
}
13+
}
14+
}
15+
]
16+
}' > pmd-report.sarif
17+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@echo off
2+
echo Running PMD 7.0.0-rc3 with: %*
3+
4+
(
5+
echo {
6+
echo "runs": [
7+
echo {
8+
echo "tool": {
9+
echo "driver": {
10+
echo "name": "PMD",
11+
echo "version": "7.0.0-rc3"
12+
echo }
13+
echo }
14+
echo }
15+
echo ]
16+
echo }
17+
)>"pmd-report.sarif"
1.01 KB
Binary file not shown.

tests/data/releases-7.0.0-rc3.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "2",
3+
"name": "latest pmd release for test (7.0.0-rc3)",
4+
"tag_name": "pmd_releases/7.0.0-rc3",
5+
"assets": [
6+
{
7+
"browser_download_url": "https://github.com/pmd/pmd/releases/download/pmd_releases/7.0.0-rc3/pmd-dist-7.0.0-rc3-bin.zip",
8+
"name": "pmd-dist-7.0.0-rc3-bin.zip"
9+
}
10+
]
11+
}

tests/util.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,24 @@ describe('pmd-github-action-util', function () {
460460
await expect(util.downloadPmd('latest', 'my-token', 'https://example.org/download')).rejects
461461
.toBe('Can\'t combine version=latest with custom downloadUrl=https://example.org/download');
462462
});
463+
464+
it('use latest PMD 7.0.0-rc3 with new binary filename', async () => {
465+
nock('https://api.github.com')
466+
.get('/repos/pmd/pmd/releases/latest')
467+
.replyWithFile(200, __dirname + '/data/releases-7.0.0-rc3.json', {
468+
'Content-Type': 'application/json',
469+
})
470+
nock('https://github.com')
471+
.get('/pmd/pmd/releases/download/pmd_releases/7.0.0-rc3/pmd-dist-7.0.0-rc3-bin.zip')
472+
.replyWithFile(200, __dirname + '/data/pmd-dist-7.0.0-rc3-bin.zip')
473+
474+
const pmdInfo = await util.downloadPmd('latest', 'my_test_token');
475+
476+
const toolCache = path.join(cachePath, 'pmd', '7.0.0-rc3', os.arch(), 'pmd-bin-7.0.0-rc3');
477+
expect(pmdInfo).toStrictEqual({ path: toolCache, version: '7.0.0-rc3' });
478+
await expect(fs.access(toolCache)).resolves.toBe(undefined);
479+
})
480+
463481
});
464482

465483
function setGlobal(key, value) {

0 commit comments

Comments
 (0)