-
Notifications
You must be signed in to change notification settings - Fork 30
125 lines (113 loc) · 3.86 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: CI
on:
push:
branches:
- '**'
workflow_dispatch:
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Check
run: make check
- name: Lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.54
skip-pkg-cache: true
- name: Test
run: make test
start-runner:
name: Start self-hosted EC2 runner
needs: check
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@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Start EC2 runner
id: start-ec2-runner
uses: namecheap/ec2-github-runner@main
with:
mode: start
github-token: ${{ secrets.GH_TOKEN }}
ec2-image-owner: 699717368611
ec2-image-filters: >
[
{ "Name": "name", "Values": ["nc-amzn2-ami-hvm-x86_64-gp2-master-*"] }
]
ec2-instance-type: t3.nano
subnet-id: subnet-01c4ff5a
security-group-id: sg-106ec76d
eip-allocation-id: eipalloc-1796f61b
iam-role-name: AmazonSSMRoleForInstancesQuickSetup
aws-resource-tags: >
[
{ "Key": "Name", "Value": "github_runner" },
{ "Key": "GitHubRepository", "Value": "${{ github.repository }}" }
]
acceptance_test:
name: Acceptance test
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
needs: start-runner
concurrency: acceptance_test # allow to run the only one instance of the current acceptance_test job
steps:
- uses: actions/checkout@v2
- name: Set up Go
run: |
curl https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz -o go1.21.5.linux-amd64.tar.gz
rm -rf .go-instance
mkdir .go-instance
tar -C .go-instance -xzf go1.21.5.linux-amd64.tar.gz
echo "#!/bin/bash" >> go-env.sh
echo "" >> go-env.sh
echo "export PATH=$PATH:$(pwd)/.go-instance/go/bin" >> go-env.sh
echo "export HOME=$(pwd)" >> go-env.sh
chmod +x go-env.sh
source go-env.sh
go version
go env GOPATH
- name: Acceptance Test
run: |
export CGO_ENABLED=0
source go-env.sh
make testacc
env:
NAMECHEAP_USER_NAME: saTerraformProvider
NAMECHEAP_API_USER: saTerraformProvider
NAMECHEAP_TEST_DOMAIN: terraform-provider-test.net
NAMECHEAP_USE_SANDBOX: true
NAMECHEAP_API_KEY: ${{ secrets.NAMECHEAP_API_KEY }}
stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner
- acceptance_test
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@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Stop EC2 runner
uses: namecheap/ec2-github-runner@main
with:
mode: stop
github-token: ${{ secrets.GH_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}