Skip to content

Commit 8e1f033

Browse files
authored
Merge pull request #10 from oozou/terraform-test
test workflow
2 parents c719633 + c735a3f commit 8e1f033

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

.github/workflows/terraform-test.yaml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,41 @@ jobs:
3636
permissions:
3737
pull-requests: write
3838
steps:
39-
- name: Comment on PR
39+
- name: Report failed jobs
4040
uses: actions/github-script@v7
4141
with:
42-
github-token: ${{ secrets.CICD_GH_PAT }} # 👈 MUST be inside 'with', not 'env'
42+
github-token: ${{ secrets.CICD_GH_PAT }}
4343
script: |
44-
const buildUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
45-
const comment = `@claude fix build error:
46-
47-
The Terraform tests have failed. Please check the build logs for details.
48-
49-
**Build Link:** ${buildUrl}
50-
51-
**Failed Job:** ${{ needs.test.result }}
52-
53-
Please review the test failures and fix any issues before merging.`;
54-
55-
github.rest.issues.createComment({
56-
issue_number: context.issue.number,
44+
const run_id = process.env.GITHUB_RUN_ID;
45+
const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
5746
owner: context.repo.owner,
5847
repo: context.repo.repo,
59-
body: comment
48+
run_id: run_id
6049
});
50+
51+
const failedJobs = jobs.jobs
52+
.filter(job => job.conclusion === 'failure')
53+
.map(job => `- ${job.name} (Job ID: ${job.id})`)
54+
.join('\n');
55+
56+
if (!failedJobs) {
57+
core.info("No failed jobs found.");
58+
return;
59+
}
60+
61+
const prNumber = context.payload.pull_request?.number;
62+
if (!prNumber) {
63+
core.warning("Not a pull request context.");
64+
return;
65+
}
66+
67+
const commentBody = `@claude ### ❌ Failed Jobs in Workflow Run #${run_id}\n${failedJobs}`;
68+
69+
await github.rest.issues.createComment({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
issue_number: prNumber,
73+
body: commentBody
74+
});
75+
76+
core.info("Posted PR comment with failed jobs.");

examples/terraform-test/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module "valkey_traditional" {
8484
port = 6379,
8585
instance_type = "cache.t3.micro",
8686
engine_version = "7.2",
87-
node_count = 1
87+
node_count = 2
8888
}
8989

9090
auth_token = "TIdAao6sd6waZ6NpiC60RZ2nRqYf7C3b"

tests/terraform_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ func TestTerraformAWSElastiCacheModule(t *testing.T) {
5757
EnvVars: map[string]string{
5858
"AWS_DEFAULT_REGION": awsRegion,
5959
},
60+
61+
// Variables to pass to our Terraform code using -var options
62+
Vars: map[string]interface{}{
63+
"prefix": "example",
64+
"environment": "example",
65+
},
6066
})
6167

6268
// At the end of the test, run `terraform destroy` to clean up any resources that were created
@@ -182,6 +188,7 @@ func testElasticacheClustersCreated(t *testing.T, terraformOptions *terraform.Op
182188
assert.Equal(t, "valkey", *rg.Engine, "Engine should be valkey")
183189
assert.True(t, *rg.AtRestEncryptionEnabled, "At-rest encryption should be enabled")
184190
assert.True(t, *rg.TransitEncryptionEnabled, "Transit encryption should be enabled")
191+
// assert.Equal(t, "enabled", string(rg.MultiAZ), "Multi-AZ should be enabled for Valkey cluster")
185192
}
186193
}
187194

@@ -239,7 +246,7 @@ func testAlarmsCreated(t *testing.T, terraformOptions *terraform.Options, region
239246
// Test alarms for Redis traditional cluster
240247
if redisReplicationGroupId != "" {
241248
input := &cloudwatch.DescribeAlarmsInput{
242-
AlarmNamePrefix: aws.String(fmt.Sprintf("example-example-redis-test-redis_high_CPU")),
249+
AlarmNamePrefix: aws.String("example-example-redis-test-redis_high_CPU"),
243250
}
244251

245252
result, err := client.DescribeAlarms(context.TODO(), input)
@@ -261,7 +268,7 @@ func testAlarmsCreated(t *testing.T, terraformOptions *terraform.Options, region
261268
// Test alarms for Valkey traditional cluster
262269
if valkeyReplicationGroupId != "" {
263270
input := &cloudwatch.DescribeAlarmsInput{
264-
AlarmNamePrefix: aws.String(fmt.Sprintf("example-example-valkey-test-redis_high_CPU")),
271+
AlarmNamePrefix: aws.String("example-example-valkey-test-redis_high_CPU"),
265272
}
266273

267274
result, err := client.DescribeAlarms(context.TODO(), input)

0 commit comments

Comments
 (0)