-
Notifications
You must be signed in to change notification settings - Fork 178
155 lines (139 loc) · 6.66 KB
/
analyses-snapshot-test.yaml
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
name: Analyses Snapshot Test
on:
workflow_dispatch:
inputs:
ANALYSIS_REF:
description: 'Branch or tag that provides the analysis output at test runtime'
required: true
default: 'edge'
SNAPSHOT_REF:
description: 'Branch or tag that provides the snapshot and test code at test runtime'
required: true
default: 'edge'
OPEN_PR_ON_FAILURE:
description: 'If the test fails, open a PR to update the snapshots'
type: boolean
required: true
default: false
schedule:
- cron: '26 7 * * *' # 7:26 AM UTC
pull_request:
paths:
- 'api/**'
- '!api/tests/**'
- '!api/docs/**'
- '!api/release-notes-internal.md'
- '!api/release-notes.md'
- 'shared-data/**/*'
- '!shared-data/js/**'
- '.github/workflows/analyses-snapshot-test.yaml'
- 'analyses-snapshot-testing/**'
types:
- opened #default
- synchronize #default
- reopened #default
- labeled
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build-and-test:
timeout-minutes: 15
runs-on: ubuntu-latest
env:
BASE_IMAGE_NAME: opentrons-python-base:3.10
ANALYSIS_REF: ${{ github.event.inputs.ANALYSIS_REF || github.head_ref || 'edge' }}
SNAPSHOT_REF: ${{ github.event.inputs.SNAPSHOT_REF || github.head_ref || 'edge' }}
# If we're running because of workflow_dispatch, use the user input to decide
# whether to open a PR on failure. Otherwise, there is no user input,
# so we only open a PR if the PR has the label 'gen-analyses-snapshot-pr'
OPEN_PR_ON_FAILURE: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.OPEN_PR_ON_FAILURE) || ((github.event_name != 'workflow_dispatch') && (contains(github.event.pull_request.labels.*.name, 'gen-analyses-snapshot-pr'))) }}
PR_TARGET_BRANCH: ${{ github.event.pull_request.base.ref || 'not a pr'}}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ env.SNAPSHOT_REF }}
- name: Are the analyses snapshots in my PR branch in sync with the target branch?
if: github.event_name == 'pull_request'
run: |
git fetch origin ${{ env.PR_TARGET_BRANCH }}
DIFF_OUTPUT=$(git diff HEAD origin/${{ env.PR_TARGET_BRANCH }} -- analyses-snapshot-testing/tests/__snapshots__/analyses_snapshot_test)
if [ -n "$DIFF_OUTPUT" ]; then
echo "Analyses snapshots do NOT match ${{ env.PR_TARGET_BRANCH }} snapshots."
echo "Is this becasue you have not pulled and merged ${{ env.PR_TARGET_BRANCH }}?"
echo "Or is this because you have already updated your snapshots and are all good 😊?"
else
echo "Analyses snapshots match ${{ env.PR_TARGET_BRANCH }} snapshots."
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build base image
id: build_base_image
uses: docker/build-push-action@v6
with:
context: analyses-snapshot-testing/citools
file: analyses-snapshot-testing/citools/Dockerfile.base
push: false
load: true
tags: ${{ env.BASE_IMAGE_NAME }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build analysis image
working-directory: analyses-snapshot-testing
run: make build-opentrons-analysis BASE_IMAGE_NAME=${{ env.BASE_IMAGE_NAME }} ANALYSIS_REF=${{ env.ANALYSIS_REF }} CACHEBUST=${{ github.run_number }}
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.13.0'
cache: 'pipenv'
cache-dependency-path: analyses-snapshot-testing/Pipfile.lock
- name: Setup Python Dependencies
working-directory: analyses-snapshot-testing
run: make setup
- name: Run Test
id: run_test
working-directory: analyses-snapshot-testing
run: make snapshot-test
- name: Upload Report
if: '!cancelled()'
uses: actions/upload-artifact@v4
with:
name: test-report
path: analyses-snapshot-testing/results/
- name: Handle Test Failure
id: handle_failure
if: always() && steps.run_test.outcome == 'failure' && (env.OPEN_PR_ON_FAILURE == 'true' || github.event_name == 'schedule')
working-directory: analyses-snapshot-testing
run: make snapshot-test-update
- name: Create Snapshot update Request
id: create_pull_request
if: always() && steps.handle_failure.outcome == 'success' && env.OPEN_PR_ON_FAILURE == 'true' && github.event_name == 'pull_request'
uses: peter-evans/create-pull-request@v7
with:
commit-message: 'fix(analyses-snapshot-testing): heal analyses snapshots'
title: 'fix(analyses-snapshot-testing): heal ${{ env.ANALYSIS_REF }} snapshots'
body: 'This PR was requested on the PR https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}'
branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF }}'
base: ${{ env.SNAPSHOT_REF }}
- name: Comment on feature PR
if: always() && steps.create_pull_request.outcome == 'success' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const message = 'A PR has been opened to address analyses snapshot changes. Please review the changes here: https://github.com/${{ github.repository }}/pull/${{ steps.create_pull_request.outputs.pull-request-number }}';
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
});
- name: Create Snapshot update Request on edge overnight failure
if: always() && steps.handle_failure.outcome == 'success' && github.event_name == 'schedule'
uses: peter-evans/create-pull-request@v7
with: # scheduled run uses the default values for ANALYSIS_REF and SNAPSHOT_REF which are edge
commit-message: 'fix(analyses-snapshot-testing): heal ${{ env.ANALYSIS_REF }} snapshots'
title: 'fix(analyses-snapshot-testing): heal ${{ env.ANALYSIS_REF }} snapshots'
body: 'The ${{ env.ANALYSIS_REF }} overnight analyses snapshot test is failing. This PR was opened to alert us to the failure.'
branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF }}'
base: ${{ env.SNAPSHOT_REF }}