Skip to content

Commit

Permalink
Change CI workflows for new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
MEhrn00 committed Aug 5, 2024
1 parent 3ed81d9 commit fcb1faf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 209 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ on:
push:
branches:
- rewrite
- test/**

paths:
- Payload_Type/thanatos/agent/**
- Payload_Type/thanatos/mythic/**
- Payload_Type/thanatos/**
- .github/workflows/**
- .github/actions/**

Expand All @@ -18,14 +16,7 @@ on:
branches:
- rewrite
paths:
- Payload_Type/thanatos/agent/**
- Payload_Type/thanatos/mythic/**
- .github/workflows/**
- .github/actions/**

env:
AGENT_CODE: Payload_Type/thanatos/agent
MYTHIC_CODE: Payload_Type/thanatos/mythic
- Payload_Type/thanatos/**

jobs:
lint-workflow:
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

env:
AGENT_CODE: Payload_Type/thanatos/agent
MYTHIC_CODE: Payload_Type/thanatos/mythic
MYTHIC_CODE: Payload_Type/thanatos

jobs:
agent:
Expand Down Expand Up @@ -53,17 +53,13 @@ jobs:
run: rustup component add clippy

- name: Install system libraries
run: sudo apt-get update -y && sudo apt-get install -y libdbus-1-dev
run: sudo apt-get update -y && sudo apt-get install -y make libdbus-1-dev

- name: Lint agent code
run: |
cargo build -p genconfig
cargo clippy --workspace --color always --all-features --all-targets -- -D warnings
run: make lint

- name: Check agent code formatting
run: |
cargo build -p genconfig
cargo fmt --all -- --color always --check
run: make checkformat

mythic:
name: Mythic Code
Expand All @@ -90,4 +86,4 @@ jobs:
working-directory: ${{ env.MYTHIC_CODE }}

- name: Check Mythic code formatting
run: gofmt -l -d . | diff -u /dev/null -
run: make checkformat
222 changes: 33 additions & 189 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ on:

env:
AGENT_CODE: Payload_Type/thanatos/agent
MYTHIC_CODE: Payload_Type/thanatos/mythic
MYTHIC_CODE: Payload_Type/thanatos

jobs:
agent:
name: Agent Tests
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu, windows]

runs-on: ${{ matrix.os }}-latest
defaults:
run:
working-directory: ${{ env.AGENT_CODE }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Golang
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.MYTHIC_CODE }}/go.mod
cache-dependency-path: ${{ env.MYTHIC_CODE }}/go.sum

- name: Setup cargo cache
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -81,63 +85,16 @@ jobs:
Remove-Item .\grcov.zip
- name: Run coverage tests
working-directory: ${{ env.AGENT_CODE }}
run: |
cargo build -p genconfig
cargo test --color always --workspace --all-features --exclude config --exclude genconfig --exclude thanatos_cdylib --exclude thanatos_binary
env:
RUSTFLAGS: -Ccodegen-units=1 -Copt-level=0 -Cinstrument-coverage

- name: Generate code coverage artifacts (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
mkdir coverage
grcov ${AGENT_CODE} \
-s . \
--binary-path ${AGENT_CODE}/target/debug \
-t lcov \
--branch \
--ignore-not-existing \
--ignore "**/.cargo/registry/**" \
--ignore "*/target/*" \
--ignore "**/build.rs" \
--ignore "*/config/*" \
-o agent-linux.lcov
- name: Generate code coverage artifacts (Windows)
if: ${{ runner.os == 'Windows' }}
run: |
mkdir coverage
grcov.exe $env:AGENT_CODE `
-s . `
--binary-path $env:AGENT_CODE/target/debug `
-t lcov `
--branch `
--ignore-not-existing `
--ignore "**/.cargo/registry/**" `
--ignore "*/target/*" `
--ignore "**/build.rs" `
--ignore "*/config/*" `
-o agent-windows.lcov
- name: Upload coverage artifacts (Linux)
if: ${{ runner.os == 'Linux' }}
uses: actions/upload-artifact@v4
with:
name: Agent Code Coverage (Linux)
path: agent-linux.lcov

- name: Upload coverage artifacts (Windows)
if: ${{ runner.os == 'Windows' }}
uses: actions/upload-artifact@v4
with:
name: Agent Code Coverage (Windows)
path: agent-windows.lcov
run: make coverage

mythic:
name: Mythic Tests
runs-on: ubuntu-latest

defaults:
run:
working-directory: ${{ env.MYTHIC_CODE }}

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -152,62 +109,29 @@ jobs:
run: go install golang.org/x/tools/cmd/cover@latest

- name: Install Golang modules
working-directory: ${{ env.MYTHIC_CODE }}
run: go mod download

- name: Command tests
working-directory: ${{ env.MYTHIC_CODE }}
run: |
mkdir -p ../../../coverage
go test -coverprofile ../../../coverage/mythic.commands.gocov ./commands/...
- name: Mockbuild tests
working-directory: ${{ env.MYTHIC_CODE }}
run: go test -coverprofile ../../../coverage/mythic.builder.gocov -run "^TestPayloadMockBuild/" ./builder

- name: Filter unneeded test coverage results
working-directory: coverage
run: |
sed -i '/^thanatos\/commands\/testing\/.*$/d' mythic.commands.gocov
sed -i '/^thanatos\/commands\/commands\.go:.*$/d' mythic.commands.gocov
sed -i '/^thanatos\/commands\/utils\/mythicrpc\.go:.*$/d' mythic.commands.gocov
sed -i '/^thanatos\/builder\/testing.*\.go:.*$/d' mythic.builder.gocov
sed -i '/^thanatos\/builder\/handlers\.go:.*$/d' mythic.builder.gocov
- name: Run coverage tests
run: make coverage

- name: Combine test coverage results
run: |
cat coverage/mythic.builder.gocov > mythic.gocov
grep "^thanatos" coverage/mythic.commands.gocov >> mythic.gocov
sanitizers:
name: Sanitizer Tests
runs-on: ubuntu-latest

- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: Mythic Code Coverage
path: mythic.gocov
defaults:
run:
working-directory: ${{ env.AGENT_CODE }}

sanitizers:
name: Sanitizer Test
strategy:
fail-fast: false
matrix:
os:
- platform: ubuntu
target: x86_64-unknown-linux-gnu
- platform: windows
target: x86_64-pc-windows-msvc
sanitizer: [address]

include:
- os:
platform: ubuntu
target: x86_64-unknown-linux-gnu
sanitizer: memory

runs-on: ${{ matrix.os.platform }}-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Golang
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.MYTHIC_CODE }}/go.mod
cache-dependency-path: ${{ env.MYTHIC_CODE }}/go.sum

- name: Setup cargo cache
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -251,17 +175,12 @@ jobs:
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
- name: Run sanitizer tests for Linux
- name: Run sanitizer tests (Linux)
if: ${{ runner.os == 'Linux' }}
working-directory: ${{ env.AGENT_CODE }}
run: cargo +nightly test -Zbuild-std --color always -p ffiwrappers --all-features --target ${TARGET}
env:
RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
TARGET: ${{ matrix.os.target }}
run: make sanitizers

- name: Run sanitizer tests for Windows
- name: Run sanitizer tests (Windows)
if: ${{ runner.os == 'Windows' }}
working-directory: ${{ env.AGENT_CODE }}
run: |
$vspath = (Get-VSSetupInstance | Select-VSSetupInstance -Require Microsoft.VisualStudio.Component.VC.ASAN).InstallationPath
Import-Module $vspath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll
Expand All @@ -272,78 +191,3 @@ jobs:
TARGET: ${{ matrix.os.target }}
RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
CARGO_INCREMENTAL: 0

coverage:
name: Merge coverage artifacts
needs: [agent, mythic]
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Golang
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.MYTHIC_CODE }}/go.mod
cache-dependency-path: ${{ env.MYTHIC_CODE }}/go.sum

- name: Install Go cover
run: go install golang.org/x/tools/cmd/cover@latest

- name: Install lcov dependencies
run: sudo apt-get install -y libgd-dev libgd-perl libdatetime-perl

- name: Build lcov
run: |
yes yes | sudo cpan -T install Date::Parse Capture::Tiny GD
git clone https://github.com/linux-test-project/lcov.git /tmp/lcov
pushd /tmp/lcov
git reset --hard 49608c474b8fe7369ad96dff5935b4746a406c09
sudo make install
popd
sudo rm -rf /tmp/lcov
- name: Create coverage directory
run: mkdir -p coverage/html/{mythic,agent}

- name: Download Linux Agent coverage artifacts
uses: actions/download-artifact@v4
with:
name: Agent Code Coverage (Linux)
path: coverage

- name: Download Windows Agent coverage artifacts
uses: actions/download-artifact@v4
with:
name: Agent Code Coverage (Windows)
path: coverage

- name: Download Mythic coverage artifacts
uses: actions/download-artifact@v4
with:
name: Mythic Code Coverage
path: coverage

- name: Generate Mythic coverage html
working-directory: ${{ env.MYTHIC_CODE }}
run: go tool cover -html ../../../coverage/mythic.gocov -o ../../../coverage/html/mythic/index.html

- name: Generate Agent coverage html
run: |
lcov --add-tracefile coverage/agent-linux.lcov -a coverage/agent-windows.lcov -o coverage/agent.lcov
genhtml -o coverage/html/agent \
-f \
--dark-mode \
--show-details \
--show-navigation \
--highlight \
--ignore-errors source \
--legend \
coverage/agent.lcov
- name: Upload combined coverage artifacts
uses: actions/upload-artifact@v4
with:
name: Combined Code Coverage Report
path: coverage

0 comments on commit fcb1faf

Please sign in to comment.