Skip to content

Commit

Permalink
Merge pull request #2 from kubewarden/reusable-workflows
Browse files Browse the repository at this point in the history
Use GHA reusable workflows from kubewarden/github-actions
  • Loading branch information
flavio authored Jan 26, 2022
2 parents 61ff21e + ed4dcea commit 25815b6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 176 deletions.
164 changes: 0 additions & 164 deletions .github/workflows/ci.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
branches:
- main
tags:
- 'v*'

name: Release policy

jobs:

test:
name: run tests and linters
uses: kubewarden/github-actions/.github/workflows/reusable-test-policy-go.yml@v1

release:
needs: test
permissions:
# Required to push to GHCR
contents: read
# Required to create GH releases
packages: write
# Required by cosign keyless signing
id-token: write

uses: kubewarden/github-actions/.github/workflows/reusable-release-policy-go.yml@v1
with:
oci-target: ghcr.io/${{ github.repository_owner }}/policies/volumes-psp
secrets:
workflow-pat: ${{ secrets.WORKFLOW_PAT }}
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
on: [push, pull_request]
name: Continuous integration
jobs:
test:
name: run tests and linters
uses: kubewarden/github-actions/.github/workflows/reusable-test-policy-go.yml@v1
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
wasm: go.mod go.sum *.go
docker run --rm -v ${PWD}:/src -w /src tinygo/tinygo:0.18.0 tinygo build -o policy.wasm -target=wasi -no-debug .
SOURCE_FILES := $(shell find . -type f -name '*.go')

annotate:
kwctl annotate -m metadata.yml -o annotated.wasm policy.wasm
policy.wasm: $(SOURCE_FILES) go.mod go.sum
docker run --rm -v ${PWD}:/src -w /src tinygo/tinygo:0.18.0 tinygo build \
-o policy.wasm -target=wasi -no-debug .

annotated-policy.wasm: policy.wasm metadata.yml
kwctl annotate -m metadata.yml -o annotated-policy.wasm policy.wasm

.PHONY: test
test:
go test -v

e2e-tests:
.PHONY: e2e-tests
e2e-tests: annotated-policy.wasm
bats e2e.bats

.PHONY: clean
clean:
go clean
rm -f policy.wasm
rm -f policy.wasm annotated-policy.wasm
12 changes: 6 additions & 6 deletions e2e.bats
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bats

@test "reject because allowedTypes is empty" {
run kwctl run policy.wasm -r test_data/request-pod-volumes.json \
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": [] }'

Expand All @@ -15,7 +15,7 @@
}

@test "reject because types not present" {
run kwctl run policy.wasm -r test_data/request-pod-volumes.json \
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": ["foo", "hostPath"] }'

Expand All @@ -29,7 +29,7 @@
}

@test "reject because mix of '*' and other types" {
run kwctl run policy.wasm -r test_data/request-pod-volumes.json \
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": ["projected", "hostPath", "*"] }'

Expand All @@ -43,7 +43,7 @@
}

@test "accept all types" {
run kwctl run policy.wasm -r test_data/request-pod-volumes.json \
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": [ "*" ] }'

Expand All @@ -56,7 +56,7 @@
}

@test "accept pods with no volumes" {
run kwctl run policy.wasm -r test_data/request-pod-no-volumes.json \
run kwctl run annotated-policy.wasm -r test_data/request-pod-no-volumes.json \
--settings-json \
'{ "allowedTypes": [ "foo" ] }'

Expand All @@ -70,7 +70,7 @@


@test "accept pods with correct types" {
run kwctl run policy.wasm -r test_data/request-pod-volumes.json \
run kwctl run annotated-policy.wasm -r test_data/request-pod-volumes.json \
--settings-json \
'{ "allowedTypes": [ "hostPath", "projected", "foo" ] }'

Expand Down

0 comments on commit 25815b6

Please # to comment.