-
Notifications
You must be signed in to change notification settings - Fork 3
206 lines (181 loc) · 8.61 KB
/
release-branch-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# **what?**
# The purpose of this workflow is to trigger CI to run for each
# release branch and main branch in a reusable format. If the CI workflow
# fails for a branch, it will post to dev-core-alerts to raise awareness.
# **why?**
# Ensures release branches and main are always shippable and not broken.
# Also, can catch any dependencies shifting beneath us that might
# introduce breaking changes (could also impact Cloud).
# **when?**
# Mainly on a schedule of 9:00, 13:00, 18:00 UTC everyday.
# Manual trigger can also test on demand
name: Release branch scheduled testing
on:
workflow_call:
inputs:
workflows_to_run:
description: 'A list of workflow(s) to run against ex: ["main.yml, "integration.yml"]'
required: true
type: string
# no special access is needed
permissions: read-all
jobs:
prep-work:
name: "Audit Inputs"
runs-on: ubuntu-latest
steps:
- name: "[DEBUG] Print Inputs"
run: |
echo "workflows_to_run: ${{ inputs.workflows_to_run }}"
fetch-latest-branches:
runs-on: ubuntu-latest
outputs:
branches_to_test: ${{ steps.add-main.outputs.full_branch_list }}
steps:
- name: "Fetch ${{ github.event.repository.name }} Latest Branches"
uses: dbt-labs/actions/fetch-repo-branches@main
id: get-latest-branches
with:
repo_name: ${{ github.event.repository.name }}
organization: "dbt-labs"
pat: ${{ secrets.GITHUB_TOKEN }}
fetch_protected_branches_only: true
regex: '^(1.(?:[4-9]|[123]\d)+|[2-9].[0-9]+).latest$' # exclude branches 1.3.latest and below
perform_match_method: "match"
retries: 3
- name: "Add main to branch list"
id: add-main
run: |
full_branch_list="${{ steps.get-latest-branches.outputs.repo-branches }}"
# Swap single and double quotes because bash doesnt interpret correctly
full_branch_list="${full_branch_list//\'/__SINGLE_QUOTE__}"
full_branch_list="${full_branch_list//\"/\'}"
full_branch_list="${full_branch_list//__SINGLE_QUOTE__/\"}"
# now convert it to a bash array and add the main branch
full_branch_list=($(echo "$full_branch_list" | jq -r '.[]'))
for item in "${full_branch_list[@]}"; do echo "$item"; done
full_branch_list+=("main")
# Convert the array to a string
full_branch_list_string=$(printf "'%s', " "${full_branch_list[@]}")
full_branch_list_string="[${full_branch_list_string%, }]"
# Assign the string to a variable
echo $full_branch_list_string
echo "full_branch_list=$full_branch_list_string" >> $GITHUB_OUTPUT
- name: "[ANNOTATION] ${{ github.event.repository.name }} - branches to test"
run: |
title="${{ github.event.repository.name }} - branches to test"
message="The workflow will run tests in ${{ inputs.workflows_to_run }} for the following branches of the ${{ github.event.repository.name }} repo: ${{ steps.add-main.outputs.full_branch_list }}"
echo "::notice $title::$message"
publish_failure_events:
# this runs here just for the previous job. The next job sends one alert per matrix run.
name: "Publish Failure Slack Message"
if: ${{ always() && needs.fetch-latest-branches.result != 'success' }}
needs: [fetch-latest-branches]
runs-on: ubuntu-latest
steps:
- name: Post failure to core Slack
uses: ravsamhq/notify-slack-action@v2
if: ${{ github.event.repository.name == 'dbt-core' || github.event.repository.name == 'dbt-common'}}
with:
status: "failure"
notification_title: '${{ github.event.repository.name }} release branch scheduled testing not successful'
message_format: ':x: Job setup failed'
footer: "<{run_url}|View Run>"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEV_CORE_ALERTS }}
- name: Post failure to adapter Slack
uses: ravsamhq/notify-slack-action@v2
if: ${{ github.event.repository.name != 'dbt-core' }}
with:
status: "failure"
notification_title: '${{ github.event.repository.name }} release branch scheduled testing not successful'
message_format: ':x: Job setup failed'
footer: "<{run_url}|View Run>"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEV_ADAPTER_ALERTS }}
kick-off-ci:
needs: [fetch-latest-branches]
name: Kick-off CI
runs-on: ubuntu-latest
strategy:
# must run CI 1 branch at a time b/c the workflow-dispatch polls for
# latest run for results and it gets confused when we kick off multiple runs
# at once. There is a race condition so we will just run in sequential order.
max-parallel: 1
fail-fast: false
matrix:
workflow_name: ${{ fromJson(inputs.workflows_to_run) }}
branch: ${{ fromJSON(needs.fetch-latest-branches.outputs.branches_to_test) }}
steps:
- name: "[DEBUG] Print Inputs"
run: |
echo "matrix.branch: ${{ matrix.branch }}"
echo "matrix.workflow_name: ${{ matrix.workflow_name }}"
- name: Check out ${{ matrix.branch }}
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
# We have to use a workflow_dispatch here because we're using the matrix branch value.
# Calling a workflow using the `uses` syntax does not give us access to any context so
# we must use hardcoded tags/branches/SHAs. This also means we need to manually monitor
# for when the workflow completes.
- name: Call CI workflow for ${{ matrix.branch }} branch
id: trigger-step
run: |
gh workflow run ${{ matrix.workflow_name }} --ref ${{ matrix.branch }}
env:
GH_TOKEN: ${{ secrets.FISHTOWN_BOT_PAT }}
# If you check for running workflows too fast, the one just submitted won't be there yet
- name: "Wait for it"
id: waiting
run: |
sleep 25s
- name: Get workflow run ID
id: workflow-id
run: |
table=$(gh run list --workflow=${{ matrix.workflow_name }} --branch=${{ matrix.branch }} --event=workflow_dispatch)
echo $table
id=$(echo "$table" | awk 'NR==1' | jq -Rr 'split("\t")[6]')
echo $id
echo "id=$id" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Wait for run to complete
id: monitor-run
uses: nick-fields/retry@v3
with:
timeout_minutes: 180
max_attempts: 3
command: gh run watch ${{ steps.workflow-id.outputs.id }} --interval 300 --exit-status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get slack message details for failed runs
if: ${{ always() && steps.monitor-run.outcome != 'success' }}
id: status-check
run: |
url=$(gh run view ${{ steps.workflow-id.outputs.id }} --json url -q ".url")
echo "workflow-url=$url" >> $GITHUB_OUTPUT
conclusion=$(gh run view ${{ steps.workflow-id.outputs.id }} --json conclusion -q ".conclusion")
echo "workflow-conclusion=$conclusion" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post failure to core Slack
uses: ravsamhq/notify-slack-action@v2
if: ${{ always() && steps.monitor-run.outcome != 'success' && (github.event.repository.name == 'dbt-core' || github.event.repository.name == 'dbt-common')}}
with:
status: ${{ job.status }}
notification_title: '${{ github.event.repository.name }} scheduled run of "${{ matrix.branch }}" branch not successful'
message_format: ':x: CI on branch "${{ matrix.branch }}" ${{ steps.status-check.outputs.workflow-conclusion }}'
footer: 'Linked failed CI run ${{ steps.status-check.outputs.workflow-url }}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEV_CORE_ALERTS }}
- name: Post failure to adapter Slack
uses: ravsamhq/notify-slack-action@v2
if: ${{ always() && steps.monitor-run.outcome != 'success' && github.event.repository.name != 'dbt-core' }}
with:
status: ${{ job.status }}
notification_title: '${{ github.event.repository.name }} scheduled run of "${{ matrix.branch }}" branch not successful'
message_format: ':x: CI on branch "${{ matrix.branch }}" ${{ steps.status-check.outputs.workflow-conclusion }}'
footer: 'Linked failed CI run ${{ steps.status-check.outputs.workflow-url }}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEV_ADAPTER_ALERTS }}