Skip to content

Commit

Permalink
refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tope Emmanuel committed Oct 9, 2023
1 parent bd790b7 commit 7e2cd8a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/actions/deploy_v2/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ inputs:
outputs:
deploy-url:
value: ${{ steps.set_env_var.outputs.deploy_url }}
dsi-hostname:
value: ${{ steps.terraform-output.outputs.dsi_hostname }}
runs:
using: composite
steps:
Expand Down Expand Up @@ -67,3 +69,9 @@ runs:
make ci ${envval} terraform-apply-aks PR_NUMBER=${{ inputs.pr }}
env:
IMAGE_TAG: ${{ steps.sha.outputs.short }}

- name: Export terraform output
shell: bash
id: terraform-output
run: |
echo "dsi_hostname=$(terraform -chdir=terraform/aks output dsi_hostname)" >> $GITHUB_OUTPUT
20 changes: 6 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,6 @@ jobs:
if_true: ':white_check_mark: DfE sign in route obtained: https://${{env.STATIC_ROUTE}}.london.cloudapps.digital'
if_false: ':warning: **DfE sign in route pool exhausted (close some open PRs!)**'

- name: Determine DfE Sign In Message - AKS
uses: haya14busa/action-cond@v1
id: dsiMessage_aks
with:
cond: ${{ env.dsi_hostname != '' }}
if_true: ':white_check_mark: DfE sign in route obtained: ${{env.dsi_hostname}}'
if_false: ':warning: **DfE sign in route pool for aks exhausted (close some open PRs!)**'


- name: Post sticky pull request comment
if: matrix.environment == 'Review'
uses: marocchino/sticky-pull-request-comment@v2
Expand Down Expand Up @@ -559,21 +550,22 @@ jobs:
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}


- name: Trigger Deployment to ${{matrix.environment}}
id: deploy-aks
uses: ./.github/workflows/actions/deploy_v2
with:
environment: ${{matrix.environment}}
sha: ${{ github.sha }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
pr: ${{github.event.number}}

- name: Determine DfE Sign In Message
- name: Determine DfE Sign In Message - AKS
uses: haya14busa/action-cond@v1
id: dsiMessage
with:
cond: ${{ env.STATIC_ROUTE != '' }}
if_true: ':white_check_mark: DfE sign in route obtained: https://${{env.STATIC_ROUTE}}.london.cloudapps.digital'
if_false: ':warning: **DfE sign in route pool exhausted (close some open PRs!)**'
cond: ${{ steps.deploy-aks.outputs.dsi-hostname != '' }}
if_true: ':white_check_mark: DfE sign in route obtained: https://${{ steps.deploy-aks.outputs.dsi-hostname }}'
if_false: ':warning: **DfE sign in route pool for aks exhausted (close some open PRs!)**'

- name: Post sticky pull request comment
if: matrix.environment == 'Review'
Expand Down
31 changes: 17 additions & 14 deletions script/get_next_mapping_aks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ check_existing_dsi_ingress() {
# Find if it is already in the list of existing linked DSI ingresses
servicename="get-school-experience-review-pr-${pr_number}"
ings=($(kubectl get ing -o=custom-columns='NAME:.metadata.name,SVCs:..service.name' -n git-development | grep "${servicename}" | grep -v "${pr_name}"))
echo "$ings"
echo "${ings}"
}

extract_numbers_from_list() {
local all_existing_ings=("$@")
local all_existing_ings=$1
local pattern="get-school-experience-review-pr-([0-9]+)\.test\.teacherservices\.cloud"
local all_existing_review_ings=()
for input_string in "${all_existing_ings[@]}"; do
for input_string in ${all_existing_ings}; do
if [[ "$input_string" =~ $pattern ]]; then
itemval="${BASH_REMATCH[1]}"
if ((1 <= $itemval <= $maximun_ing_num)); then
if ((1 <= itemval && itemval <= maximun_ing_num)); then
all_existing_review_ings+=("${BASH_REMATCH[1]}")
fi
fi
Expand All @@ -38,9 +38,10 @@ extract_numbers_from_list() {
}

is_number_in_list() {
local all_list="$1"
local number="$2"
for i in $all_list; do
local number=$1
shift
local all_list=$*
for i in ${all_list}; do
if [ "$i" = "$number" ]; then
return 0
fi
Expand All @@ -59,16 +60,18 @@ else

# extract the number part of the ingresses from ingress lists
numbers_from_ings=$(extract_numbers_from_list "${ings_list_result[@]}")
all_possible_ings=$(echo {1..20})
numbers_from_ings+=(1 2 3 4 5 6 8 9 10 11 12 13 14 15 17 18 19 20 )
echo "${numbers_from_ings[@]}"
all_possible_ings=$(seq 1 $maximun_ing_num)
selectednumber=0
for possible_ing in "${all_possible_ings[@]}"; do
if ! is_number_in_list "$numbers_from_ings" "$possible_ing" ; then
selectednumber=$possible_ing
break
for possible_ing in ${all_possible_ings}; do
if ! is_number_in_list "$possible_ing" "${numbers_from_ings[@]}" ; then
selectednumber=$possible_ing
break
fi
done
if selectednumber=0 ; then
echo ""
if [ "$selectednumber" = 0 ]; then
echo ""
else
echo "get-school-experience-review-pr-$selectednumber.test.teacherservices.cloud"
fi
Expand Down
3 changes: 3 additions & 0 deletions terraform/aks/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "dsi_hostname" {
value = var.dsi_hostname
}

0 comments on commit 7e2cd8a

Please sign in to comment.