1
+ #! /bin/bash
2
+
3
+ # Check for missing migration tests when SDKv2 resources are replaced with TFP resources
4
+ # Usage: check_migration_tests.sh <base_ref>
5
+
6
+ set -e
7
+
8
+ BASE_REF=${1:- origin/ main}
9
+ CURRENT_REF=${GITHUB_REF:- HEAD}
10
+
11
+ echo " Checking for migration tests between $BASE_REF and $CURRENT_REF "
12
+
13
+ # Get deleted SDKv2 and new TFP resources
14
+ deleted_sdkv2=$( git diff --name-status $BASE_REF ..$CURRENT_REF | grep ' ^D.*octopusdeploy/resource_.*\.go$' | grep -v ' _test\.go$' || true)
15
+ new_tfp=$( git diff --name-status $BASE_REF ..$CURRENT_REF | grep ' ^A.*octopusdeploy_framework/resource_.*\.go$' | grep -v ' _test\.go$' | grep -v ' _migration_test\.go$' || true)
16
+
17
+ if [ ! -z " $deleted_sdkv2 " ] && [ ! -z " $new_tfp " ]; then
18
+ missing_tests=" "
19
+
20
+ # Extract resource names and check for matches
21
+ for deleted_file in $deleted_sdkv2 ; do
22
+ deleted_resource=$( echo " $deleted_file " | sed ' s/.*resource_\(.*\)\.go$/\1/' )
23
+
24
+ for new_file in $new_tfp ; do
25
+ new_resource=$( echo " $new_file " | sed ' s/.*resource_\(.*\)\.go$/\1/' )
26
+
27
+ if [ " $deleted_resource " = " $new_resource " ]; then
28
+ migration_test=" octopusdeploy_framework/resource_${deleted_resource} _migration_test.go"
29
+
30
+ # Check if migration test exists or is being added
31
+ if ! git diff --name-status $BASE_REF ..$CURRENT_REF | grep -q " $migration_test " && [ ! -f " $migration_test " ]; then
32
+ missing_tests=" $missing_tests $deleted_resource "
33
+ fi
34
+ fi
35
+ done
36
+ done
37
+
38
+ if [ ! -z " $missing_tests " ]; then
39
+ echo " ::error::Migration tests required when replacing SDKV2 resources with TFP resources."
40
+ echo " Missing migration tests for:$missing_tests "
41
+ echo " Required files:"
42
+ for resource in $missing_tests ; do
43
+ echo " - octopusdeploy_framework/resource_${resource} _migration_test.go"
44
+ done
45
+ exit 1
46
+ fi
47
+ fi
48
+
49
+ echo " ::notice::Migration test requirements satisfied."
0 commit comments