-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding ci/cd for simulator testing
- Loading branch information
Armando Banuelos
authored and
Armando Banuelos
committed
Apr 1, 2024
1 parent
d5a21fc
commit 0091291
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: run_simulators | ||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: run_simulators | ||
runs-on: ubuntu-latest | ||
concurrency: | ||
group: sim | ||
|
||
steps: | ||
- name: Start EC2 Instance | ||
env: | ||
INSTANCE_ID: ${{ secrets.AWS_EC2_INSTANCE_ID }} | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | ||
run: | | ||
# Get the instance state | ||
instance_state=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r '.Reservations[].Instances[].State.Name') | ||
# If the machine is stopping wait for it to fully stop | ||
while [ "$instance_state" == "stopping" ]; do | ||
echo "Instance is stopping, waiting for it to fully stop..." | ||
sleep 10 | ||
instance_state=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r '.Reservations[].Instances[].State.Name') | ||
done | ||
# Check if instance state is "stopped" | ||
if [[ "$instance_state" == "stopped" ]]; then | ||
echo "Instance is stopped, starting it..." | ||
aws ec2 start-instances --instance-ids $INSTANCE_ID | ||
elif [[ "$instance_state" == "pending" ]]; then | ||
echo "Instance startup is pending, continuing..." | ||
elif [[ "$instance_state" == "running" ]]; then | ||
echo "Instance is already running..." | ||
exit 0 | ||
else | ||
echo "Unknown instance state: $instance_state" | ||
exit 1 | ||
fi | ||
# Wait for 2 minutes | ||
echo "Waiting 2 minutes for full startup..." | ||
sleep 120 | ||
- name: SSH into EC2 and Run Simulator Tests | ||
env: | ||
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
HOSTNAME: ${{secrets.SSH_HOST}} | ||
USER_NAME: ${{secrets.SSH_USERNAME}} | ||
run: | | ||
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | ||
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} ' | ||
# Now we have got the access of EC2 and we will start the deploy . | ||
bash /opt/carla-simulator/CarlaUE4.sh & && | ||
ls /home/ubuntu/ && | ||
cd /home/ubuntu/actions/ && | ||
git clone --branch $(basename "${{ github.ref }}") --single-branch https://$GH_ACCESS_TOKEN@github.com/BerkeleyLearnVerify/Scenic.git && | ||
cd Scenic && | ||
python3 -m venv venv && | ||
source venv/bin/activate && | ||
python3 -m pip install -e . && | ||
python3 -m pip install -e .[test-full] && | ||
python3 -m pip install -e .[guideways] && | ||
pytest tests/simulators/* && | ||
cd /home/ubuntu/ && | ||
rm -rf /home/ubuntu/actions/Scenic | ||
' | ||
- name: Stop EC2 Instance | ||
env: | ||
INSTANCE_ID: ${{ secrets.AWS_EC2_INSTANCE_ID }} | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} | ||
run: | | ||
# Get the instance state | ||
instance_state=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r '.Reservations[].Instances[].State.Name') | ||
# If the machine is pending wait for it to fully start | ||
while [ "$instance_state" == "pending" ]; do | ||
echo "Instance is pending startup, waiting for it to fully start..." | ||
sleep 10 | ||
instance_state=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r '.Reservations[].Instances[].State.Name') | ||
done | ||
# Check if instance state is "stopped" | ||
if [[ "$instance_state" == "running" ]]; then | ||
echo "Instance is running, stopping it..." | ||
aws ec2 stop-instances --instance-ids $INSTANCE_ID | ||
elif [[ "$instance_state" == "stopping" ]]; then | ||
echo "Instance is stopping..." | ||
elif [[ "$instance_state" == "stopped" ]]; then | ||
echo "Instance is already stopped..." | ||
exit 0 | ||
else | ||
echo "Unknown instance state: $instance_state" | ||
exit 1 | ||
fi |