From 097cec2560ba630ef99bf958bef9d645c2ab136d Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Wed, 18 Dec 2024 14:18:47 -0800 Subject: [PATCH] chore: updating workflow order --- .github/workflows/.tools-cleanup.yml | 37 +++++++++++++++++++++++++ .github/workflows/.tools-deploy.yml | 41 ++++++++++++---------------- .github/workflows/pr-close.yml | 36 +++--------------------- .github/workflows/pr-open.yml | 9 ++---- 4 files changed, 60 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/.tools-cleanup.yml diff --git a/.github/workflows/.tools-cleanup.yml b/.github/workflows/.tools-cleanup.yml new file mode 100644 index 000000000..015fd2feb --- /dev/null +++ b/.github/workflows/.tools-cleanup.yml @@ -0,0 +1,37 @@ +name: Tools environment cleanup + +on: + workflow_call: + +jobs: + tools-cleanup: + name: Cleanup tools environment + environment: tools + runs-on: ubuntu-24.04 + steps: + - name: Install CLI tools from OpenShift Mirror + uses: redhat-actions/openshift-tools-installer@v1 + with: + oc: "4.13" + + - name: Remove the PR database + continue-on-error: true + run: | + oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }} + oc project ${{ secrets.OC_NAMESPACE }} # Safeguard! + # This removes a new pluggable database, user and service for the PR + for i in {1..5}; do + POD_NAME=$(oc get pods -l app=nr-forest-client-tools -l deployment=nr-forest-client-tools-legacydb -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) + if [ -n "$POD_NAME" ]; then + echo "Pod found: $POD_NAME" + oc exec $POD_NAME -- /opt/oracle/removeDatabase "THE" "PR_${{ github.event.number }}" + break + else + echo "Pod not found, retrying in 10 seconds... ($i/5)" + sleep 10 + fi + done + + if [ -z "$POD_NAME" ]; then + echo "Failed to find the pod after 5 attempts." + fi \ No newline at end of file diff --git a/.github/workflows/.tools-deploy.yml b/.github/workflows/.tools-deploy.yml index bacabecf1..828b9abc5 100644 --- a/.github/workflows/.tools-deploy.yml +++ b/.github/workflows/.tools-deploy.yml @@ -1,7 +1,7 @@ name: Tools deployment on: - workflow_call: + pull_request: concurrency: # PR open and close use the same group, allowing only one at a time @@ -56,8 +56,8 @@ jobs: sleep 5 done - deploy-tools: - name: Deploy Tools + deploy-oracle: + name: Deploy Oracle Database needs: [pre-tools, builds] environment: tools runs-on: ubuntu-24.04 @@ -78,31 +78,24 @@ jobs: -p ORACLEDB_USER_W=THE -p ORACLEDB_PASSWORD_W=${{ secrets.ORACLEDB_PASSWORD_W }} -p TAG=latest + + remove-tools: + name: Remove database and user + needs: [deploy-oracle] + secrets: inherit + uses: ./.github/workflows/.tools-cleanup.yml + + deploy-tools: + name: Deploy Tools + needs: [pre-tools, builds, deploy-oracle] + environment: tools + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 - name: Install CLI tools from OpenShift Mirror uses: redhat-actions/openshift-tools-installer@v1 with: oc: "4.13" - - name: Remove the PR database - continue-on-error: true - run: | - oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }} - oc project ${{ secrets.OC_NAMESPACE }} # Safeguard! - # This removes a new pluggable database, user and service for the PR - for i in {1..5}; do - POD_NAME=$(oc get pods -l app=nr-forest-client-tools -l deployment=nr-forest-client-tools-legacydb -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) - if [ -n "$POD_NAME" ]; then - echo "Pod found: $POD_NAME" - oc exec $POD_NAME -- /opt/oracle/removeDatabase "THE" "PR_${{ github.event.number }}" - break - else - echo "Pod not found, retrying in 10 seconds... ($i/5)" - sleep 10 - fi - done - - if [ -z "$POD_NAME" ]; then - echo "Failed to find the pod after 5 attempts." - fi - name: Create the PR database continue-on-error: true diff --git a/.github/workflows/pr-close.yml b/.github/workflows/pr-close.yml index e70757b5a..fbb0d47f9 100644 --- a/.github/workflows/pr-close.yml +++ b/.github/workflows/pr-close.yml @@ -20,35 +20,7 @@ jobs: cleanup: label packages: backend database frontend legacy processor - tools-cleanup: - name: Cleanup tools environment - needs: [cleanup] - environment: tools - runs-on: ubuntu-24.04 - steps: - - name: Install CLI tools from OpenShift Mirror - uses: redhat-actions/openshift-tools-installer@v1 - with: - oc: "4.13" - - - name: Remove the PR database - continue-on-error: true - run: | - oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }} - oc project ${{ secrets.OC_NAMESPACE }} # Safeguard! - # This removes a new pluggable database, user and service for the PR - for i in {1..5}; do - POD_NAME=$(oc get pods -l app=nr-forest-client-tools -l deployment=nr-forest-client-tools-legacydb -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) - if [ -n "$POD_NAME" ]; then - echo "Pod found: $POD_NAME" - oc exec $POD_NAME -- /opt/oracle/removeDatabase "THE" "PR_${{ github.event.number }}" - break - else - echo "Pod not found, retrying in 10 seconds... ($i/5)" - sleep 10 - fi - done - - if [ -z "$POD_NAME" ]; then - echo "Failed to find the pod after 5 attempts." - fi + remove-tools: + name: Remove database and user + secrets: inherit + uses: ./.github/workflows/.tools-cleanup.yml diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 4dd524d48..c3905067d 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -21,11 +21,6 @@ jobs: run: | echo "url=${{ github.event.repository.name }}-$((${{ github.event.number }} % 50))-frontend.apps.silver.devops.gov.bc.ca" >> $GITHUB_OUTPUT - deploy-tools: - name: Tools Deployment - secrets: inherit - uses: ./.github/workflows/.tools-deploy.yml - builds: name: Builds runs-on: ubuntu-24.04 @@ -47,7 +42,7 @@ jobs: deploy: name: Deploy Application - needs: [builds, deploy-tools, vars] + needs: [builds, vars] environment: dev runs-on: ubuntu-24.04 steps: @@ -238,7 +233,7 @@ jobs: results: name: PR Results - needs: [builds, deploy, tests, deploy-tools] + needs: [builds, deploy, tests] if: always() runs-on: ubuntu-24.04 steps: