Skip to content

Commit c1a444c

Browse files
authored
Add workflows for PR validation tasks and labeling (cloudera-labs#84)
Signed-off-by: Webster Mudge <[email protected]>
1 parent 90ec105 commit c1a444c

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

.github/workflows/label_pr.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
3+
4+
name: Label validated Pull Request
5+
6+
on:
7+
workflow_run:
8+
workflows: ["Validate Pull Request"]
9+
types:
10+
- completed
11+
12+
jobs:
13+
label:
14+
permissions:
15+
contents: read
16+
pull-requests: write
17+
runs-on: ubuntu-latest
18+
if: >
19+
github.event.workflow_run.event == 'pull_request' &&
20+
github.event.workflow_run.conclusion == 'success'
21+
steps:
22+
- name: Download the PR number artifact
23+
uses: actions/github-script@v6
24+
with:
25+
script: |
26+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
run_id: context.payload.workflow_run.id,
30+
});
31+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
32+
return artifact.name == "pr_number"
33+
})[0];
34+
let download = await github.rest.actions.downloadArtifact({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
artifact_id: matchArtifact.id,
38+
archive_format: 'zip',
39+
});
40+
let fs = require('fs');
41+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
42+
43+
- name: 'Unzip artifact'
44+
run: unzip pr_number.zip
45+
46+
- name: Read the PR number
47+
id: read
48+
run: echo "pr_number=$(cat pr_number)" >> $GITHUB_OUTPUT
49+
50+
- name: Label the PR
51+
uses: actions-ecosystem/action-add-labels@v1
52+
with:
53+
labels: validated
54+
number: ${{ steps.read.outputs.pr_number }}

.github/workflows/reset_pr.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
3+
name: Reset Pull Request validation label
4+
5+
on:
6+
pull_request_target:
7+
types:
8+
- reopened
9+
- synchronize
10+
- ready_for_review
11+
branches:
12+
- 'release/**'
13+
- 'devel'
14+
- 'devel-pvc-base'
15+
16+
jobs:
17+
reset:
18+
permissions:
19+
contents: read
20+
pull-requests: write
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Reset the PR label
24+
uses: actions-ecosystem/action-remove-labels@v1
25+
with:
26+
labels: validated

.github/workflows/validate_pr.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
3+
name: Validate Pull Request
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- 'release/**'
9+
- 'devel'
10+
- 'devel-pvc-base'
11+
12+
jobs:
13+
validate:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
19+
- name: Setup Python and caching
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.9'
23+
cache: 'pip'
24+
25+
- name: Set up Ansible collections
26+
run: |
27+
sudo update-alternatives --install /usr/bin/python python $(which python3) 1
28+
pip install ansible-core==2.12 ansible-builder pycodestyle voluptuous pylint pyyaml ansible-lint
29+
ansible-galaxy collection install -r builder/requirements.yml -p /usr/share/ansible/collections
30+
#ansible-galaxy role install -r builder/requirements.yml -p /usr/share/ansible/roles
31+
32+
- name: Report Ansible version, collections, and roles
33+
run: |
34+
ansible --version
35+
ansible-galaxy collection list
36+
#ansible-galaxy role list
37+
38+
- name: Set up Ansible collection dependencies
39+
run: |
40+
ansible-builder introspect \
41+
--write-pip final_python.txt --write-bindep final_bindep.txt \
42+
/usr/share/ansible/collections
43+
pip install -r final_python.txt
44+
sudo apt-get -y install $(cat final_bindep.txt)
45+
46+
- name: Report installed Python dependencies
47+
run: pip freeze
48+
49+
- name: Validate collection
50+
run: |
51+
pushd /usr/share/ansible/collections/ansible_collections/cloudera/cloud
52+
#ansible-lint
53+
#ansible-test sanity --test pep8
54+
#ansible-test sanity --test validate-modules
55+
#ansible-test units --requirements --color yes --redact
56+
popd
57+
58+
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
59+
- name: Save PR number
60+
env:
61+
PR_NUMBER: ${{ github.event.number }}
62+
run: |
63+
mkdir -p ./pr
64+
echo $PR_NUMBER > ./pr/pr_number
65+
66+
- name: Upload the PR number
67+
uses: actions/upload-artifact@v3
68+
with:
69+
name: pr_number
70+
path: pr/

builder/requirements.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
3+
collections:
4+
- source: .
5+
type: dir

0 commit comments

Comments
 (0)