Chore: Add GHA workflow for mono-install role
[ansible/roles/mono-install.git] / .github / workflows / gerrit-verify.yaml
1 ---
2 name: Gerrit Verify for Ansible roles
3
4 # yamllint disable-line rule:truthy
5 on:
6   workflow_dispatch:
7     inputs:
8       GERRIT_BRANCH:
9         description: "Branch that change is against"
10         required: true
11         type: string
12       GERRIT_CHANGE_ID:
13         description: "The ID for the change"
14         required: true
15         type: string
16       GERRIT_CHANGE_NUMBER:
17         description: "The Gerrit number"
18         required: true
19         type: string
20       GERRIT_CHANGE_URL:
21         description: "URL to the change"
22         required: true
23         type: string
24       GERRIT_EVENT_TYPE:
25         description: "Type of Gerrit event"
26         required: true
27         type: string
28       GERRIT_PATCHSET_NUMBER:
29         description: "The patch number for the change"
30         required: true
31         type: string
32       GERRIT_PATCHSET_REVISION:
33         description: "The revision sha"
34         required: true
35         type: string
36       GERRIT_PROJECT:
37         description: "Project in Gerrit"
38         required: true
39         type: string
40       GERRIT_REFSPEC:
41         description: "Gerrit refspec of change"
42         required: true
43         type: string
44
45 concurrency:
46   group: ${{ github.event.inputs.GERRIT_CHANGE_ID || github.run_id }}
47   cancel-in-progress: true
48
49 jobs:
50   prepare:
51     runs-on: ubuntu-latest
52     steps:
53       - name: Clear votes
54         uses: lfit/gerrit-review-action@v0.3
55         with:
56           host: ${{ vars.LFIT_GERRIT_SERVER }}
57           username: ${{ vars.LFIT_GERRIT_SSH_USER }}
58           key: ${{ secrets.LFIT_GERRIT_SSH_PRIVKEY_NP }}
59           known_hosts: ${{ vars.LFIT_GERRIT_KNOWN_HOSTS }}
60           gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
61           gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
62           vote-type: clear
63       - name: Allow replication
64         run: sleep 10s
65
66   actionlint:
67     needs: prepare
68     runs-on: ubuntu-latest
69     steps:
70       - uses: lfit/checkout-gerrit-change-action@v0.6
71         with:
72           gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
73           delay: "0s"
74       - name: Download actionlint
75         id: get_actionlint
76         run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
77         shell: bash
78       - name: Check workflow files
79         run: ${{ steps.get_actionlint.outputs.executable }} -color
80         shell: bash
81
82   # run pre-commit tox env separately to get use of more parallel processing
83   pre-commit:
84     needs: prepare
85     runs-on: ubuntu-latest
86     steps:
87       - uses: lfit/checkout-gerrit-change-action@v0.6
88         with:
89           gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
90           delay: "0s"
91       - uses: actions/setup-python@v4
92         with:
93           python-version: "3.8"
94       - name: Run static analysis and format checkers
95         run: pipx run pre-commit run --all-files --show-diff-on-failure
96
97   molecule-run:
98     needs: prepare
99     name: Molecule
100     runs-on: ubuntu-latest
101     strategy:
102       matrix:
103         distro:
104           - centos7
105           - centos8
106           - ubuntu1804
107           - ubuntu2004
108           - ubuntu2204
109       fail-fast: false
110     steps:
111       - name: Gerrit Checkout
112         # yamllint disable-line rule:line-length
113         uses: lfit/checkout-gerrit-change-action@v0.6
114         with:
115           gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
116           delay: "0s"
117       - name: Install test dependencies.
118         run: |
119           python -m pip install --upgrade pip
120           pip3 install ansible ansible-lint molecule-plugins[docker] docker
121       - name: Run Molecule tests.
122         run: molecule test
123         working-directory: ${{env.working-directory}}
124         env:
125           PY_COLORS: "1"
126           ANSIBLE_FORCE_COLOR: "1"
127           MOLECULE_PLATFORM_NAME: ${{ matrix.distro }}
128
129   vote:
130     if: ${{ always() }}
131     needs:
132       [
133         prepare,
134         actionlint,
135         pre-commit,
136         molecule-run,
137       ]
138     runs-on: ubuntu-latest
139     steps:
140       - uses: technote-space/workflow-conclusion-action@v3
141       - name: Set vote
142         uses: lfit/gerrit-review-action@v0.3
143         with:
144           host: ${{ vars.LFIT_GERRIT_SERVER }}
145           username: ${{ vars.LFIT_GERRIT_SSH_USER }}
146           key: ${{ secrets.LFIT_GERRIT_SSH_PRIVKEY_NP }}
147           known_hosts: ${{ vars.LFIT_GERRIT_KNOWN_HOSTS }}
148           gerrit-change-number: ${{ inputs.GERRIT_CHANGE_NUMBER }}
149           gerrit-patchset-number: ${{ inputs.GERRIT_PATCHSET_NUMBER }}
150           vote-type: ${{ env.WORKFLOW_CONCLUSION }}