|
| 1 | +# This workflow will run mock-acpi compose on self-hosted equinix runners and run validator tool |
| 2 | +name: Mock ACPI |
| 3 | + |
| 4 | +on: # yamllint disable-line rule:truthy |
| 5 | + issue_comment: |
| 6 | + types: [created] |
| 7 | + |
| 8 | +jobs: |
| 9 | + create-runner: |
| 10 | + if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi' |
| 11 | + name: Create Runner |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: metal-runner-action |
| 16 | + uses: equinix-labs/[email protected] |
| 17 | + with: |
| 18 | + github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }} |
| 19 | + metal_auth_token: ${{ secrets.EQUINIX_API_TOKEN }} |
| 20 | + metal_project_id: ${{ secrets.EQUINIX_PROJECT_ID }} |
| 21 | + metro: da |
| 22 | + plan: c3.small.x86 |
| 23 | + os: ubuntu_20_04 |
| 24 | + |
| 25 | + setup-runner: |
| 26 | + if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi' |
| 27 | + name: Setup Runner |
| 28 | + needs: create-runner |
| 29 | + runs-on: self-hosted |
| 30 | + continue-on-error: true # This is done to release equinix runners irrespective of failure |
| 31 | + outputs: |
| 32 | + runner-name: ${{ runner.name }} |
| 33 | + playbook-status: ${{ steps.run-playbook.outcome }} |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Configure SSH |
| 37 | + run: | |
| 38 | + echo "Configuring SSH for runner" |
| 39 | + sudo ssh-keygen -t rsa -b 4096 -f /root/.ssh/ansible_rsa -N '' |
| 40 | + sudo cat ~/.ssh/ansible_rsa.pub >> ~/.ssh/authorized_keys |
| 41 | + sudo echo "StrictHostKeyChecking no" >> ~/.ssh/config |
| 42 | +
|
| 43 | + - name: Install Dependencies |
| 44 | + run: | |
| 45 | + echo "Installing Ansible and Docker module" |
| 46 | + sudo apt install software-properties-common -y |
| 47 | + sudo add-apt-repository --yes --update ppa:ansible/ansible |
| 48 | + sudo apt install -y ansible python3-pip |
| 49 | + sudo ansible-galaxy collection install community.docker |
| 50 | +
|
| 51 | + - name: Checkout code |
| 52 | + uses: actions/checkout@v3 |
| 53 | + |
| 54 | + - name: Run playbook |
| 55 | + id: run-playbook |
| 56 | + run: | |
| 57 | + echo "Setting up the infra" |
| 58 | + cd ${GITHUB_WORKSPACE}/ansible |
| 59 | + ansible-playbook -vv -i inventory.yaml setup.yaml |
| 60 | + echo "Launching Mock ACPI compose and running validator" |
| 61 | + ansible-playbook -vv -i inventory.yaml mock_acpi_playbook.yaml -e "pr_number=${{ github.event.issue.number }}" |
| 62 | +
|
| 63 | + - name: Set failure status if playbook failed |
| 64 | + if: steps.run-playbook.outcome == 'failure' |
| 65 | + run: echo "failure_status=true" >> $GITHUB_ENV |
| 66 | + |
| 67 | + cleanup: |
| 68 | + if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi' |
| 69 | + name: Cleanup |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: [setup-runner] |
| 72 | + steps: |
| 73 | + - name: delete runner |
| 74 | + uses: rootfs/metal-delete-action@main |
| 75 | + with: |
| 76 | + authToken: ${{ secrets.EQUINIX_API_TOKEN }} |
| 77 | + projectID: ${{ secrets.EQUINIX_PROJECT_ID }} |
| 78 | + runnerName: ${{ needs.setup-runner.outputs.runner-name }} |
| 79 | + |
| 80 | + # Marking the workflow as failed if the playbook fails |
| 81 | + mark-workflow-failed: |
| 82 | + if: github.event.issue.pull_request && github.event.comment.body == '/test-acpi' |
| 83 | + name: Mark workflow as failed |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: [setup-runner] |
| 86 | + steps: |
| 87 | + - name: Mark workflow as failed if playbook failed |
| 88 | + if: needs.setup-runner.outputs.playbook-status == 'failure' |
| 89 | + run: | |
| 90 | + echo "Playbook failed, marking workflow as failed" |
| 91 | + exit 1 |
0 commit comments