Skip to content

Commit dba0414

Browse files
authored
Added go//konstraint and raw option (#25)
1 parent a894f67 commit dba0414

5 files changed

Lines changed: 58 additions & 12 deletions

File tree

.github/workflows/confbatstest.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v2
1919

20-
- name: Conftest
20+
- name: confbatstest - tests
2121
uses: ./confbatstest
2222
with:
23-
tests: confbatstest/_test/conftest.sh
23+
tests: confbatstest/_test/conftest.sh
24+
25+
- name: confbatstest - raw
26+
uses: ./confbatstest
27+
with:
28+
raw: konstraint doc -o POLICIES.md
29+
30+
- name: Check POLICIES.md file exists
31+
run: |
32+
FILE="POLICIES.md"
33+
if [ -f "$FILE" ]; then
34+
echo "$FILE exists."
35+
else
36+
echo "$FILE does not exist."
37+
exit 1
38+
fi

confbatstest/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.2
22

3-
LABEL version="1.2.1"
3+
LABEL version="1.3.0"
44
LABEL repository="http://github.com/redhat-cop/github-actions"
55
LABEL homepage="http://github.com/redhat-cop/github-actions/confbatstest"
66
LABEL maintainer="Red Hat CoP"
@@ -48,6 +48,16 @@ RUN export OC_VERSION=4.4 && \
4848
ln -s /tmp/oc /usr/local/bin/oc && \
4949
oc version
5050

51+
RUN export GO_VERSION=1.14 && \
52+
wget --no-verbose https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
53+
tar -C /tmp -xzf go${GO_VERSION}.linux-amd64.tar.gz && \
54+
ln -s /tmp/go/bin/go /usr/local/bin/go && \
55+
go version
56+
57+
RUN GO111MODULE=on go get github.com/plexsystems/konstraint && \
58+
ln -s ~/go/bin/konstraint /usr/local/bin/konstraint && \
59+
konstraint --help
60+
5161
RUN pip3 install yq && \
5262
yq --version
5363

confbatstest/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ It also contains several tools which are used for JSON and YAML manipulation:
1010
- oc
1111

1212
## Usage
13-
13+
Execute a BATS file which contains conftest tests.
1414
```yaml
1515
- name: Conftest
1616
uses: redhat-cop/github-actions/confbatstest@master
1717
with:
1818
tests: _test/conftest.sh
1919
policies: '[{"name": "redhat-cop", "url":"github.com/redhat-cop/rego-policies.git//policy"},{"name": "deprek8ion", "url":"github.com/swade1987/deprek8ion.git//policies"}]'
20+
```
21+
22+
Execute a command, such as konstraint to generate rego policy documentation.
23+
```yaml
24+
- name: Conftest
25+
uses: redhat-cop/github-actions/confbatstest@master
26+
with:
27+
raw: konstraint doc -o POLICIES.md
2028
```

confbatstest/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ inputs:
1010
default: "_test/conftest.sh"
1111
required: false
1212
policies:
13-
description: "JSON array of policies to pull via conftest pull. See: https://github.com/open-policy-agent/conftest/blob/master/docs/sharing.md"
13+
description: "JSON array of policies to pull via conftest. See: https://github.com/open-policy-agent/conftest/blob/master/docs/sharing.md"
1414
default: '[{"name": "redhat-cop", "url":"github.com/redhat-cop/rego-policies.git//policy"},{"name": "deprek8ion", "url":"github.com/swade1987/deprek8ion.git//policies"}]'
1515
required: false
16+
raw:
17+
description: "Execute a single command, i.e.: konstraint doc -o POLICIES.md"
18+
required: false
1619

1720
runs:
1821
using: 'docker'
1922
image: 'Dockerfile'
2023
args:
2124
- ${{ inputs.tests }}
22-
- ${{ inputs.policies }}
25+
- ${{ inputs.policies }}
26+
- ${{ inputs.raw }}

confbatstest/entrypoint.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ exec_bats() {
3131

3232
conftest pull "${url}" --policy "${name}"
3333

34-
# shellcheck disable=SC2038
35-
for file in $(find "${name}"/* -name "*.rego" -type f | xargs) ; do
36-
cp "${file}" "policy/${file////_}"
37-
done
38-
34+
# Move pulled policies into main policy dir
35+
mv "${name}"/* policy/
3936
rm -rf "${name}"
4037
done
4138

@@ -49,4 +46,16 @@ exec_bats() {
4946
exec bats "${TESTS}"
5047
}
5148

52-
exec_bats "${1}" "${2}"
49+
exec_raw() {
50+
local COMMAND="${1}"
51+
52+
echo "Executing: ${COMMAND}"
53+
54+
eval "${COMMAND}"
55+
}
56+
57+
if [[ -z "${3}" ]]; then
58+
exec_bats "${1}" "${2}"
59+
else
60+
exec_raw "${3}"
61+
fi

0 commit comments

Comments
 (0)