name: Acceptance tests

on: 
  push:
    branches:
      - master
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs: 
 
  acceptance-tests:
    runs-on: ubuntu-18.04

    steps:
      - uses: actions/checkout@v2
      - name: Build and run docker image for cross compiling
        run: |
          cd test/artificial_samples
          docker build -t cross_compiling .
          docker run --rm -v $(pwd)/build:/home/cwe/artificial_samples/build cross_compiling sudo python3 -m SCons
      - uses: actions/setup-java@v1
        with:
          java-version: "11.0.x"
          java-package: jdk
          architecture: x64
      - name: Install Ghidra
        run: |
          curl -fSL https://www.ghidra-sre.org/ghidra_9.2.1_PUBLIC_20201215.zip -o ghidra.zip
          unzip -q ghidra.zip
          mv ghidra_9.2.1_PUBLIC /opt/ghidra
          rm ghidra.zip
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Install cwe_checker
        run: make all GHIDRA_PATH=/opt/ghidra
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: --no-fail-fast -p acceptance_tests_ghidra -- --show-output --ignored --test-threads 1

  docker-build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Build the docker image
        run: docker build -t cwe_checker .
      - name: Check functionality of the image
        run: docker run --rm cwe_checker /bin/echo | grep -q CWE676