Skip to content

Commit 5cb4866

Browse files
committed
Make it possible to run incremental or full mutation tests depending on scenario:
- full for master branch push - full if certain text is found in PR or commit description - incremental is default for all other PRs - incremental is default for branches other than master
1 parent f6d1955 commit 5cb4866

File tree

2 files changed

+121
-11
lines changed

2 files changed

+121
-11
lines changed

.github/workflows/pricing.yml

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,85 @@ on:
44
pull_request:
55
types: [opened, reopened]
66
jobs:
7+
determine_run_parameters:
8+
runs-on: ubuntu-24.04
9+
outputs:
10+
mutant_mode: ${{ steps.set_params.outputs.mutant_mode }}
11+
mutant_since_target: ${{ steps.set_params.outputs.mutant_since_target }}
12+
num_groups: ${{ steps.set_params.outputs.num_groups }}
13+
steps:
14+
- name: Determine Mutation Run Parameters
15+
id: set_params
16+
shell: bash
17+
run: |
18+
echo "--- Debug: Determining mutation run parameters for pricing ---"
19+
echo "Event name: ${{ github.event_name }}"
20+
echo "Ref name: ${{ github.ref_name }}"
21+
echo "Base ref (for PR): ${{ github.event.pull_request.base.ref }}"
22+
echo "PR title: ${{ github.event.pull_request.title }}"
23+
COMMIT_MESSAGES_LOG=$(echo "${{ join(github.event.commits.*.message, ' // ') }}" | head -c 500)
24+
echo "Commit messages in push (first 500 chars): ${COMMIT_MESSAGES_LOG}..."
25+
CONTAINS_MUTATE_FULL_IN_PUSH=$([[ "${{ contains(join(github.event.commits.*.message, ' '), '[mutate-full]') }}" == "true" ]] && echo "true" || echo "false")
26+
echo "Contains '[mutate-full]' in push commit messages: $CONTAINS_MUTATE_FULL_IN_PUSH"
27+
CONTAINS_MUTATE_FULL_IN_PR_TITLE=$([[ "${{ contains(github.event.pull_request.title, '[mutate-full]') }}" == "true" ]] && echo "true" || echo "false")
28+
echo "Contains '[mutate-full]' in PR title: $CONTAINS_MUTATE_FULL_IN_PR_TITLE"
29+
CONTAINS_MUTATE_FULL_IN_PR_BODY=$([[ "${{ contains(github.event.pull_request.body, '[mutate-full]') }}" == "true" ]] && echo "true" || echo "false")
30+
echo "Contains '[mutate-full]' in PR body: $CONTAINS_MUTATE_FULL_IN_PR_BODY"
31+
echo "---------------------------------------------"
32+
33+
FINAL_MUTANT_MODE="full"
34+
FINAL_NUM_GROUPS=32
35+
FINAL_SINCE_TARGET=""
36+
37+
IS_MUTATE_FULL_TRIGGERED="false"
38+
if [[ "${{ github.event_name }}" == "pull_request" && \
39+
( "$CONTAINS_MUTATE_FULL_IN_PR_TITLE" == "true" || "$CONTAINS_MUTATE_FULL_IN_PR_BODY" == "true" ) ]]; then
40+
echo "Logic path: [mutate-full] in PR title/body."
41+
IS_MUTATE_FULL_TRIGGERED="true"
42+
elif [[ "${{ github.event_name }}" == "push" && "$CONTAINS_MUTATE_FULL_IN_PUSH" == "true" ]]; then
43+
echo "Logic path: [mutate-full] in push commit message(s)."
44+
IS_MUTATE_FULL_TRIGGERED="true"
45+
fi
46+
47+
if [[ "$IS_MUTATE_FULL_TRIGGERED" == "true" ]]; then
48+
echo "Action: Mode set to 'full' (NUM_GROUPS=32) due to [mutate-full] trigger."
49+
FINAL_MUTANT_MODE="full"
50+
FINAL_NUM_GROUPS=32
51+
else
52+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
53+
echo "Logic path: Pull request event (no [mutate-full] trigger)."
54+
echo "Action: Mode set to 'incremental' (NUM_GROUPS=4) for PR."
55+
FINAL_MUTANT_MODE="incremental"
56+
FINAL_NUM_GROUPS=4
57+
FINAL_SINCE_TARGET="origin/${{ github.event.pull_request.base.ref }}"
58+
echo "Incremental target: $FINAL_SINCE_TARGET"
59+
elif [[ "${{ github.event_name }}" == "push" ]]; then
60+
if [[ "${{ github.ref_name }}" == "master" || "${{ github.ref_name }}" == "main" ]]; then
61+
echo "Logic path: Push event to main branch (no [mutate-full] trigger)."
62+
echo "Action: Mode set to 'full' (NUM_GROUPS=32) for main branch."
63+
FINAL_MUTANT_MODE="full"
64+
FINAL_NUM_GROUPS=32
65+
else
66+
echo "Logic path: Push event to non-main branch ('${{ github.ref_name }}') (no [mutate-full] trigger)."
67+
echo "Action: Mode set to 'incremental' (NUM_GROUPS=4) for branch push."
68+
FINAL_MUTANT_MODE="incremental"
69+
FINAL_NUM_GROUPS=4
70+
FINAL_SINCE_TARGET="origin/master"
71+
echo "Incremental target: $FINAL_SINCE_TARGET"
72+
fi
73+
fi
74+
fi
75+
76+
echo "mutant_mode=${FINAL_MUTANT_MODE}" >> $GITHUB_OUTPUT
77+
echo "mutant_since_target=${FINAL_SINCE_TARGET}" >> $GITHUB_OUTPUT
78+
echo "num_groups=${FINAL_NUM_GROUPS}" >> $GITHUB_OUTPUT
79+
80+
echo "--- Final Parameters for pricing ---"
81+
echo "Mutant Mode: ${FINAL_MUTANT_MODE}"
82+
echo "Mutant Since Target: ${FINAL_SINCE_TARGET}"
83+
echo "Num Groups: ${FINAL_NUM_GROUPS}"
84+
echo "------------------------"
85+
786
test:
887
runs-on: ubuntu-24.04
988
strategy:
@@ -27,7 +106,7 @@ jobs:
27106
{
28107
attachments: [{
29108
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
30-
text: `${process.env.AS_WORKFLOW}/${{ github.job }} ${{ job.status }} in ${process.env.AS_TOOK}\n${process.env.AS_COMMIT} in ${process.env.AS_REF}`,
109+
text: `${process.env.AS_WORKFLOW}/${{ github.job }} ${{ job.status }} in ${process.env.AS_TOOK}\n${process.env.AS_COMMIT} in ${process.env.AS_REF} for pricing`,
31110
}]
32111
}
33112
env:
@@ -37,12 +116,15 @@ jobs:
37116

38117
prepare_mutation_subjects_pricing:
39118
runs-on: ubuntu-24.04
119+
needs: determine_run_parameters
40120
outputs:
41121
subject_groups: ${{ steps.split_subjects.outputs.subject_groups }}
42122
env:
43123
WORKING_DIRECTORY: ecommerce/pricing
44124
steps:
45125
- uses: actions/checkout@v3
126+
with:
127+
fetch-depth: 0
46128
- uses: ruby/setup-ruby@v1
47129
with:
48130
ruby-version: ruby-3.3.7
@@ -51,8 +133,11 @@ jobs:
51133
- name: List and split subjects for pricing
52134
id: split_subjects
53135
working-directory: ${{ env.WORKING_DIRECTORY }}
136+
env:
137+
NUM_GROUPS_FROM_CI: ${{ needs.determine_run_parameters.outputs.num_groups }}
54138
run: |
55-
SUBJECT_LIST_OUTPUT=$(RAILS_ENV=test bundle exec mutant environment subject list)
139+
echo "--- Preparing subjects for pricing ---"
140+
SUBJECT_LIST_OUTPUT=$(bundle exec mutant environment subject list)
56141
57142
mapfile -t subjects_array < <( \
58143
echo "$SUBJECT_LIST_OUTPUT" | \
@@ -69,7 +154,9 @@ jobs:
69154
fi
70155
71156
total_subjects=${#subjects_array[@]}
72-
NUM_GROUPS=32 # Define the number of parallel jobs
157+
NUM_GROUPS=${NUM_GROUPS_FROM_CI:-4}
158+
echo "Total subjects found: $total_subjects"
159+
echo "Number of parallel groups to create: $NUM_GROUPS"
73160
groups_json_array_content=""
74161
75162
for (( i=0; i<NUM_GROUPS; i++ )); do
@@ -90,9 +177,10 @@ jobs:
90177
done
91178
echo "Generated subject_groups for pricing: [$groups_json_array_content]"
92179
echo "subject_groups=[$groups_json_array_content]" >> $GITHUB_OUTPUT
180+
echo "-----------------------------------"
93181
94182
mutate:
95-
needs: prepare_mutation_subjects_pricing
183+
needs: [determine_run_parameters, prepare_mutation_subjects_pricing]
96184
if: ${{ needs.prepare_mutation_subjects_pricing.outputs.subject_groups != '[]' && needs.prepare_mutation_subjects_pricing.outputs.subject_groups != '' }}
97185
runs-on: ubuntu-24.04
98186
strategy:
@@ -101,14 +189,19 @@ jobs:
101189
subject_group: ${{ fromJson(needs.prepare_mutation_subjects_pricing.outputs.subject_groups) }}
102190
env:
103191
WORKING_DIRECTORY: ecommerce/pricing
192+
MUTANT_MODE: ${{ needs.determine_run_parameters.outputs.mutant_mode }}
193+
MUTANT_SINCE_TARGET: ${{ needs.determine_run_parameters.outputs.mutant_since_target }}
104194
steps:
105195
- uses: actions/checkout@v3
196+
with:
197+
fetch-depth: 0
106198
- uses: ruby/setup-ruby@v1
107199
with:
108200
ruby-version: ruby-3.3.7
109201
bundler-cache: true
110202
working-directory: ${{ env.WORKING_DIRECTORY }}
111-
- run: make mutate
203+
- name: Run mutation tests (parallel group for pricing)
204+
run: make mutate
112205
working-directory: ${{ env.WORKING_DIRECTORY }}
113206
env:
114207
CI_MUTATE_SUBJECTS: ${{ matrix.subject_group }}
@@ -141,4 +234,4 @@ jobs:
141234
}]
142235
}
143236
env:
144-
SLACK_WEBHOOK_URL: ${{ secrets.CI_WEBHOOK }}
237+
SLACK_WEBHOOK_URL: ${{ secrets.CI_WEBHOOK }}

ecommerce/pricing/Makefile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@ install:
22
@bundle install
33

44
test:
5+
@echo "Running unit tests for pricing"
56
@bundle exec ruby -e "require \"rake/rake_test_loader\"" test/*_test.rb
67

78
mutate:
8-
ifeq ($(CI_MUTATE_SUBJECTS),)
9-
@echo "Running all mutation tests (local or full CI run)"
10-
@env RAILS_ENV=test bundle exec mutant run
9+
$(eval ACTUAL_MUTANT_ARGS :=)
10+
$(eval SUBJECTS_TO_RUN := $(strip $(CI_MUTATE_SUBJECTS)))
11+
12+
@echo "--- Preparing Mutation Test Run for pricing ---"
13+
ifeq ($(MUTANT_MODE),incremental)
14+
ifndef MUTANT_SINCE_TARGET
15+
$(error MUTANT_MODE is 'incremental', but MUTANT_SINCE_TARGET is not set. This variable should be set by the CI workflow.)
16+
endif
17+
$(eval ACTUAL_MUTANT_ARGS := --since $(MUTANT_SINCE_TARGET))
18+
@echo "Mutation Mode: Incremental"
19+
@echo "Target for --since: $(MUTANT_SINCE_TARGET)"
20+
else
21+
@echo "Mutation Mode: Full"
22+
endif
23+
24+
ifeq ($(SUBJECTS_TO_RUN),)
25+
@echo "Subjects: All relevant (within scope of full/incremental mode)"
1126
else
12-
@echo "Running CI mutation tests for subjects: $(CI_MUTATE_SUBJECTS)"
13-
@env RAILS_ENV=test bundle exec mutant run $(CI_MUTATE_SUBJECTS)
27+
@echo "Subjects: Specific group for CI - '$(SUBJECTS_TO_RUN)'"
1428
endif
29+
@echo "------------------------------------"
30+
@echo "Executing: bundle exec mutant run $(ACTUAL_MUTANT_ARGS) $(SUBJECTS_TO_RUN)"
31+
@bundle exec mutant run $(ACTUAL_MUTANT_ARGS) $(SUBJECTS_TO_RUN)
1532

1633
.PHONY: install test mutate

0 commit comments

Comments
 (0)