Skip to content

Commit f0073b1

Browse files
committed
CI: update CI with changes to follow github action template
Signed-off-by: Sam Yuan <yy19902439@126.com>
1 parent 99a6bc8 commit f0073b1

File tree

3 files changed

+159
-159
lines changed

3 files changed

+159
-159
lines changed

.github/workflows/ci.yml

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

.github/workflows/image.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: imagebuild
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
image_build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4.1.1
17+
- name: Login to Quay
18+
uses: docker/#-action@v3
19+
with:
20+
registry: quay.io/sustainable_computing_io
21+
username: ${{ secrets.username }}
22+
password: ${{ secrets.password }}
23+
- name: Build and push the container
24+
uses: docker/build-push-action@v5
25+
with:
26+
context: .
27+
platforms: linux/amd64
28+
push: true
29+
tags: quay.io/sustainable_computing_io/aws_ec2_self_hosted_runner:latest
30+
labels: latest
31+
file: Dockerfile

.github/workflows/pr.yml

-159
This file was deleted.

0 commit comments

Comments
 (0)