diff --git a/.github/actions/docker-build-action/action.yml b/.github/actions/docker-build-action/action.yml new file mode 100644 index 0000000..7cbd246 --- /dev/null +++ b/.github/actions/docker-build-action/action.yml @@ -0,0 +1,44 @@ +name: 'Docker Build and Push' +description: 'Builds and pushes Docker images to GitHub Container Registry' +inputs: + imageName: + description: 'Name of the image to build and push' + required: true + dockerFile: + description: 'Filepath relative to the repository root' + required: true + user: + description: 'User name used for ghcr' + required: true + password: + description: 'Password for user when logging in to ghcr' + required: true +outputs: + imageTag: + description: 'The tag of the built Docker image' +runs: + using: 'composite' + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Log in to GitHub Container Registry + shell: bash + run: docker login ghcr.io -u ${{ inputs.user }} -p ${{ inputs.password }} + + - name: Pull existing Docker image + shell: bash + run: docker pull ghcr.io/${{ github.repository_owner }}/${{ inputs.imageName }} || true + + - name: Build Docker image + shell: bash + run: docker build -t ghcr.io/${{ github.repository_owner }}/${{ inputs.imageName }} -f ${{ inputs.dockerFile }} . + + - name: Push Docker image + shell: bash + run: docker push ghcr.io/${{ github.repository_owner }}/${{ inputs.imageName }} + + - name: Set output + shell: bash + run: echo "imageTag=ghcr.io/${{ github.repository_owner }}/${{ inputs.imageName }}" >> $GITHUB_OUTPUT + diff --git a/.github/workflows/build_alpine_sanitizers.yml b/.github/workflows/build_alpine_sanitizers.yml new file mode 100644 index 0000000..06dbd29 --- /dev/null +++ b/.github/workflows/build_alpine_sanitizers.yml @@ -0,0 +1,44 @@ +name: Build and Test with Alpine and Clang sanitizers + +on: [push, pull_request] + +jobs: + build-and-push-docker-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and Push Docker Image + id: docker-build + uses: ./.github/actions/docker-build-action + with: + imageName: json_struct_docker + dockerFile: docker/alpine-test.Dockerfile + user: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + test-address-sanitizer: + runs-on: ubuntu-latest + needs: build-and-push-docker-image + container: ${{ needs.build-and-push-docker-image.outputs.imageTag }} + steps: + - uses: actions/checkout@v2 + - name: Run AddressSanitizer + run: | + echo "hello ${{ needs.build-and-push-docker-image.outputs.imageTag }} world" + mkdir build && cd build + CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" -GNinja .. + ninja + ctest . + + test-memory-sanitizer: + runs-on: ubuntu-latest + needs: build-and-push-docker-image + container: ${{ needs.build-and-push-docker-image.outputs.imageTag }} + steps: + - uses: actions/checkout@v2 + - name: Run MemorySanitizer + run: | + mkdir build && cd build + CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-fsanitize=memory" -GNinja .. + ninja + ctest . diff --git a/build_asan.sh b/build_asan.sh new file mode 100644 index 0000000..99e1e39 --- /dev/null +++ b/build_asan.sh @@ -0,0 +1,3 @@ +CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" -GNinja .. +CXX=clang++ cmake -DCMAKE_CXX_FLAGS="-fsanitize=memory" -GNinja .. + diff --git a/docker/alpine-test.Dockerfile b/docker/alpine-test.Dockerfile new file mode 100644 index 0000000..a712549 --- /dev/null +++ b/docker/alpine-test.Dockerfile @@ -0,0 +1,2 @@ +FROM alpine:latest +RUN apk add vim git cmake clang ninja compiler-rt