@@ -6,47 +6,27 @@ on: # yamllint disable-line rule:truthy
6
6
types : [created]
7
7
8
8
jobs :
9
- # Since `issue_comment` event runs on the default branch,
10
- # we need to get the branch of the pull request
11
- fetch-branch-name :
9
+ test-mock-acpi :
12
10
if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
13
- name : Fetch branch name
11
+ name : Test Mock ACPI
14
12
runs-on : ubuntu-latest
15
- outputs :
16
- head_ref : ${{ steps.pr_branch.outputs.head_ref }}
17
- head_sha : ${{ steps.pr_branch.outputs.head_sha }}
18
13
steps :
14
+ # Since `issue_comment` event runs on the default branch,
15
+ # we need to get the branch of the pull request
19
16
- name : Get PR branch
20
17
id : pr_branch
21
18
uses : xt0rted/pull-request-comment-branch@v2
22
-
23
- - name : Set ref and sha as outputs
24
- run : |
25
- echo "head_ref=${{ steps.pr_branch.outputs.head_ref }}" >> $GITHUB_ENV
26
- echo "head_sha=${{ steps.pr_branch.outputs.head_sha }}" >> $GITHUB_ENV
27
-
28
- # Since `issue_comment` event workflow will not appear on the
29
- # pull request page, we need to set the status of the job
30
- # in order to attach it to the pull request itself
31
- set-status-pending :
32
- if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
33
- name : Set job status as pending
34
- runs-on : ubuntu-latest
35
- needs : fetch-branch-name
36
- steps :
19
+ # Since `issue_comment` event workflow will not appear on the
20
+ # pull request page, we need to set the status of the job
21
+ # in order to attach it to the pull request itself
37
22
- name : Set job status as pending
23
+ if : ${{ success() }}
38
24
uses : myrotvorets/set-commit-status-action@master
39
25
with :
40
- sha : ${{ needs.fetch-branch-name .outputs.head_sha }}
26
+ sha : ${{ steps.pr_branch .outputs.head_sha }}
41
27
token : ${{ secrets.GITHUB_TOKEN }}
42
28
status : pending
43
29
44
- create-runner :
45
- if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
46
- name : Create Runner
47
- runs-on : ubuntu-latest
48
-
49
- steps :
50
30
- name : metal-runner-action
51
31
uses : equinix-labs/metal-runner-action@v0.2.0
52
32
with :
@@ -57,25 +37,16 @@ jobs:
57
37
plan : c3.small.x86
58
38
os : ubuntu_20_04
59
39
60
- setup-runner :
61
- if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
62
- name : Setup Runner
63
- needs : [fetch-branch-name, create-runner]
64
- runs-on : self-hosted
65
- continue-on-error : true # This is done to release equinix runners irrespective of failure
66
- outputs :
67
- runner-name : ${{ runner.name }}
68
- playbook-status : ${{ steps.run-playbook.outcome }}
69
-
70
- steps :
71
40
- name : Configure SSH
41
+ if : ${{ success() }}
72
42
run : |
73
43
echo "Configuring SSH for runner"
74
44
sudo ssh-keygen -t rsa -b 4096 -f /root/.ssh/ansible_rsa -N ''
75
45
sudo cat ~/.ssh/ansible_rsa.pub >> ~/.ssh/authorized_keys
76
46
sudo echo "StrictHostKeyChecking no" >> ~/.ssh/config
77
47
78
48
- name : Install Dependencies
49
+ if : ${{ success() }}
79
50
run : |
80
51
echo "Installing Ansible and Docker module"
81
52
sudo apt install software-properties-common -y
@@ -84,54 +55,40 @@ jobs:
84
55
sudo ansible-galaxy collection install community.docker
85
56
86
57
- name : Checkout code
58
+ if : ${{ success() }}
87
59
uses : actions/checkout@v3
88
60
with :
89
- ref : ${{ needs.fetch-branch-name .outputs.head_ref }}
61
+ ref : ${{ steps.pr_branch .outputs.head_ref }}
90
62
91
63
- name : Run playbook
92
64
id : run-playbook
65
+ if : ${{ success() }}
66
+ continue-on-error : true # This is done to release equinix runners irrespective of failure
93
67
run : |
94
68
echo "Setting up the infra"
95
69
cd ${GITHUB_WORKSPACE}/ansible
96
70
ansible-playbook -vv -i inventory.yaml setup.yaml
97
71
echo "Launching Mock ACPI compose and running validator"
98
72
ansible-playbook -vv -i inventory.yaml mock_acpi_playbook.yaml -e "pr_number=${{ github.event.issue.number }}"
99
73
100
- cleanup :
101
- if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
102
- name : Cleanup
103
- runs-on : ubuntu-latest
104
- needs : setup-runner
105
- steps :
106
74
- name : delete runner
107
75
uses : rootfs/metal-delete-action@main
108
76
with :
109
77
authToken : ${{ secrets.EQUINIX_API_TOKEN }}
110
78
projectID : ${{ secrets.EQUINIX_PROJECT_ID }}
111
- runnerName : ${{ needs.setup- runner.outputs.runner- name }}
79
+ runnerName : ${{ runner.name }}
112
80
113
- # Marking the workflow as failed if the playbook fails
114
- mark-workflow-failed :
115
- if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
116
- name : Mark workflow as failed
117
- runs-on : ubuntu-latest
118
- needs : setup-runner
119
- steps :
81
+ # Marking the workflow as failed if the playbook fails
120
82
- name : Mark workflow as failed if playbook failed
121
- if : needs.setup-runner.outputs. playbook-status == 'failure'
83
+ if : ${{ steps.run- playbook.outcome == 'failure' }}
122
84
run : |
123
85
echo "Playbook failed, marking workflow as failed"
124
86
exit 1
125
87
126
- set-final-status :
127
- if : github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
128
- name : Set final status
129
- runs-on : ubuntu-latest
130
- steps :
131
88
- name : Set job status as ${{ job.status }}
132
89
uses : myrotvorets/set-commit-status-action@master
133
90
if : always()
134
91
with :
135
- sha : ${{ env .head_sha }}
92
+ sha : ${{ steps.pr_branch.outputs .head_sha }}
136
93
token : ${{ secrets.GITHUB_TOKEN }}
137
94
status : ${{ job.status }}
0 commit comments