From f738d01ed858187d352beec79ada009bf98f7608 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Wed, 26 Jul 2023 19:18:21 +0300
Subject: [PATCH 01/10] chore(ci): use ec2 for build-and-test-differential
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .../build-and-test-differential.yaml          | 53 +++++++++++++++++--
 1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index e32dccda70b25..9616815e2dfd9 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -13,9 +13,34 @@ jobs:
     with:
       label: run-build-and-test-differential
 
-  build-and-test-differential:
+  start-runner:
+    name: Start self-hosted EC2 runner
     needs: prevent-no-label-execution
     if: ${{ needs.prevent-no-label-execution.outputs.run == 'true' }}
+    runs-on: ubuntu-latest
+    outputs:
+      label: ${{ steps.start-ec2-runner.outputs.label }}
+      ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
+    steps:
+      - name: Configure AWS credentials
+        uses: aws-actions/configure-aws-credentials@v2
+        with:
+          aws-access-key-id: ${{ secrets.EC2_ON_DEMAND_AWS_ACCESS_KEY_ID_COMMON }}
+          aws-secret-access-key: ${{ secrets.EC2_ON_DEMAND_AWS_SECRET_ACCESS_KEY_COMMON }}
+          aws-region: ${{ secrets.EC2_ON_DEMAND_AWS_REGION_COMMON }}
+      - name: Start EC2 runner
+        id: start-ec2-runner
+        uses: machulav/ec2-github-runner@v2
+        with:
+          mode: start
+          github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
+          ec2-image-id: ami-0cbce164c47885212
+          ec2-instance-type: c6i.xlarge
+          subnet-id: subnet-06df98f0f6ec9a128
+          security-group-id: sg-0d632c4394279ec19
+
+  build-and-test-differential:
+    needs: start-runner
     runs-on: [self-hosted, linux, X64]
     container: ${{ matrix.container }}${{ matrix.container-suffix }}
     strategy:
@@ -70,9 +95,9 @@ jobs:
           flags: differential
 
   clang-tidy-differential:
-    runs-on: [self-hosted, linux, X64]
-    container: ghcr.io/autowarefoundation/autoware-universe:humble-latest-cuda
     needs: build-and-test-differential
+    runs-on: ${{ needs.start-runner.outputs.label }}
+    container: ghcr.io/autowarefoundation/autoware-universe:humble-latest-cuda
     steps:
       - name: Check out repository
         uses: actions/checkout@v3
@@ -103,3 +128,25 @@ jobs:
           target-files: ${{ steps.get-modified-files.outputs.all_changed_files }}
           clang-tidy-config-url: https://raw.githubusercontent.com/autowarefoundation/autoware/main/.clang-tidy
           build-depends-repos: build_depends.repos
+
+  stop-runner:
+    name: Stop self-hosted EC2 runner
+    needs:
+      - start-runner
+      - clang-tidy-differential
+    runs-on: ubuntu-latest
+    if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
+    steps:
+      - name: Configure AWS credentials
+        uses: aws-actions/configure-aws-credentials@v2
+        with:
+          aws-access-key-id: ${{ secrets.EC2_ON_DEMAND_AWS_ACCESS_KEY_ID_COMMON }}
+          aws-secret-access-key: ${{ secrets.EC2_ON_DEMAND_AWS_SECRET_ACCESS_KEY_COMMON }}
+          aws-region: ${{ secrets.EC2_ON_DEMAND_AWS_REGION_COMMON }}
+      - name: Stop EC2 runner
+        uses: machulav/ec2-github-runner@v2
+        with:
+          mode: stop
+          github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
+          label: ${{ needs.start-runner.outputs.label }}
+          ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
\ No newline at end of file

From 8b8b3635f6421c530735c1aeeecc43c29d256381 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Wed, 26 Jul 2023 16:30:56 +0000
Subject: [PATCH 02/10] style(pre-commit): autofix

---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index 9616815e2dfd9..ec3e711c0dfde 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -149,4 +149,4 @@ jobs:
           mode: stop
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
           label: ${{ needs.start-runner.outputs.label }}
-          ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
\ No newline at end of file
+          ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}

From 8a525b400b2a447e096aabc42278a6abb131cfa4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 14:19:46 +0300
Subject: [PATCH 03/10] update ids
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index ec3e711c0dfde..2bcd90d088314 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -36,8 +36,8 @@ jobs:
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
           ec2-image-id: ami-0cbce164c47885212
           ec2-instance-type: c6i.xlarge
-          subnet-id: subnet-06df98f0f6ec9a128
-          security-group-id: sg-0d632c4394279ec19
+          subnet-id: subnet-070b3d46464230127
+          security-group-id: sg-0cca5762919221f16
 
   build-and-test-differential:
     needs: start-runner

From a9fbede8ca83aea1c5c9ac9627251fe0125824e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 14:38:02 +0300
Subject: [PATCH 04/10] use small machine for testing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index 2bcd90d088314..e855c80cf305f 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -35,7 +35,7 @@ jobs:
           mode: start
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
           ec2-image-id: ami-0cbce164c47885212
-          ec2-instance-type: c6i.xlarge
+          ec2-instance-type: t2.micro
           subnet-id: subnet-070b3d46464230127
           security-group-id: sg-0cca5762919221f16
 

From 0cb62cff79cd6f53bacbe70199d770b6cbff6676 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 15:24:46 +0300
Subject: [PATCH 05/10] ami test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index e855c80cf305f..f39311d397225 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -34,7 +34,7 @@ jobs:
         with:
           mode: start
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
-          ec2-image-id: ami-0cbce164c47885212
+          ec2-image-id: ami-0b8453dd9fcf6f844
           ec2-instance-type: t2.micro
           subnet-id: subnet-070b3d46464230127
           security-group-id: sg-0cca5762919221f16

From 45eff4d6fc1a80043da88ba3d78565c7a6e78a8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 15:34:32 +0300
Subject: [PATCH 06/10] ami test2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index f39311d397225..6e81798ade8c0 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -34,7 +34,7 @@ jobs:
         with:
           mode: start
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
-          ec2-image-id: ami-0b8453dd9fcf6f844
+          ec2-image-id: ami-0b4f1da68afafd2b8
           ec2-instance-type: t2.micro
           subnet-id: subnet-070b3d46464230127
           security-group-id: sg-0cca5762919221f16

From 17d95b30ba4f00939c24ae62d66c8c2186f7bf43 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 15:59:51 +0300
Subject: [PATCH 07/10] ami test3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index 6e81798ade8c0..906be2d4b47e1 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -34,10 +34,11 @@ jobs:
         with:
           mode: start
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
-          ec2-image-id: ami-0b4f1da68afafd2b8
+          ec2-image-id: ami-092a175a6ad1aad7a
           ec2-instance-type: t2.micro
           subnet-id: subnet-070b3d46464230127
           security-group-id: sg-0cca5762919221f16
+          runner-home-dir: /home/ubuntu/actions-runner
 
   build-and-test-differential:
     needs: start-runner

From c6ebf3c836b6222e8931c81a174e4e98b806221d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 16:38:25 +0300
Subject: [PATCH 08/10] use the correct machine type
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index 906be2d4b47e1..049bf7ebed1fd 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -35,7 +35,7 @@ jobs:
           mode: start
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
           ec2-image-id: ami-092a175a6ad1aad7a
-          ec2-instance-type: t2.micro
+          ec2-instance-type: c6i.xlarge
           subnet-id: subnet-070b3d46464230127
           security-group-id: sg-0cca5762919221f16
           runner-home-dir: /home/ubuntu/actions-runner

From 8b212efa16ee786de8ad01d748caf8bc60ddfa2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 16:45:11 +0300
Subject: [PATCH 09/10] use amd version
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index 049bf7ebed1fd..00ab2eff28f84 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -35,7 +35,7 @@ jobs:
           mode: start
           github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN_MFC }}
           ec2-image-id: ami-092a175a6ad1aad7a
-          ec2-instance-type: c6i.xlarge
+          ec2-instance-type: c6a.xlarge
           subnet-id: subnet-070b3d46464230127
           security-group-id: sg-0cca5762919221f16
           runner-home-dir: /home/ubuntu/actions-runner

From 85d00914ca35d673ca962a42d1383ea6543cc965 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= <mfc@leodrive.ai>
Date: Mon, 31 Jul 2023 17:41:40 +0300
Subject: [PATCH 10/10] run on its own instance
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
---
 .github/workflows/build-and-test-differential.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/build-and-test-differential.yaml b/.github/workflows/build-and-test-differential.yaml
index 00ab2eff28f84..950141e8ae6da 100644
--- a/.github/workflows/build-and-test-differential.yaml
+++ b/.github/workflows/build-and-test-differential.yaml
@@ -42,7 +42,7 @@ jobs:
 
   build-and-test-differential:
     needs: start-runner
-    runs-on: [self-hosted, linux, X64]
+    runs-on: ${{ needs.start-runner.outputs.label }}
     container: ${{ matrix.container }}${{ matrix.container-suffix }}
     strategy:
       fail-fast: false