generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
2742420
commit 02f53de
Showing
2 changed files
with
58 additions
and
9 deletions.
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 |
---|---|---|
|
@@ -32,17 +32,17 @@ jobs: | |
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | ||
type=ref,event=tag | ||
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/') }} | ||
type=ref,event=pr | ||
type=ref,event=branch,branch=main,latest=true | ||
type=ref,event=branch,branch=main,tag=latest | ||
type=ref,event=branch,branch!=main | ||
type=semver,pattern={{version}},branch=main,latest=false,tag=stable | ||
type=ref,event=tag,tag={{ tag }} | ||
- name: Show tags | ||
run: | | ||
git tag | ||
echo ${{ steps.meta.outputs.tags }} | ||
echo "Tags generated by metadata-action:\n" | ||
for tag in ${{ steps.metadata.output.tags }}; do | ||
echo $tag | ||
done | ||
- name: Extract version from tag | ||
if: startsWith(github.ref, 'refs/tags/') | ||
|
@@ -65,4 +65,53 @@ jobs: | |
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
build-args: | | ||
BASE_APE_IMAGE_TAG=stable-slim | ||
BASE_APE_IMAGE_TAG=latest-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: | ||
account: ApeWorX | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
image-tags: "!stable* !latest* !${{ env.keep_tags }}" | ||
tag-selection: both | ||
cut-off: 4w | ||
dry-run: true | ||
|
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