Skip to content

Commit b397f9c

Browse files
authored
Merge pull request #29 from Shayan-Ghani/actions
feat : github actions linting on push and pull request
2 parents c92c6a5 + 0baa382 commit b397f9c

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

.github/workflows/test.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: BVSTACK CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- actions
8+
pull_request:
9+
branches:
10+
- main
11+
12+
env:
13+
VAULT_ADDR: ${{ vars.VAULT_ADDR }}
14+
VAULT_TOKEN: ${{ vars.VAULT_TOKEN }}
15+
BOUNDARY_ADDR: ${{ vars.BOUNDARY_ADDR }}
16+
17+
jobs:
18+
lint-boundary-terraform:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: "boundary/terraform/"
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: setup terraform cli
28+
uses: hashicorp/setup-terraform@v3
29+
30+
- name: Terraform fmt
31+
id: fmt
32+
run: terraform fmt -check
33+
continue-on-error: true
34+
35+
- name: Terraform Init
36+
id: init
37+
run: terraform init
38+
39+
- name: Terraform Validate
40+
id: validate
41+
run: terraform validate -no-color
42+
43+
- name: validate stdout
44+
run: echo "${{ steps.validate.outputs.stdout }}"
45+
46+
- name: validate sterr
47+
run: echo "${{ steps.validate.outputs.stderr }}"
48+
49+
- name: validate exitcode
50+
run: echo "${{ steps.validate.outputs.exitcode }}"
51+
52+
lint-vault-terraform:
53+
runs-on: ubuntu-latest
54+
defaults:
55+
run:
56+
working-directory: "vault/terraform/"
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@v4
60+
61+
- name: setup terraform cli
62+
uses: hashicorp/setup-terraform@v3
63+
64+
- name: Terraform fmt
65+
id: fmt
66+
run: terraform fmt -check
67+
continue-on-error: true
68+
69+
- name: Terraform Init
70+
id: init
71+
run: terraform init
72+
73+
- name: Terraform Validate
74+
id: validate
75+
run: terraform validate -no-color
76+
77+
- run: echo ${{ steps.plan.outputs.stdout }}
78+
- run: echo ${{ steps.plan.outputs.stderr }}
79+
- run: echo ${{ steps.plan.outputs.exitcode }}
80+
81+
lint-ansible:
82+
runs-on: ubuntu-latest
83+
defaults:
84+
run:
85+
working-directory: ./scripts
86+
shell: bash
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v4
90+
91+
- name: setup python
92+
uses: actions/setup-python@v5
93+
with:
94+
python-version: '3.10'
95+
cache: 'pip'
96+
97+
- name: install ansible
98+
run: |
99+
pip install -U pip
100+
pip install ansible wheel
101+
102+
- name: check playbook and role's syntax
103+
run: bash linter.sh ansible

scripts/linter.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
function lint_terraform(){
46

57
if ! command -v terraform &> /dev/null; then
@@ -43,4 +45,23 @@ function lint_docker () {
4345

4446
return 0
4547

46-
}
48+
}
49+
50+
function lint_ansible () {
51+
52+
cd ../ansible || { echo "Failed to change directory to ansible"; return 1; }
53+
54+
playbooks=$(find . -maxdepth 1 -name "*.yml" -print)
55+
for play in $playbooks; do
56+
if ! ansible-playbook $play --syntax-check &> /dev/null; then
57+
echo "Ansible Syntax Error: syntax check failed for $play, check the underlying roles!"
58+
return 3
59+
fi
60+
echo "$play is fine in terms of syntax!"
61+
done
62+
return 0
63+
}
64+
65+
if [ $1 == "ansible" ]; then
66+
lint_ansible
67+
fi

0 commit comments

Comments
 (0)