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

feat: limit cleanup to versions created in last X days [KHCP-7885] #58

Merged
merged 8 commits into from
Aug 16, 2023
Merged
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
8 changes: 7 additions & 1 deletion pr-previews/cleanup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
package:
description: Package to cleanup PR versions
required: true
days:
description: Only clean up the versions that are days-to-cleanup newer
default: 40
openPRs:
description: List of open PRs in the repo

Expand All @@ -21,12 +24,15 @@ runs:
echo "package: ${pkgName}"
echo "openPRs: ${openPRs}"

oldestDate=$(date -d '-${{ inputs.days }} day' +%s)
echo "oldestDate:${oldestDate}"

current=1
canDelete="true"

# get the list of the "-pr." published version for the packages
pkgDetails=$(npm view "${pkgName}" --json)
prVersions=($(echo ${pkgDetails}| jq -r '.versions' | grep '\-pr.'| tac | sed 's/[,\"]//g'))
prVersions=($(echo ${pkgDetails} | jq -r '.time' | jq -r 'to_entries' | jq --arg jq_oldestDate ${oldestDate} '[.[] | select(.value |.[0:19] +"Z" | fromdateiso8601 > ($jq_oldestDate|tonumber))]' | jq '[.[] | .key]'| grep "\-pr." | tac | sed 's/[,\"]//g'))
if [[ -z "${prVersions}" ]]; then
echo "No preview versions found, exiting..."
exit 0
Expand Down
Loading