From f027a8cc23c6b59c877f64e1ae4cc10e800f0129 Mon Sep 17 00:00:00 2001 From: Vincent Shen Date: Wed, 21 Feb 2024 19:58:22 -0800 Subject: [PATCH] OCP4: Add workflow to test ocp content Add this workflow so we can test ocp4 content can be parsed on each PR --- .github/workflows/automatus-cs8.yaml | 3 ++ .github/workflows/k8s-content-pr-test.yaml | 58 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/k8s-content-pr-test.yaml diff --git a/.github/workflows/automatus-cs8.yaml b/.github/workflows/automatus-cs8.yaml index 5980544ee807..052b05d8d80a 100644 --- a/.github/workflows/automatus-cs8.yaml +++ b/.github/workflows/automatus-cs8.yaml @@ -4,6 +4,9 @@ on: branches: [ master, 'stabilization*' ] env: DATASTREAM: ssg-centos8-ds.xml +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: build-content: name: Build Content diff --git a/.github/workflows/k8s-content-pr-test.yaml b/.github/workflows/k8s-content-pr-test.yaml new file mode 100644 index 000000000000..8f03a1f280e0 --- /dev/null +++ b/.github/workflows/k8s-content-pr-test.yaml @@ -0,0 +1,58 @@ +--- +name: Gate / Kubernetes Test Content Parsing + +on: + pull_request: + types: + - opened + - reopened + - synchronize + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + datastream-parsing: + name: Fetch XCCDF files from existing content image + runs-on: ubuntu-latest + steps: + - name: Copy XCCDF files from existing content image + uses: nick-fields/retry@v3 + with: + timeout_minutes: 15 + max_attempts: 3 + retry_wait_seconds: 120 + retry_on: error + command: | + mkdir -p content + docker pull ghcr.io/complianceascode/k8scontent:${{ github.event.number }} + docker run --rm -v $PWD/content:/content:z ghcr.io/complianceascode/k8scontent:${{ github.event.number }} bash -c "cp *.xml /content" + - name: Clone compliance operator repository + run: | + git clone https://github.com/ComplianceAsCode/compliance-operator.git + - uses: actions/setup-go@v5 + with: + go-version: '>=1.19.0' + - run: go version + - name: Install ginkgo + run: | + go install github.com/onsi/ginkgo/ginkgo@latest + - name: Run ginkgo tests and check if each XCCDF file is parsed correctly + run: | + export CONTENT_FOLDER=$PWD/content + cd compliance-operator + for file in $CONTENT_FOLDER/*.xml; do + export DEFAULT_CONTENT_DS_FILE_PATH=$file + ginkgo --focus "Testing for correct content parsing" ./pkg/utils | tee /tmp/ginkgo_output + if grep -q "0 Passed" /tmp/ginkgo_output && grep -q "0 Failed" /tmp/ginkgo_output; then + echo "XCCDF file $file is not parsed correctly" + exit 1 + elif grep -q "SUCCESS!" /tmp/ginkgo_output; then + echo "XCCDF file $file is parsed correctly" + else + echo "XCCDF file $file is not parsed correctly" + exit 1 + fi + done +