fix: force en language #22
Workflow file for this run
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
name: Build Keycloak (Connect) github release (Push Tag) | |
on: | |
push: | |
tags: | |
- '*.*.*-develop' | |
- '*.*.*-staging' | |
- '*.*.*' | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
#container: | |
# image: bitnami/keycloak:20.0.3-debian-11-r5 | |
# options: --user 0 | |
steps: | |
- name: Set variables | |
run: | | |
TAG="$( echo "${GITHUB_REF}" | cut -d'/' -f3 )" | |
if grep -qs -e '^.*.*-develop' <<< "${TAG}" ; then | |
echo "Found environment: DEVELOP - ${TAG}" | |
echo "MANIFESTS_ENVIRONMENT=develop" | tee -a "${GITHUB_ENV}" | |
elif grep -qs -e '^.*.*-staging' <<< "${TAG}" ; then | |
echo "Found environment: STAGING - ${TAG}" | |
echo "MANIFESTS_ENVIRONMENT=staging" | tee -a "${GITHUB_ENV}" | |
elif grep -qs -e '^.*.*' <<< "${TAG}" ; then | |
echo "No environment found, assuming: PRODUCTION - ${TAG}" | |
echo "MANIFESTS_ENVIRONMENT=production" | tee -a "${GITHUB_ENV}" | |
else | |
echo 'Not a valid tag. Skipping...' | |
exit 1 | |
fi | |
echo "TAG=$TAG" | tee -a "${GITHUB_ENV}" | |
VERSION="${TAG}" | |
echo "VERSION=${VERSION}" | tee -a "${GITHUB_ENV}" | |
echo "COMMIT_SHA=$GITHUB_SHA" | tee -a "${GITHUB_ENV}" | |
echo "IMAGE_TAG=connectof/keycloak:${TAG}" | tee -a "${GITHUB_ENV}" | |
echo "IMAGE_SOURCE_URL=https://github.com/weni-ai/connect-keycloak" | tee -a "${GITHUB_ENV}" | |
echo "MANIFESTS_REPOSITORY=weni-ai/kubernetes-manifests-connect" | tee -a "${GITHUB_ENV}" | |
echo "MANIFESTS_APPLICATION=keycloak" | tee -a "${GITHUB_ENV}" | |
echo "MANIFESTS_PATCH_TARGET=sts.json" | tee -a "${GITHUB_ENV}" | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
with: | |
ref: "${{env.GITHUB_SHA}}" | |
- name: Build Release - Keycloak (Connect) | |
uses: addnab/docker-run-action@v3 | |
with: | |
image: bitnami/keycloak:20.0.3-debian-11-r5 | |
options: -v ${{ github.workspace }}:/workdir -w /workdir --user 0 | |
run: | | |
apt-get update | |
apt-get install -y xz-utils | |
( | |
cd keycloak-user-migration | |
sh ./mvnw clean package | |
cp target/*.jar app.jar | |
tar --xz -cvf ../plugins.tar.xz *.jar | |
) | |
( | |
cd themes | |
tar --xz -cvf ../themes.tar.xz * | |
) | |
- name: Create Release - Keycloak (Connect) | |
uses: softprops/action-gh-release@v1 | |
id: create_release | |
with: | |
name: "${{ env.TAG }}" | |
files: | | |
plugins.tar.xz | |
themes.tar.xz | |
- name: Check out Kubernetes Manifests | |
uses: actions/checkout@master | |
with: | |
ref: main | |
repository: "${{ env.MANIFESTS_REPOSITORY }}" | |
token: "${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }}" | |
path: ./kubernetes-manifests/ | |
- name: Update version on keycloak application | |
run: | | |
which jq > /dev/null 2>&1 || ( sudo apt update ; sudo apt install -y jq ) | |
# Dep: coreutils | |
verlte() { | |
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] | |
} | |
verlt(){ | |
[ "$1" = "$2" ] && return 1 || verlte $1 $2 | |
} | |
export PROJECT_DIR="${{ env.MANIFESTS_APPLICATION }}" | |
ENV_DIR="kubernetes-manifests/${{ env.MANIFESTS_APPLICATION }}/${MANIFESTS_ENVIRONMENT}" | |
for e in ${ENV_DIR}; do | |
echo "Update ${e}:" | |
if [ ! -d "${e}" ] ; then | |
echo "${e}: Does not exist, skipping" | |
elif [ ! -r "${e}/kustomization.yaml" ] ; then | |
echo "${e}/kustomization.yaml: Does not readable, skipping" | |
elif [ ! -r "${e}/${{ env.MANIFESTS_PATCH_TARGET }}" ] ; then | |
echo "${e}/${{ env.MANIFESTS_PATCH_TARGET }}: Does not readable, skipping" | |
else | |
OLD_IMAGE=$( | |
cat "${e}/${{ env.MANIFESTS_PATCH_TARGET }}" \ | |
| jq '.[] | select(.path == "/spec/template/spec/initContainers/0/env/0/value") | .value' | |
) | |
echo "Old image to replace: ${OLD_IMAGE}" | |
OLD_VERSION=$( | |
echo "${OLD_IMAGE}" \ | |
| sed s'/^.*[v:-]\([0-9]*\.[0-9]*\.[0-9]*\).*$/\1/'g \ | |
| head -n1 | |
) | |
echo "Old image version to compare: ${OLD_VERSION}<=${{env.VERSION}}" | |
if verlte "${OLD_VERSION}" "${VERSION}" || [[ ! "${OLD_VERSION}" =~ [0-9]+\.[0-9]+\.[0-9]+ ]] ; then | |
echo 'New configurations Themes:' | |
new_configuration=$( | |
cat "${e}/${{ env.MANIFESTS_PATCH_TARGET }}" \ | |
| jq '(..|select(.path == "/spec/template/spec/initContainers/0/env/0/value")?) += {value: "https://github.com/weni-ai/connect-keycloak/releases/download/'"${{env.TAG}}"'/themes.tar.xz"}' | |
) | |
echo "${new_configuration}" | |
echo "${new_configuration}" > "${e}/${{ env.MANIFESTS_PATCH_TARGET }}" | |
echo 'New configurations Plugins:' | |
new_configuration=$( | |
cat "${e}/${{ env.MANIFESTS_PATCH_TARGET }}" \ | |
| jq '(..|select(.path == "/spec/template/spec/initContainers/0/env/1/value")?) += {value: "https://github.com/weni-ai/connect-keycloak/releases/download/'"${{env.TAG}}"'/plugins.tar.xz"}' | |
) | |
echo "${new_configuration}" | |
echo "${new_configuration}" > "${e}/${{ env.MANIFESTS_PATCH_TARGET }}" | |
else | |
echo "Version in file is greater than build, skipping update yaml" | |
fi | |
fi | |
done | |
- name: Commit & Push changes | |
uses: actions-js/push@master | |
with: | |
github_token: "${{ secrets.DEVOPS_GITHUB_PERMANENT_TOKEN }}" | |
repository: "${{ env.MANIFESTS_REPOSITORY }}" | |
directory: ./kubernetes-manifests/ | |
branch: main | |
message: "From Keycloak (Connect) Build (Push Tag ${{ env.MANIFESTS_ENVIRONMENT }})" | |