-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a57738
commit 4bf0d06
Showing
3 changed files
with
78 additions
and
18 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,39 @@ | ||
name: Artifactory Cleanup | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
from_date: | ||
description: '' | ||
required: false | ||
default: '30 days ago' | ||
schedule: | ||
- cron: '0 12 7,14,21,28 * *' | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
cleanup: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup jfrog CLI | ||
uses: jfrog/setup-jfrog-cli@v1 | ||
env: | ||
JF_ARTIFACTORY_1: ${{ secrets.JF_ARTIFACTORY_SERVER_1 }} | ||
|
||
- name: Ping Artifactory with jfrog CLI | ||
run: | | ||
# Ping the server | ||
jfrog rt ping | ||
- name: Run Cleanup | ||
run: | | ||
./build/gh-action-cleanup-artifactory.sh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
FROM_DATE: ${{ github.event.inputs.from_date || '30 days ago' }} |
This file contains 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,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
comp_date=$(date --date="${FROM_DATE:=14 days ago}" +"%Y-%m-%dT%H:%M:%S.000Z") | ||
|
||
local_dist_path="yorc-bin-dev-local/ystia/yorc/dist" | ||
|
||
all_paths=$(jfrog rt s "${local_dist_path}/*/yorc-*.tgz" --limit 0 | jq -r ".[]| [.modified, .path] | @tsv" | sed -e "s@${local_dist_path}/\(.*\)/yorc-.*\.tgz@\1@g" | sort) | ||
|
||
function get_pr_state() { | ||
gh pr view "${1}" --json state | jq -r ".state" | ||
} | ||
|
||
function does_branch_exit() { | ||
gh api --silent "/repos/:owner/:repo/branches/${1}" 2> /dev/null | ||
return $? | ||
} | ||
|
||
function delete_artifactory_path() { | ||
jfrog rt del --quiet "${local_dist_path}/${1}" || echo "failed to delete ${local_dist_path}/${1}" | ||
} | ||
|
||
echo "${all_paths}" | while read line ; do | ||
item_date=$(echo "$line" | awk '{print $1}') | ||
if [[ "${item_date}" > "${comp_date}" ]] ; then | ||
continue | ||
fi | ||
ref=$(echo "${line}" | awk -F '\t' '{print $2}') | ||
if [[ "${ref}" == PR-* ]] ; then | ||
if [[ "$(get_pr_state "${ref##*PR-}")" != "OPEN" ]] ; then | ||
delete_artifactory_path "${ref}" | ||
fi | ||
else | ||
if ! does_branch_exit "${ref}" ; then | ||
delete_artifactory_path "${ref}" | ||
fi | ||
fi | ||
done |