Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage instrumentation to CI pipeline #68

Merged
merged 5 commits into from
Dec 25, 2024
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
2 changes: 2 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[profile.default]
slow-timeout = { period = "500ms", terminate-after = 5, grace-period = "2s" }
47 changes: 42 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,49 @@ jobs:
- name: Setup Rust cache
uses: swatinem/rust-cache@v2
- name: Build
run: cargo build --release --all-targets
run: cargo build --all-targets --all-features
- name: Clippy
run: cargo clippy --no-deps --release --all-targets
# The tests depend on the 'herostratus' binary that 'cargo build' built
run: cargo clippy --no-deps --all-targets --all-features

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: llvm-tools-preview
- name: Setup Rust cache
uses: swatinem/rust-cache@v2
- name: Setup nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest,cargo-llvm-cov
- name: Test
run: |
git fetch
cargo test --release --all-targets
cargo test --release --all-targets -- --ignored required
cargo llvm-cov --no-report nextest --all-targets --all-features
cargo llvm-cov report --cobertura --output-path coverage.xml
head coverage.xml
RATE="$(grep -o -m 1 -P '(?<=line-rate=").*?(?=")' coverage.xml | head -1)"
echo "RATE=$RATE"
PERCENT="$(echo "($RATE * 100)/1" | bc)"
echo "PERCENT=$PERCENT"
echo "COVERAGE_PERCENT=$PERCENT" >> $GITHUB_ENV
- name: Update coverage badge
uses: schneegans/[email protected]
if: github.ref_name == github.event.repository.default_branch
with:
# https://github.com/Notgnoshi/herostratus/settings/secrets/actions
# https://github.com/settings/personal-access-tokens
# https://gist.github.com/Notgnoshi/b20aa388c90ca92aba6aa37ec55a7f12
# https://github.com/marketplace/actions/dynamic-badges
auth: ${{ secrets.HEROSTRATUS_COVERAGE_GIST_TOKEN }}
gistID: b20aa388c90ca92aba6aa37ec55a7f12
filename: herostratus-coverage.json
label: Code Coverage
message: "${{ env.COVERAGE_PERCENT }}%"
valColorRange: ${{ env.COVERAGE_PERCENT }}
minColorRange: 60
maxColorRange: 95
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
# https://github.com/Notgnoshi/herostratus/settings/secrets/actions
# https://github.com/settings/personal-access-tokens
token: ${{ secrets.HEROSTRATUS_RELEASE_TOKEN }}
- name: Validate SemVer Version
shell: bash # Explicitly setting the shell sets errexit and pipefail flags
Expand Down
30 changes: 18 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ These changelog entries will automatically be added to the project release notes
focus on the user impact** rather than the actual changes made.

# Herostratus - Unreleased - (YYYY-MM-DD)

<!-- Please add new changelog entries here -->

## Added

* Added the following rules:
| ID | Description |
|-------------------------|--------------------------------------------------|
| H3-longest-subject-line | Find the commit with the longest subject line |
| H4-non-unicode | Make a commit message containing non UTF-8 bytes |
* | Added the following rules: | ID | Description |
| ------------------------------------------- | --------------------------------------------- | ----------- |
| H3-longest-subject-line | Find the commit with the longest subject line | |
| a commit message containing non UTF-8 bytes | | |

* You can now configure rules on a per-rule basis. The following rules and options are supported:

Expand All @@ -36,9 +36,13 @@ focus on the user impact** rather than the actual changes made.
```

## Changed

## Deprecated

## Removed

## Fixed

## Security

# Herostratus - 0.1.0 - (2024-10-20)
Expand All @@ -47,7 +51,7 @@ This is Herostratus's first release! It represents the _bare minimum_, and only
different achievement types.

| ID | Description |
|--------------------------|------------------------------------------------|
| ------------------------ | ---------------------------------------------- |
| H1-fixup | Find fixup! and similar commits |
| H2-shortest-subject-line | Find the commit with the shortest subject line |

Expand All @@ -69,8 +73,7 @@ Achievement { name: "I meant to fix that up later, I swear!", commit: a987013884
Achievement { name: "I meant to fix that up later, I swear!", commit: 60b480b554dbd5266eec0f2378f72df5170a6702 }
```

> [!WARNING]
> This output format will change as Herostratus becomes more usable
> [!WARNING] This output format will change as Herostratus becomes more usable

[`test/fixup`](https://github.com/Notgnoshi/herostratus/tree/test/fixup) is a branch used for
integration testing that looks like
Expand All @@ -96,12 +99,12 @@ herostratus add [email protected]:Notgnoshi/herostratus.git test/simple
herostratus add [email protected]:Notgnoshi/herostratus.git test/fixup
```

> [!TIP]
> There are several configuration options for SSH and HTTPS authentication, as well as customizing
> where the repositories are cloned. See `herostratus --help` and `herostratus add --help` for
> details.
> [!TIP] There are several configuration options for SSH and HTTPS authentication, as well as
> customizing where the repositories are cloned. See `herostratus --help` and
> `herostratus add --help` for details.

Herostratus supports the following clone URL protocols

* SSH in both URL formats
* Example: `ssh://[email protected]/Notgnoshi/herostratus.git`
* Example: `[email protected]:Notgnoshi/herostratus.git`
Expand Down Expand Up @@ -172,6 +175,7 @@ herostratus check-all
# Herostratus - 0.1.0-rc2 - (2024-07-14)

## Changed

The Herostratus CLI interface has been changed to use subcommands:

* `herostratus check <path> [reference]` - statelessly check the repository at the given path
Expand All @@ -192,10 +196,12 @@ Not all subcommands are implemented, and the ones that are implemented need to b
* `check-all` -- needs better error / edge case handling

# Herostratus - 0.1.0-rc1 - (2024-04-07)

This is the first release of Herostratus! This release is largely centered around project
bootstrapping; Herostratus isn't quite ready to use yet.

## Added

* Cargo project bootstrapping. You can run Herostratus with

```sh
Expand Down
11 changes: 7 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ This is a silly project to gamify things that shouldn't be gamified.
* It should be easyish to add new rules
* Its target runtime environment is modern Linux x86_64
* It should provide optional integrations:
* It should provide an integration with [GitLab achievements](https://docs.gitlab.com/ee/user/profile/achievements.html)
* It could provide an integration with GitHub
* It should provide an integration with
[GitLab achievements](https://docs.gitlab.com/ee/user/profile/achievements.html)
* It could provide an integration with GitHub

## Releases

Releases are automated by the CI/CD pipeline. They are triggered by bumping the version number in
the [Cargo.toml](Cargo.toml).

The process is:

1. Submit a PR making the release
1. Bump the version number in `Cargo.toml`
2. Add a new entry to the `CHANGELOG.md`
Expand Down Expand Up @@ -47,8 +49,8 @@ Logs are great. Spammy logs are less great.
* The default log level for users is INFO. INFO should not be spammy
* Prefer logs that are useful for troubleshooting, both from a developer perspective and a user one

E.g., prefer `"failed to process repository '{repo}' because: '{e:?}'"` over `"Failed to process
repository"`
E.g., prefer `"failed to process repository '{repo}' because: '{e:?}'"` over
`"Failed to process repository"`

## Git

Expand All @@ -69,6 +71,7 @@ export GITLINT_CONFIG="$PWD/.github/gitlint/gitlint.ini"
export GITLINT_EXTRA_PATH="$PWD/.github/gitlint"
gitlint --commits main..HEAD
```

You can invoke gitlint through the CLI, your editor, or as a commit hook.

**I don't desire a perfect history. Just a good one.**
7 changes: 1 addition & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
[workspace]

resolver = "2"
members = [
# The main library and application
"herostratus",
# Integration tests and test fixtures
# Test fixtures
"herostratus-tests",
]
default-members = ["herostratus", "herostratus-tests"]

[workspace.package]
description = "**Herostratus** *n.* **1.** An ancient Greek known for seeking fame through crime and destruction. **2.** Also a Git repository achievements engine."
repository = "https://github.com/Notgnoshi/herostratus"
license = "MIT"
version = "0.1.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/Notgnoshi/herostratus"
description = "**Herostratus** *n.* **1.** An ancient Greek known for seeking fame through crime and destruction. **2.** Also a Git repository achievements engine."

[workspace.dependencies]
assert_cmd = { version = "2.0.14", features = ["color"] }
Expand All @@ -27,7 +26,7 @@ git2 = "0.19"
inventory = "0.3.15"
lazy_static = "1.4.0"
predicates = "3.1.0"
serde = { version = "1.0.204", features =["derive"] }
serde = { version = "1.0.204", features = ["derive"] }
tempfile = "3.10.1"
toml = "0.8.14"
tracing = "0.1.40"
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Herostratus

![lint workflow](https://github.com/Notgnoshi/herostratus/actions/workflows/lint.yml/badge.svg?event=push)
![release workflow](https://github.com/Notgnoshi/herostratus/actions/workflows/release.yml/badge.svg?event=push)
![code coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Notgnoshi/b20aa388c90ca92aba6aa37ec55a7f12/raw/herostratus-coverage.json)

**Herostratus** *n.* **1.** An [ancient Greek](https://en.wikipedia.org/wiki/Herostratus) known for
**Herostratus** _n._ **1.** An [ancient Greek](https://en.wikipedia.org/wiki/Herostratus) known for
seeking fame through crime and destruction. **2.** A Git repository achievements engine.

## Usage
Expand Down Expand Up @@ -31,12 +33,12 @@ $ herostratus add [email protected]:Notgnoshi/herostratus.git test/simple
$ herostratus add [email protected]:Notgnoshi/herostratus.git test/fixup
```

> [!TIP]
> You may find the `--data-dir`, `--get-data-dir`, `--config-file`, and `--get-config` options
> useful when setting up Herostratus to run on one more more repository over time.
> [!TIP] You may find the `--data-dir`, `--get-data-dir`, `--config-file`, and `--get-config`
> options useful when setting up Herostratus to run on one more more repository over time.

After this, you can use the `fetch-all` and `check-all` subcommands to update and check the cloned
repositories.

```sh
$ # Fetch from the remote tracking branch for test/simple and test/fixup
$ herostratus fetch-all
Expand All @@ -47,19 +49,21 @@ Achievement { name: "I meant to fix that up later, I swear!", commit: a987013884
Achievement { name: "I meant to fix that up later, I swear!", commit: 60b480b554dbd5266eec0f2378f72df5170a6702 }
```

> [!WARNING]
> This output format will change as Herostratus becomes more usable
> [!WARNING] This output format will change as Herostratus becomes more usable

## Development

### Build and test

The usual `cargo build` and `cargo test`. There are a few integration tests that take too long to
run every time. These can be run with `cargo test -- --ignored`.

### Test Branches

There are orphan test branches in this repository used for integration tests.

For example, the `test/simple` branch was created like this:

```sh
git checkout --orphan test/simple
git rm -rf .
Expand All @@ -69,4 +73,5 @@ done
```

### Contribution

Contribution is welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).
17 changes: 10 additions & 7 deletions docs/design/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Scope

This document answers the following questions

* What data does an achievement contain or reference?
* What inputs are required for a Rule engine?

Expand Down Expand Up @@ -60,27 +61,29 @@ rule-specific data to the cache.
## Rule variants

1. Context-free. E.g., swear in a commit message
1. Commit message
2. Commit message + diff
3. Commit message + diff + submodule
1. Commit message
2. Commit message + diff
3. Commit message + diff + submodule
2. Contextual
1. User aware. E.g., be the most prolific contributor
2. Commit history aware. E.g., revert a previous commit within 30min, or revert the same commit
multiple times
1. User aware. E.g., be the most prolific contributor
2. Commit history aware. E.g., revert a previous commit within 30min, or revert the same commit
multiple times

## Rule configuration

There might be global configuration shared between rules like

* Exclude commits from these users
* Exclude commit messages matching these hashes or regexes

But there will also be rule-specific configuration like

* When calculating the shortest subject line, exclude any subject lines longer than 10 characters

## Rule inputs

* The repository
* Any submodules of the repository
* Any submodules of the repository
* The reference being processed
* The `&Config`
* The commit itself
Expand Down
8 changes: 4 additions & 4 deletions docs/design/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

# GitLab

GitLab provides an [Achievements API](https://docs.gitlab.com/ee/user/profile/achievements.html).
It appears it internally manages a database of achievements, and provides them their own ID when
they are created. So we'll have to maintain a mapping of our achievement IDs to the GitLab
instance's IDs.
GitLab provides an [Achievements API](https://docs.gitlab.com/ee/user/profile/achievements.html). It
appears it internally manages a database of achievements, and provides them their own ID when they
are created. So we'll have to maintain a mapping of our achievement IDs to the GitLab instance's
IDs.

This implies that there needs to be a stateful database that is GitLab (or in general) integration
specific.
Expand Down
Loading
Loading