Skip to content

Add ingress testing mode for Kots installation #34

Add ingress testing mode for Kots installation

Add ingress testing mode for Kots installation #34

name: Delete Branch Changes
on:
pull_request:
types: [closed, unlabeled] # Trigger on close and unlabel events in pull requests
jobs:
delete-changes:
timeout-minutes: 3
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Replicated CLI
shell: bash
run: |
curl -s https://api.github.com/repos/replicatedhq/replicated/releases/latest \
| grep "browser_download_url.*linux_amd64.tar.gz" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -O replicated.tar.gz -qi -
tar xf replicated.tar.gz replicated && rm replicated.tar.gz
mv replicated /usr/local/bin/replicated
- name: Generate channel name
id: generate-channel-info
shell: bash
run: |
GITHUB_BRANCH_NAME=${GITHUB_HEAD_REF}
# Cleaning refs/*/
# refs/whatever/main => main
export GITHUB_BRANCH_NAME=${GITHUB_BRANCH_NAME#refs/[a-z]*/}
# Normalize image tags characters
# my-branch/test-01 => my-branch_test-01
export NORMALIZED_GIT_BRANCH_NAME=${GITHUB_BRANCH_NAME//[^[:alnum:]]/_}
# To lowercase all characters
export NORMALIZED_GIT_BRANCH_NAME=${NORMALIZED_GIT_BRANCH_NAME,,}
# Set maximum 128 characters for image name
export NORMALIZED_GIT_BRANCH_NAME=${NORMALIZED_GIT_BRANCH_NAME:0:127}
# Share the variable for further steps
echo "channel-name=${NORMALIZED_GIT_BRANCH_NAME}" >> "$GITHUB_OUTPUT"
echo "version=$(yq .version -r chart/Chart.yaml)" >> "$GITHUB_OUTPUT"
- name: Check if channel assigned to PR exists
id: check-if-channel-exists
shell: bash
env:
REPLICATED_APP: carto
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_API_TOKEN }}
run: |
set -eu
CHANNEL_DELETE_REQUIRED="false"
if replicated channel ls | grep -q ${{ steps.generate-channel-info.outputs.channel-name }}; then
CHANNEL_DELETE_REQUIRED="true"
CHANNEL_ID=$(replicated channel ls | grep ${{ steps.generate-channel-info.outputs.channel-name }} | awk '{print $1}')
echo "channel-id=${CHANNEL_ID}" >> "$GITHUB_OUTPUT"
fi
echo "channel-exists=${CHANNEL_DELETE_REQUIRED}" >> ${GITHUB_OUTPUT}
- name: Unassign customers from channel
if: steps.check-if-channel-exists.outputs.channel-exists == 'true'
shell: bash
env:
REPLICATED_APP: carto
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_API_TOKEN }}
run: |
set -eu
echo "::group::Updating customers to Stable channel"
CUSTOMERS=$(replicated customer ls | grep ${{ steps.generate-channel-info.outputs.channel-name }})
while IFS= read -r customer; do
CUSTOMER_ID=$(echo $customer | awk '{print $1}')
CUSTOMER_NAME=$(echo $customer | awk '{print $2}')
replicated customer update \
--channel "Stable" \
--name "${CUSTOMER_NAME}" \
--customer "${CUSTOMER_ID}"
done <<< "$CUSTOMERS"
echo "::endgroup::"
- name: Delete channel
if: steps.check-if-channel-exists.outputs.channel-exists == 'true'
shell: bash
env:
REPLICATED_APP: carto
REPLICATED_API_TOKEN: ${{ secrets.REPLICATED_API_TOKEN }}
run: |
replicated channel rm ${{ steps.check-if-channel-exists.outputs.channel-id }}