Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: GNU
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
groups:
actions:
patterns: ['*']
- package-ecosystem: cargo
directories: [/imgconvert, /imgcrop, /pypaste]
schedule:
interval: weekly
cooldown:
default-days: 7
groups:
rust:
patterns: ['*']
40 changes: 40 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Analysis

on:
schedule:
- cron: '34 5 * * 4'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: analysis-${{ github.ref }}
cancel-in-progress: false

jobs:
codeql:
strategy:
fail-fast: false
matrix:
language: [actions, rust, c-cpp]
permissions:
contents: read
security-events: write
uses: cleisson-labs/.github/.github/workflows/codeql.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0
with:
language: ${{ matrix.language }}

rust-audit:
strategy:
fail-fast: false
matrix:
project: [imgconvert, imgcrop, pypaste]
uses: cleisson-labs/.github/.github/workflows/rust-audit.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0
with:
working-directory: ${{ matrix.project }}

external-links:
uses: cleisson-labs/.github/.github/workflows/docs.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0
with:
external: true
34 changes: 34 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Scorecard
on:
push:
branches: [main]
schedule:
- cron: '31 6 * * 4'
permissions: {}
cache-mode: none
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
scorecard:
runs-on: ubuntu-24.04
timeout-minutes: 12
permissions:
contents: read
id-token: write
security-events: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Analyze and publish the public result
uses: ossf/scorecard-action@23f22cd43608bae7a1f1fa2603d7314dee9538a5 # v2.6.0
with:
results_file: scorecard.sarif
results_format: sarif
publish_results: true
fail_on_publish_error: true
- name: Upload code scanning results
uses: github/codeql-action/upload-sarif@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
with:
sarif_file: scorecard.sarif
91 changes: 75 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,91 @@
name: Run All Tests
name: CI

on:
push:
pull_request:
push:
branches: [main]

permissions:
contents: read

concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
test:
runs-on: ubuntu-latest
security:
uses: cleisson-labs/.github/.github/workflows/security.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0

steps:
- name: Checkout repository
uses: actions/checkout@v4
docs:
uses: cleisson-labs/.github/.github/workflows/docs.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
all-tools:
runs-on: ubuntu-latest
timeout-minutes: 25
env:
RUSTUP_TOOLCHAIN: stable
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
components: rustfmt, clippy

- name: Install C dependencies
persist-credentials: false
- name: Set up Rust
run: rustup toolchain install stable --profile minimal --component rustfmt --component clippy
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: |
imgconvert
imgcrop
pypaste
save-if: ${{ github.event_name == 'push' }}
cache-bin: false
- name: Install build and shell lint dependencies
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev shellcheck

sudo apt-get install -y --no-install-recommends libcurl4-openssl-dev shellcheck
- name: Verify committed dependency locks
run: |
for manifest in */Cargo.toml; do
cargo metadata --locked --format-version=1 --manifest-path "$manifest" > /dev/null
done
- name: Run all lint checks
run: ./.scripts/lint_all.sh

- name: Build all tools
run: ./.scripts/build_all.sh

- name: Run all tests
run: ./.scripts/test_all.sh

c:
strategy:
fail-fast: false
matrix:
project: [raw_http, workpay]
uses: cleisson-labs/.github/.github/workflows/c.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0
with:
working-directory: ${{ matrix.project }}
apt-packages: libcurl4-openssl-dev
coverage: true
sanitizers: true

codeql:
strategy:
fail-fast: false
matrix:
language: [actions, rust, c-cpp]
permissions:
contents: read
security-events: write
uses: cleisson-labs/.github/.github/workflows/codeql.yml@03f53ed9e71b2741c683c448a538f7a7b8aa1786 # v1.0.0
with:
language: ${{ matrix.language }}

ci-ok:
if: always()
needs: [security, docs, codeql, all-tools, c]
runs-on: ubuntu-latest
timeout-minutes: 3
permissions: {}
steps:
- name: Require every CI job to pass
env:
RESULTS: ${{ toJSON(needs) }}
run: jq -e 'length > 0 and all(.[]; .result == "success")' <<< "$RESULTS"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
ai_tasks/
# Native test and coverage artifacts
*.dSYM/
*.gcno
*.gcda
15 changes: 15 additions & 0 deletions .scripts/c-checks.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Each C tool keeps its own sources, flags and test entry point.
.PHONY: analyze sanitize coverage

analyze:
cppcheck --std=c11 --enable=warning,performance,portability --error-exitcode=1 \
$(CPPFLAGS) src tests

sanitize:
UBSAN_OPTIONS=halt_on_error=1 $(MAKE) test \
CFLAGS="$(CFLAGS) -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer"

coverage:
rm -f ./*.gcda ./*.gcno
$(MAKE) build test CFLAGS="$(CFLAGS) -O0 -g --coverage"
gcovr --root . --filter 'src/' --txt --print-summary
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CLI Tools Collection

[![CI](https://github.com/cleisson-labs/cli_tools/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/cleisson-labs/cli_tools/actions/workflows/tests.yml)
[![License](https://img.shields.io/github/license/cleisson-labs/cli_tools)](LICENSE)
[![Coverage report](https://img.shields.io/badge/coverage-C%20report-blue)](https://github.com/cleisson-labs/cli_tools/actions/workflows/tests.yml)

A multi-language set of focused command-line tools for everyday workflows.

## Tools
Expand All @@ -10,7 +14,7 @@ A multi-language set of focused command-line tools for everyday workflows.
| `imgcrop` | Rust | Crops images to exact dimensions with optional proportion/framing controls. | `cd imgcrop && make build` | `cd imgcrop && make test` |
| `pypaste` | Rust | Compacts Python scripts for terminal pasting and copies output to clipboard. | `cd pypaste && make build` | `cd pypaste && make test` |
| `raw_http` | C (libcurl) | Sends raw HTTP requests from `.txt` files and prints/saves full responses. | `cd raw_http && make build` | `cd raw_http && make test` |
| `workpay` | C (libcurl) | Calculates earnings from worked time and converts currencies via AwesomeAPI. | `cd workpay && make build` | `N/A` (no `test` target in `Makefile`) |
| `workpay` | C (libcurl) | Calculates earnings from worked time and converts currencies via AwesomeAPI. | `cd workpay && make build` | `cd workpay && make test` |

Detailed per-tool docs:
- [imgconvert/README.md](imgconvert/README.md)
Expand Down Expand Up @@ -45,6 +49,13 @@ Use the repository scripts from the repository root:
./.scripts/test_all.sh
```

CI runs the same lint, build and test scripts on Linux and checks changed C
lines with clang-format's GNU style. For either C tool,
`make -C raw_http analyze` runs Cppcheck, `make -C raw_http sanitize CC=clang`
runs the tests with AddressSanitizer and UndefinedBehaviorSanitizer, and
`make -C raw_http coverage CC=gcc` prints a gcovr report. Replace `raw_http`
with `workpay` to check that tool. Coverage requires GCC and gcovr.

Install built binaries from a local clone:

```bash
Expand Down
2 changes: 2 additions & 0 deletions raw_http/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ test:

clean:
@rm -f raw_http test_parse test_cli_output

include ../.scripts/c-checks.mk
2 changes: 2 additions & 0 deletions workpay/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ test:

clean:
@rm -f workpay test_parse test_money test_cli test_quota test_report_store test_report_query test_report_export

include ../.scripts/c-checks.mk
24 changes: 16 additions & 8 deletions workpay/tests/test_quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ get_today_date (char *output, size_t output_size)
struct tm local_time;

assert (now != (time_t)-1);
assert (localtime_r (&now, &local_time) != NULL);
assert (strftime (output, output_size, "%Y-%m-%d", &local_time) != 0);
struct tm *result = localtime_r (&now, &local_time);
assert (result != NULL);
size_t length = strftime (output, output_size, "%Y-%m-%d", &local_time);
assert (length != 0);
}

static void
Expand All @@ -28,15 +30,17 @@ create_temp_usage_file_path (char *output, size_t output_size)
fd = mkstemp (output);
assert (fd != -1);
close (fd);
assert (remove (output) == 0);
int cleanup_result = remove (output);
assert (cleanup_result == 0);
}

static void
write_usage_file (const char *path, const char *date, int request_count)
{
FILE *file = fopen (path, "w");
assert (file != NULL);
assert (fprintf (file, "%s %d\n", date, request_count) > 0);
int written = fprintf (file, "%s %d\n", date, request_count);
assert (written > 0);
fclose (file);
}

Expand All @@ -47,7 +51,8 @@ read_usage_count (const char *path, char *date_output, size_t date_output_size)
int request_count = -1;

assert (file != NULL);
assert (fscanf (file, "%15s %d", date_output, &request_count) == 2);
int fields = fscanf (file, "%15s %d", date_output, &request_count);
assert (fields == 2);
fclose (file);

(void)date_output_size;
Expand All @@ -73,7 +78,8 @@ test_first_request_creates_usage_file (void)
assert (request_count == 1);

assert (unsetenv ("WORKPAY_USAGE_FILE") == 0);
assert (remove (path) == 0);
int cleanup_result = remove (path);
assert (cleanup_result == 0);
}

static void
Expand All @@ -96,7 +102,8 @@ test_request_99_advances_to_100 (void)
assert (request_count == 100);

assert (unsetenv ("WORKPAY_USAGE_FILE") == 0);
assert (remove (path) == 0);
int cleanup_result = remove (path);
assert (cleanup_result == 0);
}

static void
Expand All @@ -119,7 +126,8 @@ test_limit_reached_at_100 (void)
assert (request_count == 100);

assert (unsetenv ("WORKPAY_USAGE_FILE") == 0);
assert (remove (path) == 0);
int cleanup_result = remove (path);
assert (cleanup_result == 0);
}

int
Expand Down
6 changes: 4 additions & 2 deletions workpay/tests/test_report_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ test_csv_export_writes_expected_header_and_rows (void)
assert (strstr (content, "alpha") != NULL);
assert (strstr (content, "beta") != NULL);

assert (remove (output_path) == 0);
int cleanup_result = remove (output_path);
assert (cleanup_result == 0);
}

static void
Expand All @@ -91,7 +92,8 @@ test_json_export_writes_expected_fields (void)
assert (strstr (content, "\"from_currency\": \"USD\"") != NULL);
assert (strstr (content, "alpha \\\"quoted\\\"") != NULL);

assert (remove (output_path) == 0);
int cleanup_result = remove (output_path);
assert (cleanup_result == 0);
}

static void
Expand Down
Loading
Loading