Skip to content

Commit 0f3651b

Browse files
authored
Merge pull request #1722 from sustainable-computing-io/fix-flow
fix(ci): consolidate mock-acpi workflow into single job
2 parents cefe652 + af7fc6b commit 0f3651b

File tree

1 file changed

+19
-62
lines changed

1 file changed

+19
-62
lines changed

.github/workflows/mock_acpi.yml

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,27 @@ on: # yamllint disable-line rule:truthy
66
types: [created]
77

88
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:
1210
if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi'
13-
name: Fetch branch name
11+
name: Test Mock ACPI
1412
runs-on: ubuntu-latest
15-
outputs:
16-
head_ref: ${{ steps.pr_branch.outputs.head_ref }}
17-
head_sha: ${{ steps.pr_branch.outputs.head_sha }}
1813
steps:
14+
# Since `issue_comment` event runs on the default branch,
15+
# we need to get the branch of the pull request
1916
- name: Get PR branch
2017
id: pr_branch
2118
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
3722
- name: Set job status as pending
23+
if: ${{ success() }}
3824
uses: myrotvorets/set-commit-status-action@master
3925
with:
40-
sha: ${{ needs.fetch-branch-name.outputs.head_sha }}
26+
sha: ${{ steps.pr_branch.outputs.head_sha }}
4127
token: ${{ secrets.GITHUB_TOKEN }}
4228
status: pending
4329

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:
5030
- name: metal-runner-action
5131
uses: equinix-labs/metal-runner-action@v0.2.0
5232
with:
@@ -57,25 +37,16 @@ jobs:
5737
plan: c3.small.x86
5838
os: ubuntu_20_04
5939

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:
7140
- name: Configure SSH
41+
if: ${{ success() }}
7242
run: |
7343
echo "Configuring SSH for runner"
7444
sudo ssh-keygen -t rsa -b 4096 -f /root/.ssh/ansible_rsa -N ''
7545
sudo cat ~/.ssh/ansible_rsa.pub >> ~/.ssh/authorized_keys
7646
sudo echo "StrictHostKeyChecking no" >> ~/.ssh/config
7747
7848
- name: Install Dependencies
49+
if: ${{ success() }}
7950
run: |
8051
echo "Installing Ansible and Docker module"
8152
sudo apt install software-properties-common -y
@@ -84,54 +55,40 @@ jobs:
8455
sudo ansible-galaxy collection install community.docker
8556
8657
- name: Checkout code
58+
if: ${{ success() }}
8759
uses: actions/checkout@v3
8860
with:
89-
ref: ${{ needs.fetch-branch-name.outputs.head_ref }}
61+
ref: ${{ steps.pr_branch.outputs.head_ref }}
9062

9163
- name: Run playbook
9264
id: run-playbook
65+
if: ${{ success() }}
66+
continue-on-error: true # This is done to release equinix runners irrespective of failure
9367
run: |
9468
echo "Setting up the infra"
9569
cd ${GITHUB_WORKSPACE}/ansible
9670
ansible-playbook -vv -i inventory.yaml setup.yaml
9771
echo "Launching Mock ACPI compose and running validator"
9872
ansible-playbook -vv -i inventory.yaml mock_acpi_playbook.yaml -e "pr_number=${{ github.event.issue.number }}"
9973
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:
10674
- name: delete runner
10775
uses: rootfs/metal-delete-action@main
10876
with:
10977
authToken: ${{ secrets.EQUINIX_API_TOKEN }}
11078
projectID: ${{ secrets.EQUINIX_PROJECT_ID }}
111-
runnerName: ${{ needs.setup-runner.outputs.runner-name }}
79+
runnerName: ${{ runner.name }}
11280

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
12082
- name: Mark workflow as failed if playbook failed
121-
if: needs.setup-runner.outputs.playbook-status == 'failure'
83+
if: ${{ steps.run-playbook.outcome == 'failure' }}
12284
run: |
12385
echo "Playbook failed, marking workflow as failed"
12486
exit 1
12587
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:
13188
- name: Set job status as ${{ job.status }}
13289
uses: myrotvorets/set-commit-status-action@master
13390
if: always()
13491
with:
135-
sha: ${{ env.head_sha }}
92+
sha: ${{ steps.pr_branch.outputs.head_sha }}
13693
token: ${{ secrets.GITHUB_TOKEN }}
13794
status: ${{ job.status }}

0 commit comments

Comments
 (0)