Skip to content

Commit c8de436

Browse files
committed
Add check-migration-tests job to github workflow
1 parent 8c3dd08 commit c8de436

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Require Tests for SDKv2 to TFP Resource Migrations
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
check-migration-tests:
13+
name: Check Migration Tests Required
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Check for missing migration tests
23+
run: |
24+
chmod +x ci-scripts/helpers/check_migration_tests.sh
25+
ci-scripts/helpers/check_migration_tests.sh origin/main
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)