-
Notifications
You must be signed in to change notification settings - Fork 3
Remove extra logging, add additional task for removing npm versions and remove use of versioning plugin #238
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b6b035f
Remove logging of XMLBeans version now that we know what the real pro…
labkey-susanh 18b6dbd
Add new PurgeNpmVersions task
labkey-susanh 8fd80ca
Revert accidental commit of classpath change for xmlbeans
labkey-susanh f36878e
Remove use of versioning plugin
labkey-susanh d475764
Switch to info logging
labkey-susanh ae37b5c
Change branch/version name
labkey-susanh e01fac7
Update readme
labkey-susanh 06f3464
use different git command for Windows
labkey-susanh 6dc698b
merge from develop
labkey-susanh 559f178
Strip out token from Git URL if present
labkey-susanh 8b79978
prepare for merge
labkey-susanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/main/groovy/org/labkey/gradle/task/PurgeNpmVersions.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package org.labkey.gradle.task | ||
|
|
||
|
|
||
| import org.apache.commons.lang3.StringUtils | ||
| import org.apache.hc.client5.http.classic.methods.HttpDelete | ||
| import org.apache.hc.client5.http.impl.classic.CloseableHttpClient | ||
| import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse | ||
| import org.apache.hc.client5.http.impl.classic.HttpClients | ||
| import org.apache.hc.core5.http.HttpStatus | ||
| import org.gradle.api.DefaultTask | ||
| import org.gradle.api.GradleException | ||
| import org.gradle.api.provider.Property | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.TaskAction | ||
| import org.labkey.gradle.util.TaskUtils | ||
|
|
||
| abstract class PurgeNpmVersions extends DefaultTask | ||
| { | ||
| private static final String REPOSITORY_NAME = 'libs-client-local' | ||
| public static final String DRY_RUN_PROPERTY = 'dryRun' | ||
| private static final String PACKAGE_NAME_PROP = "packageName" | ||
| private static final String VERSION_LIST_PROP = "versionList" | ||
|
|
||
| @Input | ||
| final abstract Property<String> packageName = project.objects.property(String).convention((project.hasProperty(PACKAGE_NAME_PROP) ? (String) project.property(PACKAGE_NAME_PROP) : null)) | ||
|
|
||
| @Input | ||
| final abstract Property<String> versionList = project.objects.property(String).convention((project.hasProperty(VERSION_LIST_PROP) ? (String) project.property(VERSION_LIST_PROP) : null)) | ||
|
|
||
| @Input | ||
| final abstract Property<Boolean> isDryRun = project.objects.property(Boolean).convention(project.hasProperty(DRY_RUN_PROPERTY)) | ||
| @Input | ||
| final abstract Property<String> artifactoryUrl = project.objects.property(String).convention((String) project.property('artifactory_contextUrl')) | ||
| @Input | ||
| final abstract Property<String> artifactoryUser = project.objects.property(String).convention((String) project.property('artifactory_user')) | ||
| @Input | ||
| final abstract Property<String> artifactoryPassword = project.objects.property(String).convention((String) project.property('artifactory_password')) | ||
|
|
||
| @TaskAction | ||
| void purgeVersions() | ||
| { | ||
| if (!packageName.isPresent() || StringUtils.isEmpty(packageName.get().trim())) | ||
| throw new GradleException("No value provided for packageName.") | ||
| String packageName = "@labkey/" + packageName.get() | ||
| String[] undeletedVersions = [] | ||
|
|
||
| logger.quiet("Considering ${packageName}...") | ||
| List<String> versions = readPurgeVersions() | ||
| if (versions.isEmpty()) | ||
| logger.quiet("No versions provided.") | ||
| else { | ||
| logger.quiet("Found ${versions.size()} versions in package ${packageName}") | ||
| versions.forEach(version -> { | ||
| if (isDryRun.get()) | ||
| logger.quiet("Removing version ${version} of package ${packageName} -- Skipped for dry run") | ||
| else { | ||
| logger.quiet("Removing version ${version} of package ${packageName}") | ||
| if (!makeDeleteRequest(packageName, version)) { | ||
| undeletedVersions += "${packageName}: ${version}" | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| if (undeletedVersions.size() > 0) | ||
| throw new GradleException("The following versions were not deleted.\n${undeletedVersions}\nCheck the log for more information.") | ||
| } | ||
|
|
||
| List<String> readPurgeVersions() | ||
| { | ||
| if (versionList.isPresent() && !StringUtils.isEmpty(versionList.get().trim())) | ||
| return TaskUtils.readInputFile(versionList.get(), "versions", logger) | ||
| else | ||
| throw new GradleException("No " + VERSION_LIST_PROP + " or " + VERSION_LIST_PROP + " property provided."); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * This uses the Artifactory REST Api to request a deletion of a particular package and version. There does | ||
| * not appear to be a way to request deletion of multiple versions at once. Also, though it might seem natural | ||
| * to use "npm unpublish" for this deletion, this does not work with artifactory, possibly due to this long-standing | ||
| * issue: https://github.com/npm/npm-registry-client/issues/41 | ||
| * The command appears to work, returning a 200 status code when you use --verbose logging, but the artifact doesn't | ||
| * go anywhere. | ||
| * | ||
| * Another possibility here would be to use the same action as is used in the Web UI. There, Artifactory sends | ||
| * a POST request to: | ||
| * Request URL: https://artifactory.labkey.com/artifactory/ui/artifactactions/delete | ||
| * with parameters | ||
| * repoKey: libs-client-local | ||
| * path: "@labkey/components/-/@labkey/components-2.14.2-fb-update-react-select.1.tgz" | ||
| * The REST API seems a better approach, though. | ||
| * @param packageName the package whose version is to be deleted, including the scope (e.g., @labkey/components) | ||
| * @param version the version of the package to delete (e.g., 2.14.2-fb-update-react-select.1) | ||
| * @return true if deletion was successful, false otherwise | ||
| * @throws GradleException if the delete request throws an exception | ||
| */ | ||
| protected boolean makeDeleteRequest(String packageName, String version) | ||
| { | ||
| CloseableHttpClient httpClient = HttpClients.createDefault() | ||
| String endpoint = artifactoryUrl.get() | ||
| boolean success = true | ||
| if (!endpoint.endsWith("/")) | ||
| endpoint += "/" | ||
|
|
||
| // The coordinates of the packages look like this: "@labkey/components/-/@labkey/components-2.14.2-fb-update-react-select.1.tgz" | ||
| endpoint += REPOSITORY_NAME + "/" + packageName + "/-/" + packageName + "-" + version + ".tgz" | ||
| logger.debug("Making delete request for package ${packageName} and version ${version} via endpoint ${endpoint}") | ||
| try | ||
| { | ||
| HttpDelete httpDelete = new HttpDelete(endpoint) | ||
| // N.B. Using Authorization Bearer with an API token does not currently work | ||
| httpDelete.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("${artifactoryUser.get()}:${artifactoryPassword.get()}".getBytes())) | ||
| CloseableHttpResponse response = httpClient.execute(httpDelete) | ||
| int statusCode = response.getCode() | ||
| if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_NO_CONTENT) { | ||
| logger.error("Unable to delete using ${endpoint}: ${statusCode} ${response.getReasonPhrase()}") | ||
| success = false | ||
| } | ||
| response.close() | ||
| return success | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| throw new GradleException("Problem executing delete request with url ${endpoint}", e) | ||
| } | ||
| finally | ||
| { | ||
| httpClient.close() | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
25.12?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should still be compatible with 25.10 since the presence of the versioning plugin version shouldn't cause problems; we simply won't be using it.