-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding retention policy (#2247)
- Loading branch information
1 parent
3ad3407
commit 9e13391
Showing
1 changed file
with
48 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -39,7 +39,6 @@ jobs: | |
- name: Show tags | ||
run: | | ||
git tag | ||
echo ${{ steps.meta.outputs.tags }} | ||
- name: Extract version from tag | ||
|
@@ -77,3 +76,51 @@ jobs: | |
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
SLIM_IMAGE=${{ steps.meta.outputs.tags }}-slim | ||
- name: Fetch all tags and store them | ||
run: | | ||
# List all tags | ||
tags=$(git tag -l) | ||
echo "All tags:" | ||
echo "$tags" | ||
# Save tags in an environment variable for later use | ||
echo "ALL_TAGS=$(echo $tags | tr '\n' ' ')" >> $GITHUB_ENV | ||
- name: Retain last two minor versions | ||
run: | | ||
# Fetch all tags in the format X.Y.Z | ||
echo "Using stored tags..." | ||
all_tags="${{ env.ALL_TAGS }}" | ||
echo "All tags:" | ||
echo "$all_tags" | ||
# Extract the minor versions (X.Y) from tags in the format vX.X.X | ||
latest_two_minors=$(echo "$all_tags" | tr ' ' '\n' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed -E 's/^v([0-9]+\.[0-9]+)\.[0-9]+$/\1/' | uniq | tail -n 2) | ||
echo "Last two minor versions:" | ||
echo "$latest_two_minors" | ||
keep_tags="" | ||
for minor in $latest_two_minors; do | ||
echo "Processing minor version: $minor" | ||
patches=$(echo "$all_tags" | tr ' ' '\n' | grep "^v$minor\.") | ||
echo "Latest patch for $minor: $patches" | ||
keep_tags="$keep_tags $patches" | ||
done | ||
# Store the tags in the environment variable | ||
keep_tags=$(echo $keep_tags | tr ' ' '\n' | paste -sd ',' -) | ||
echo "Tags to keep: $keep_tags" | ||
echo "keep_tags=$keep_tags" >> $GITHUB_ENV | ||
echo "keep_tags=$keep_tags" | ||
- name: Run container retention policy | ||
if: github.ref == 'refs/heads/main' | ||
uses: snok/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
keep-tag-names: | | ||
stable | ||
latest | ||
${{ env.keep_tags }} | ||