Skip to content

Commit

Permalink
Update deploy-hubs workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
sgibson91 committed Dec 18, 2024
1 parent b507159 commit be8b0a8
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions .github/workflows/deploy-hubs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ jobs:
# just failed. Data is injected to the script before its executed via
# string literals as rendered GitHub workflow expressions.
- name: Filter staging and prod deploy jobs to run based on failures in support
id: filter-jobs
shell: python
run: |
import os
Expand All @@ -348,22 +349,22 @@ jobs:
outputs = json.loads(r"""${{ toJson(needs.upgrade-support.outputs) }}""")
try:
filtered_staging_jobs = [
staging_job
for staging_job in staging_jobs
if outputs[f"failure_{staging_job['cluster_name'].replace('.', '-')}"] != "true"
]
filtered_prod_jobs = [
prod_job
for prod_job in prod_jobs
if outputs[f"failure_{prod_job['cluster_name'].replace('.', '-')}"] != "true"
]
filtered_staging_jobs = [
staging_job
for staging_job in staging_jobs
if outputs[f"failure_{staging_job['cluster_name'].replace('.', '-')}"] != "true"
]
filtered_prod_jobs = [
prod_job
for prod_job in prod_jobs
if outputs[f"failure_{prod_job['cluster_name'].replace('.', '-')}"] != "true"
]
except KeyError:
print(f"The {cluster_name} cluster wasn't found in the `upgrade-support.outputs` list. Please add it before continuing!")
env_file = os.getenv("GITHUB_ENV")
with open(env_file, "a") as f:
output_file = os.getenv("GITHUB_OUTPUT")
with open(output_file, "a") as f:
f.write(f"filtered-staging-hub-matrix-jobs={json.dumps(filtered_staging_jobs)}\n")
f.write(f"filtered-prod-hub-matrix-jobs={json.dumps(filtered_prod_jobs)}")
Expand All @@ -387,7 +388,7 @@ jobs:

# This job upgrades staging hubs on clusters in parallel, if required. This
# job needs the `filter-failed-support-jobs` to have completed to provide its
# output `filtered-staging-hub-matrix-jobs`. It is a list of dictionaries with
# output `staging-hub-matrix-jobs`. It is a list of dictionaries with
# the keys cluster_name, provider, and hub_name for each staging hub that
# requires an upgrade and didn't have a failed support-upgrade job
# run as part of this workflow.
Expand All @@ -398,12 +399,12 @@ jobs:
!cancelled() &&
(github.event_name == 'push' && contains(github.ref, 'main')) &&
needs.filter-failed-support-jobs.result == 'success' &&
needs.filter-failed-support-jobs.outputs.filtered-staging-hub-matrix-jobs != '[]'
needs.filter-failed-support-jobs.outputs.staging-hub-matrix-jobs != '[]'
strategy:
# Don't stop other deployments if one fails
fail-fast: false
matrix:
jobs: ${{ fromJson(needs.filter-failed-support-jobs.outputs.filtered-staging-hub-matrix-jobs) }}
jobs: ${{ fromJson(needs.filter-failed-support-jobs.outputs.staging-hub-matrix-jobs) }}

# We declare outputs indicating the job failed status of a specific job
# variation. We are currently required to do this in a hardcoded fashion,
Expand Down Expand Up @@ -469,17 +470,19 @@ jobs:
deployer run-hub-health-check ${{ matrix.jobs.cluster_name }} ${{ matrix.jobs.hub_name }}
- name: Declare failure status
id: declare-failure
if: always()
shell: python
run: |
import os
name = "${{ matrix.jobs.cluster_name }}".replace(".", "-")
cluster_name = "${{ matrix.jobs.cluster_name }}".replace(".", "-")
hub_name = "${{ matrix.jobs.hub_name }}"
failure = "${{ job.status == 'failure' }}"
env_file = os.getenv("GITHUB_ENV")
with open(env_file, "a") as f:
f.write(f"failure_{name}={failure}")
output_file = os.getenv("GITHUB_OUTPUT")
with open(output_file, "a") as f:
f.write(f"failure_{cluster_name}_{hub_name}={failure}\n")
# https://github.com/ravsamhq/notify-slack-action
# Needs to be added per job
Expand All @@ -503,15 +506,15 @@ jobs:
# filtering out any deployment to a cluster with a failed staging hub job.
filter-failed-staging-jobs:
runs-on: ubuntu-latest
needs: [generate-jobs, filter-failed-support-jobs, upgrade-staging-hubs]
needs: [filter-failed-support-jobs, upgrade-staging-hubs]
if: |
!cancelled() &&
(github.event_name == 'push' && contains(github.ref, 'main')) &&
needs.generate-jobs.result == 'success' &&
needs.filter-failed-support-jobs.outputs.filtered-prod-hub-matrix-jobs != '[]'
needs.filter-failed-support-jobs == 'success' &&
needs.filter-failed-support-jobs.outputs.prod-hub-matrix-jobs != '[]'
outputs:
refiltered-prod-hub-matrix-jobs: ${{ env.refiltered-prod-hub-matrix-jobs }}
prod-hub-matrix-jobs: ${{ steps.filter-jobs.outputs.filtered-prod-hub-matrix-jobs }}

steps:
# This Python script filters out any prod hub deployment job from running
Expand All @@ -525,17 +528,23 @@ jobs:
import os
import json
prod_jobs = json.loads(r"""${{ needs.filter-failed-support-jobs.outputs.filtered-prod-hub-matrix-jobs }}""")
prod_jobs = json.loads(r"""${{ needs.filter-failed-support-jobs.outputs.prod-hub-matrix-jobs }}""")
outputs = json.loads(r"""${{ toJson(needs.upgrade-staging-hubs.outputs) }}""")
try:
filtered_prod_jobs = [
prod_job
for prod_job in prod_jobs
if outputs[f"failure_{prod_job['cluster_name'].replace('.', '-')}"] != "true"
]
filtered_prod_jobs = []
for prod_job in prod_jobs:
failed_jobs = {
k: v
for k, v in outputs.items()
if prod_job["cluster_name"] in k
and v == "true"
}
if len(failed_jobs) == 0:
filtered_prod_jobs.append(prod_job)
except KeyError:
print(f"The {cluster_name} cluster wasn't found in the `upgrade-staging-hubs.outputs` list. Please add it before continuing!")
print(f"The {cluster_name} cluster wasn't found in the `upgrade-staging-hubs.outputs` list. Please add it before continuing!")
output_file = os.getenv("GITHUB_OUTPUT")
with open(output_file, "a") as f:
Expand Down

0 comments on commit be8b0a8

Please sign in to comment.