Skip to content

Commit e10b4f0

Browse files
authored
Merge pull request #28 from geekcell/add-test
Adding simple Test
2 parents 45c7c1a + 608fb07 commit e10b4f0

File tree

3 files changed

+183
-30
lines changed

3 files changed

+183
-30
lines changed

.github/workflows/test.yaml

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
###############
3+
## Run tests ##
4+
###############
5+
6+
#
7+
# Documentation:
8+
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
9+
#
10+
11+
name: Test
12+
on:
13+
pull_request:
14+
push:
15+
branches: [ main ]
16+
17+
##########################
18+
# Prevent duplicate jobs #
19+
##########################
20+
concurrency:
21+
group: ${{ github.repository }}
22+
cancel-in-progress: false
23+
24+
permissions:
25+
id-token: write
26+
contents: read
27+
28+
###############
29+
# Run the job #
30+
###############
31+
jobs:
32+
self-test:
33+
name: Testing
34+
runs-on: ubuntu-latest
35+
steps:
36+
############################
37+
# Checkout the source code #
38+
############################
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
42+
#############################
43+
# Configure AWS credentials #
44+
#############################
45+
- name: Configure AWS credentials
46+
uses: aws-actions/configure-aws-credentials@v4
47+
with:
48+
role-to-assume: arn:aws:iam::${{ vars.AWS_TESTING_ACCOUNT_ID }}:role/${{ vars.AWS_TESTING_ROLE }}
49+
aws-region: ${{ vars.AWS_TESTING_REGION }}
50+
mask-aws-account-id: false
51+
52+
######################
53+
# Test Action itself #
54+
######################
55+
- name: Test With Log Tail
56+
uses: ./
57+
with:
58+
# Pre created
59+
cluster: github-gha
60+
task-definition: arn:aws:ecs:${{ vars.AWS_TESTING_REGION }}:${{ vars.AWS_TESTING_ACCOUNT_ID }}:task-definition/github-gha-alpine
61+
62+
assign-public-ip: 'ENABLED'
63+
security-group-ids: |
64+
sg-09a0ccb78d5be2a25
65+
subnet-ids: |
66+
subnet-08bbfd6c53b0c1049
67+
subnet-0fef13a6bef01f61a
68+
subnet-0a676289b4a27a7fa
69+
70+
tail-logs: true
71+
override-container: alpine
72+
override-container-command: |
73+
/bin/sh
74+
-c
75+
echo "Hello, World!" && \
76+
echo "$TEST_VAR" && \
77+
x=0; while [ $x -le 10 ]; do echo "Sleeping... $x" && x=$(( $x + 1 )) && sleep 2; done
78+
override-container-environment: |
79+
TEST_VAR=foobar123
80+
81+
######################
82+
# Test Action itself #
83+
######################
84+
- name: Test Failure Exit Code
85+
id: expect-fail
86+
continue-on-error: true
87+
uses: ./
88+
with:
89+
# Pre created
90+
cluster: github-gha
91+
task-definition: arn:aws:ecs:${{ vars.AWS_TESTING_REGION }}:${{ vars.AWS_TESTING_ACCOUNT_ID }}:task-definition/github-gha-alpine
92+
93+
assign-public-ip: 'ENABLED'
94+
security-group-ids: |
95+
sg-09a0ccb78d5be2a25
96+
subnet-ids: |
97+
subnet-08bbfd6c53b0c1049
98+
subnet-0fef13a6bef01f61a
99+
subnet-0a676289b4a27a7fa
100+
101+
override-container: alpine
102+
override-container-command: |
103+
/bin/sh
104+
-c
105+
exit 1
106+
107+
##########################
108+
# Check expected failure #
109+
##########################
110+
- name: Check previous for Failure
111+
if: steps.expect-fail.outcome == 'success'
112+
run: |
113+
echo "Expected a failure. Outcome: ${{ steps.expect-fail.outcome }}"
114+
exit 1
115+
116+
######################
117+
# Test Action itself #
118+
######################
119+
- name: Test Fire and Forget
120+
uses: ./
121+
with:
122+
# Pre created
123+
cluster: github-gha
124+
task-definition: arn:aws:ecs:${{ vars.AWS_TESTING_REGION }}:${{ vars.AWS_TESTING_ACCOUNT_ID }}:task-definition/github-gha-alpine
125+
126+
assign-public-ip: 'ENABLED'
127+
security-group-ids: |
128+
sg-09a0ccb78d5be2a25
129+
subnet-ids: |
130+
subnet-08bbfd6c53b0c1049
131+
subnet-0fef13a6bef01f61a
132+
subnet-0a676289b4a27a7fa
133+
134+
task-wait-until-stopped: false
135+
override-container: alpine
136+
override-container-command: |
137+
/bin/sh
138+
-c
139+
x=0; while [ $x -le 10 ]; do echo "Sleeping... $x" && x=$(( $x + 1 )) && sleep 10; done

dist/index.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -74003,12 +74003,16 @@ const main = async () => {
7400374003
core.setOutput('task-id', taskId);
7400474004
core.info(`Starting Task with ARN: ${taskArn}\n`);
7400574005

74006-
// Wait for task to be in running state
74007-
core.debug(`Waiting for task to be in running state.`)
74008-
await waitUntilTasksRunning({
74009-
client: ecs,
74010-
maxWaitTime: taskStartMaxWaitTime,
74011-
}, {cluster, tasks: [taskArn]});
74006+
try {
74007+
core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`);
74008+
await waitUntilTasksRunning({
74009+
client: ecs,
74010+
maxWaitTime: taskStartMaxWaitTime,
74011+
}, {cluster, tasks: [taskArn]});
74012+
} catch (error) {
74013+
core.setFailed(`Task did not start successfully. Error: ${error.name}. State: ${error.state}.`);
74014+
return;
74015+
}
7401274016

7401374017
// If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any
7401474018
// information on the exitCodes or status of the task
@@ -74070,15 +74074,18 @@ const main = async () => {
7407074074
}
7407174075
}
7407274076

74073-
// Wait for Task to finish
74074-
core.debug(`Waiting for task to finish.`);
74075-
await waitUntilTasksStopped({
74076-
client: ecs,
74077-
maxWaitTime: taskStoppedMaxWaitTime,
74078-
}, {
74079-
cluster,
74080-
tasks: [taskArn],
74081-
});
74077+
try {
74078+
core.debug(`Waiting for task to finish. Waiting for ${taskStoppedMaxWaitTime} seconds.`);
74079+
await waitUntilTasksStopped({
74080+
client: ecs,
74081+
maxWaitTime: taskStoppedMaxWaitTime,
74082+
}, {
74083+
cluster,
74084+
tasks: [taskArn],
74085+
});
74086+
} catch (error) {
74087+
core.setFailed(`Task did not stop successfully. Error: ${error.name}. State: ${error.state}.`);
74088+
}
7408274089

7408374090
// Close LogStream and store output
7408474091
if (logFilterStream !== null) {

index.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ const main = async () => {
105105
core.setOutput('task-id', taskId);
106106
core.info(`Starting Task with ARN: ${taskArn}\n`);
107107

108-
// Wait for task to be in running state
109-
core.debug(`Waiting for task to be in running state.`)
110-
await waitUntilTasksRunning({
111-
client: ecs,
112-
maxWaitTime: taskStartMaxWaitTime,
113-
}, {cluster, tasks: [taskArn]});
108+
try {
109+
core.debug(`Waiting for task to be in running state. Waiting for ${taskStartMaxWaitTime} seconds.`);
110+
await waitUntilTasksRunning({
111+
client: ecs,
112+
maxWaitTime: taskStartMaxWaitTime,
113+
}, {cluster, tasks: [taskArn]});
114+
} catch (error) {
115+
core.setFailed(`Task did not start successfully. Error: ${error.name}. State: ${error.state}.`);
116+
return;
117+
}
114118

115119
// If taskWaitUntilStopped is false, we can bail out here because we can not tail logs or have any
116120
// information on the exitCodes or status of the task
@@ -172,15 +176,18 @@ const main = async () => {
172176
}
173177
}
174178

175-
// Wait for Task to finish
176-
core.debug(`Waiting for task to finish.`);
177-
await waitUntilTasksStopped({
178-
client: ecs,
179-
maxWaitTime: taskStoppedMaxWaitTime,
180-
}, {
181-
cluster,
182-
tasks: [taskArn],
183-
});
179+
try {
180+
core.debug(`Waiting for task to finish. Waiting for ${taskStoppedMaxWaitTime} seconds.`);
181+
await waitUntilTasksStopped({
182+
client: ecs,
183+
maxWaitTime: taskStoppedMaxWaitTime,
184+
}, {
185+
cluster,
186+
tasks: [taskArn],
187+
});
188+
} catch (error) {
189+
core.setFailed(`Task did not stop successfully. Error: ${error.name}. State: ${error.state}.`);
190+
}
184191

185192
// Close LogStream and store output
186193
if (logFilterStream !== null) {

0 commit comments

Comments
 (0)