Skip to content

Commit

Permalink
Refactor container.yml
Browse files Browse the repository at this point in the history
Refactor 'set IS_VERSION_TAG' into determine-tags-action composite action
  • Loading branch information
Robert Schardt authored and Robert Schardt committed Sep 20, 2024
1 parent 1bc955d commit 54f3e18
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
30 changes: 30 additions & 0 deletions .github/actions/determine-tags-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'determine-tags-action'
description: 'Determine version and latest tags'
runs:
using: "composite"
steps:
- name: "set IS_VERSION_TAG"
run: |
echo "IS_VERSION_TAG=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
# set defaults
echo "IS_LATEST_TAG=false" >> $GITHUB_ENV
- name: "set IS_LATEST_TAG"
if: ( env.IS_VERSION_TAG )
run: |
# find the latest version that is not ourself
export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort)
# get major minor patch versions
IFS='.' read -r latest_major latest_minor latest_patch << EOF
$LATEST_VERSION
EOF
IFS='.' read -r tag_major tag_minor tag_patch << EOF
${{ github.ref_name }}
EOF
# remove leading v
latest_major=$(echo $latest_major | cut -c2-)
tag_major=$(echo $tag_major | cut -c2-)
echo "$tag_major >= $latest_major"
if [[ $tag_major -ge $latest_major && ($tag_minor -ne 0 || $tag_patch -ne 0) ]]; then
# set this tag to latest and stable
echo "IS_LATEST_TAG=true" >> $GITHUB_ENV
fi
51 changes: 22 additions & 29 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,14 @@ on:
workflow_dispatch:

jobs:
production:
name: Production Images
build-push-debian-stable-container:
name: Build and push debian:stable container
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: "set IS_VERSION_TAG"
run: |
echo "IS_VERSION_TAG=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
# set defaults
echo "IS_LATEST_TAG=false" >> $GITHUB_ENV
- name: "set IS_LATEST_TAG"
if: ( env.IS_VERSION_TAG )
run: |
# find the latest version that is not ourself
export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort)
# get major minor patch versions
IFS='.' read -r latest_major latest_minor latest_patch << EOF
$LATEST_VERSION
EOF
IFS='.' read -r tag_major tag_minor tag_patch << EOF
${{ github.ref_name }}
EOF
# remove leading v
latest_major=$(echo $latest_major | cut -c2-)
tag_major=$(echo $tag_major | cut -c2-)
echo "$tag_major >= $latest_major"
if [[ $tag_major -ge $latest_major && ($tag_minor -ne 0 || $tag_patch -ne 0) ]]; then
# set this tag to latest and stable
echo "IS_LATEST_TAG=true" >> $GITHUB_ENV
fi
- name: determine-tags-action
uses: ./.github/actions/determine-tags-action
- name: "Setup meta information debian:stable"
id: meta
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -83,6 +60,14 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build-push-debian-oldstable-container:
name: Build and push debian:oldstable container
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: determine-tags-action
uses: ./.github/actions/determine-tags-action
- name: "Setup meta information debian:oldstable"
id: old_stable_meta
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -110,6 +95,14 @@ jobs:
tags: ${{ steps.old_stable_meta.outputs.tags }}
labels: ${{ steps.old_stable_meta.outputs.labels }}

build-push-debian-testing-container:
name: Build and push debian:testing container
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: determine-tags-action
uses: ./.github/actions/determine-tags-action
- name: "Setup meta information debian:testing"
id: testing_meta
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -139,7 +132,7 @@ jobs:

# triggers projects that work with stable branches on a new stable tag
trigger-stable-projects:
needs: production
needs: build-push-debian-stable-container
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
name: Trigger update container images in related projects for new tags
strategy:
Expand All @@ -164,7 +157,7 @@ jobs:
ref: main

trigger-related-projects:
needs: production
needs: build-push-debian-stable-container
if: github.event_name != 'pull_request'
name: Trigger update container images in related projects
strategy:
Expand Down

0 comments on commit 54f3e18

Please sign in to comment.