1+ # shellcheck disable=SC1000-SC9999
2+ name : Continuous Integration
3+
4+ on :
5+ pull_request :
6+ push :
7+ branches :
8+ - main
9+
10+ permissions :
11+ contents : read
12+
13+ jobs :
14+ test-docker :
15+ name : Docker Tests
16+ runs-on : ubuntu-latest
17+
18+ # Run a local registry to push to
19+ services :
20+ registry :
21+ image : registry:2
22+ ports :
23+ - 5001:5000
24+
25+ env :
26+ TEST_TAG : localhost:5001/sustainable_computing_io/aws_ec2_self_hosted_runner:latest
27+
28+ steps :
29+ - name : Checkout
30+ id : checkout
31+ uses : actions/checkout@v4
32+
33+ - name : Setup Docker BuildX
34+ id : setup-buildx
35+ uses : docker/setup-buildx-action@v3
36+ with :
37+ install : true
38+ driver-opts : network=host
39+
40+ - name : Build the Container
41+ id : build
42+ uses : docker/build-push-action@v5
43+ with :
44+ context : .
45+ push : true
46+ tags : ${{ env.TEST_TAG }}
47+
48+
49+ setup-runner :
50+ name : GitHub Actions Test create instance
51+ runs-on : ubuntu-latest
52+ outputs :
53+ instance_id : ${{ steps.create-runner.outputs.instance_id }}
54+ runner_name : ${{ steps.create-runner.outputs.runner_name }}
55+ steps :
56+ - name : Checkout
57+ id : checkout
58+ uses : actions/checkout@v4
59+
60+ - name : Test Local Action
61+ id : create-runner
62+ uses : ./
63+ with :
64+ action : " create"
65+ aws_region : ${{ secrets.AWS_REGION }}
66+ github_token : ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
67+ aws_access_key_id : ${{ secrets.AWS_ACCESS_KEY_ID }}
68+ aws_secret_access_key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
69+ security_group_id : ${{ secrets.AWS_SECURITY_GROUP_ID }}
70+ github_repo : ${{ github.repository }}
71+ ami_id : " ami-0e4d0bb9670ea8db0"
72+ instance_type : " t2.micro"
73+ create_s3_bucket : " false"
74+ spot_instance_only : " true"
75+
76+ - name : Print Output
77+ id : output
78+ run : |
79+ echo "instance_id ${{ steps.create-runner.outputs.instance_id }}"
80+ echo "instance_ip ${{ steps.create-runner.outputs.instance_ip }}"
81+ echo "runner_name ${{ steps.create-runner.outputs.runner_name }}"
82+ echo "bucket_name ${{ steps.create-runner.outputs.bucket_name }}"
83+
84+ test-runner :
85+ needs : setup-runner
86+ runs-on : [self-hosted, linux, x64]
87+ steps :
88+ - name : Checkout
89+ uses : actions/checkout@v4
90+
91+ - name : Run Tests
92+ run : |
93+ export INSTANCE_ID="${{ needs.setup-runner.outputs.instance_id }}"
94+ echo "Running tests on self-hosted runner with instance ${INSTANCE_ID}"
95+ uname -a # or any other command
96+ cat /etc/os-release
97+ cat /proc/cpuinfo
98+
99+ destroy-runner :
100+ if : always()
101+ name : GitHub Actions Test destroy instance
102+ needs : [setup-runner, test-runner]
103+ runs-on : ubuntu-latest
104+ steps :
105+ - name : Checkout
106+ id : checkout
107+ uses : actions/checkout@v4
108+
109+ - name : unregister runner
110+ id : unregister
111+ uses : ./
112+ with :
113+ action : " unregister"
114+ runner_name : ${{ needs.setup-runner.outputs.runner_name }}
115+ github_token : ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
116+ github_repo : ${{ github.repository }}
117+
118+ - name : terminate instance
119+ id : terminate
120+ uses : ./
121+ with :
122+ action : " terminate"
123+ aws_access_key_id : ${{ secrets.AWS_ACCESS_KEY_ID }}
124+ aws_secret_access_key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
125+ instance_id : ${{ needs.setup-runner.outputs.instance_id }}
126+
0 commit comments