Skip to content

Commit add319e

Browse files
committed
refactor pipeliie
1 parent 7c3398c commit add319e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,19 @@ jobs:
135135
136136
- name: Start EC2 and wait for SSM agent
137137
run: |
138-
aws ec2 start-instances --instance-ids "$EC2_INSTANCE_ID" 2>/dev/null || true
139-
aws ec2 wait instance-running --instance-ids "$EC2_INSTANCE_ID"
140-
echo "Instance is running, waiting for SSM agent to come online..."
138+
STATE=$(aws ec2 describe-instances \
139+
--instance-ids "$EC2_INSTANCE_ID" \
140+
--query "Reservations[0].Instances[0].State.Name" \
141+
--output text)
142+
if [ "$STATE" != "running" ]; then
143+
echo "Instance is $STATE — starting it"
144+
aws ec2 start-instances --instance-ids "$EC2_INSTANCE_ID"
145+
aws ec2 wait instance-running --instance-ids "$EC2_INSTANCE_ID"
146+
echo "STARTED_BY_PIPELINE=true" >> $GITHUB_ENV
147+
else
148+
echo "Instance already running — will not stop after deploy"
149+
fi
150+
echo "Waiting for SSM agent to come online..."
141151
for i in {1..20}; do
142152
SSM_STATUS=$(aws ssm describe-instance-information \
143153
--filters "Key=InstanceIds,Values=$EC2_INSTANCE_ID" \
@@ -197,7 +207,7 @@ jobs:
197207
exit 1
198208
199209
- name: Stop EC2 instance
200-
if: always() && env.EC2_INSTANCE_ID != ''
210+
if: always() && env.STARTED_BY_PIPELINE == 'true'
201211
run: |
202212
aws ec2 stop-instances --instance-ids "$EC2_INSTANCE_ID"
203213
echo "EC2 instance stopped"

0 commit comments

Comments
 (0)