Skip to content

Commit

Permalink
wip - ci
Browse files Browse the repository at this point in the history
  • Loading branch information
itewk committed Oct 17, 2024
1 parent c025977 commit c60a379
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/scripts/determine-image-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

IMAGE_REPOSITORY=${REGISTRY_URI}/${REGISTRY_REPOSITORY}/${IMAGE_NAME}

# determine version
# if scheduled build then version is 'nightly'
# else if REF is a tag then version is tag
# else if REF is the default branch then version is 'edge'
# else if REF is pull request then version is pull request event number
VERSION=noop
if [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
VERSION=nightly
elif [[ ${GITHUB_REF} == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ ${GITHUB_REF} == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ ${GITHUB_REF} == refs/pull/* ]]; then
VERSION=pr-${GITHUB_EVENT_NUMBER}
fi
VERSION="${VERSION}"
TAGS="${IMAGE_REPOSITORY}:${VERSION}"

# if version is vMAJOR.MINOR.MICRO then also tag with vMAJOR and vMAJOR.MINOR
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="${TAGS},${IMAGE_REPOSITORY}:${MINOR},${IMAGE_REPOSITORY}:${MAJOR},${IMAGE_REPOSITORY}:latest"
fi

# add sha tag if not a pull request
if [[ ${GITHUB_REF} != refs/pull/* ]]; then
TAGS="${TAGS},${IMAGE_REPOSITORY}:sha-${GITHUB_SHA::12}"
fi

# if a flavor is provided then iterate each tag and add the flavor to it
# if IMAGE_IS_DEFAULT_FLAVOR is also true, then also use the unflavored tags
if [[ ${IMAGE_TAG_FLAVOR} ]] ; then
original_tags=$TAGS
TAGS=""

for original_tag in $(echo $original_tags | sed "s/,/ /g")
do
if [[ ${IMAGE_IS_DEFAULT_FLAVOR} =~ true|True|t|T|yes|Yes|y|Y ]]; then
new_tags="${original_tag},${original_tag}${IMAGE_TAG_FLAVOR}"
else
new_tags="${original_tag}${IMAGE_TAG_FLAVOR}"
fi

if [[ ${TAGS} ]]; then
TAGS="${TAGS},${new_tags}"
else
TAGS="${new_tags}"
fi
done
fi

# set output for future github action steps
echo "version=${VERSION}${IMAGE_TAG_FLAVOR}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
69 changes: 69 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: publish

on:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches: [ main ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
GITHUB_EVENT_REPOSITORY_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
REGISTRY_URI: ${{ vars.REGISTRY_URI }}
REGISTRY_REPOSITORY: ${{ vars.REGISTRY_REPOSITORY }}

jobs:
e-kustomzie-with-ocm-policygenerator-plugin-and-helm:
runs-on: ubuntu-latest

env:
IMAGE_NAME: ee-kustomzie-with-ocm-policygenerator-plugin-and-helm
IMAGE_TAG_LOCAL: localhost:5000/${{ vars.REGISTRY_REPOSITORY }}/ploigos-base:latest.ubi8

services:
registry:
image: registry:2
ports:
- 5000:5000

outputs:
version: ${{ steps.prep.outputs.version }}

steps:
- name: Checkout 🛎️
uses: actions/[email protected]

- name: Determine Image Version and Tags ⚙️
id: prep
run: ${GITHUB_WORKSPACE}/.github/scripts/determine-image-version.sh

- name: Version 📌
run: echo ${{ steps.prep.outputs.version }}

- name: Image Tags 🏷
run: echo ${{ steps.prep.outputs.tags }}

- name: Install ansible-builder 🧰
run: pip install ansible-builder

- name: Build Ansible EE container image
run: |
ansible-builder build -v3
- name: Log in to ${{ vars.REGISTRY_URI }} 🔑
uses: redhat-actions/[email protected]
with:
registry: ${{ vars.REGISTRY_URI }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

0 comments on commit c60a379

Please sign in to comment.