From 83e8a49708f65c4a1839afe16573f77bf571d157 Mon Sep 17 00:00:00 2001 From: Gabriel Becker Date: Mon, 25 Oct 2021 12:38:12 +0200 Subject: [PATCH] Add github workflow action to output the diff of datastreams. --- .github/workflows/compare-ds.yaml | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/compare-ds.yaml diff --git a/.github/workflows/compare-ds.yaml b/.github/workflows/compare-ds.yaml new file mode 100644 index 000000000000..71d6fea1c617 --- /dev/null +++ b/.github/workflows/compare-ds.yaml @@ -0,0 +1,92 @@ +name: Compare DS +on: + pull_request_target: + branches: [ master ] +jobs: + build-content: + name: Generate Diff + runs-on: ubuntu-latest + container: + image: fedora:latest + steps: + - name: Install Deps + run: dnf install -y cmake make openscap-utils python3-pyyaml python3-jinja2 git python3-deepdiff python3-requests jq python3-pip + - name: Install deps python + run: pip install gitpython xmldiff + - name: Checkout master + uses: actions/checkout@v2 + with: + ref: master + - name: Checkout (CTF) + uses: actions/checkout@v2 + with: + repository: mildas/content-test-filtering + path: ctf + - name: Detect content changes in the PR + run: python3 ./ctf/content_test_filtering.py pr --rule --output json ${{ github.event.pull_request.number }} > output.json + - name: Test if there are no content changes + run: echo "::set-output name=CTF_OUTPUT_SIZE::$(stat --printf="%s" output.json)" + id: ctf + - name: Print changes to content detected if any + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + run: cat output.json + - name: Get product attribute + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + id: product + uses: notiz-dev/github-action-json-property@release + with: + path: 'output.json' + prop_path: 'product' + - name: Build product (master) + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + run: ./build_product ${{steps.product.outputs.prop}} --datastream-only + - name: Copy built datastream stream to be compared + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + run: cp build/ssg-${{steps.product.outputs.prop}}-ds.xml ssg-${{steps.product.outputs.prop}}-ds.xml + - name: Checkout + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + uses: actions/checkout@v2 + with: + clean: false + - name: Build product + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + run: ./build_product ${{steps.product.outputs.prop}} --datastream-only + - name: Compare datastreams + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + run: utils/compare_ds.py ssg-${{steps.product.outputs.prop}}-ds.xml build/ssg-${{steps.product.outputs.prop}}-ds.xml | tee diff.log + env: + PYTHONPATH: ${{ github.workspace }} + - name: Get diff.log + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + id: diff + run: | + body=$(cat diff.log) + body="${body//'%'/'%25'}" + body="${body//$'\n'/'%0A'}" + body="${body//$'\r'/'%0D'}" + echo ::set-output name=log::$body + - name: Find Comment + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Datastream diff output + - name: Create or update comment + if: ${{ steps.ctf.outputs.CTF_OUTPUT_SIZE != '0' }} + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + This datastream diff is auto generated by the check `Compare DS/Generate Diff` +
+ Click here to see the full diff + + ```diff + ${{ steps.diff.outputs.log }} + ``` + +
+ edit-mode: replace