Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new binary dist filenames with PMD 7.0.0-rc3 #180

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

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-rc3-bin.zip pmd-bin-7.0.0-rc3
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-rc3/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-rc3 with: $@"

echo '{
"runs": [
{
"tool": {
"driver": {
"name": "PMD",
"version": "7.0.0-rc3"
}
}
}
]
}' > pmd-report.sarif

17 changes: 17 additions & 0 deletions tests/data/pmd-bin-7.0.0-rc3/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-rc3 with: %*

(
echo {
echo "runs": [
echo {
echo "tool": {
echo "driver": {
echo "name": "PMD",
echo "version": "7.0.0-rc3"
echo }
echo }
echo }
echo ]
echo }
)>"pmd-report.sarif"
Binary file added tests/data/pmd-dist-7.0.0-rc3-bin.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/data/releases-7.0.0-rc3.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-rc3)",
"tag_name": "pmd_releases/7.0.0-rc3",
"assets": [
{
"browser_download_url": "https://github.com/pmd/pmd/releases/download/pmd_releases/7.0.0-rc3/pmd-dist-7.0.0-rc3-bin.zip",
"name": "pmd-dist-7.0.0-rc3-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-rc3 with new binary filename', async () => {
nock('https://api.github.com')
.get('/repos/pmd/pmd/releases/latest')
.replyWithFile(200, __dirname + '/data/releases-7.0.0-rc3.json', {
'Content-Type': 'application/json',
})
nock('https://github.com')
.get('/pmd/pmd/releases/download/pmd_releases/7.0.0-rc3/pmd-dist-7.0.0-rc3-bin.zip')
.replyWithFile(200, __dirname + '/data/pmd-dist-7.0.0-rc3-bin.zip')

const pmdInfo = await util.downloadPmd('latest', 'my_test_token');

const toolCache = path.join(cachePath, 'pmd', '7.0.0-rc3', os.arch(), 'pmd-bin-7.0.0-rc3');
expect(pmdInfo).toStrictEqual({ path: toolCache, version: '7.0.0-rc3' });
await expect(fs.access(toolCache)).resolves.toBe(undefined);
})

});

function setGlobal(key, value) {
Expand Down