Skip to content

Commit f870781

Browse files
authored
add CI (#2)
* add CI * correct directory * add MSRV
1 parent bbb91cd commit f870781

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

.github/workflows/main.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '**'
9+
pull_request: {}
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: dtolnay/rust-toolchain@stable
18+
with:
19+
components: rustfmt, clippy
20+
21+
- id: cache-rust
22+
uses: Swatinem/rust-cache@v2
23+
24+
- uses: pre-commit/action@v3.0.0
25+
with:
26+
extra_args: --all-files --verbose
27+
env:
28+
PRE_COMMIT_COLOR: always
29+
SKIP: test
30+
31+
resolve:
32+
runs-on: ubuntu-latest
33+
outputs:
34+
MSRV: ${{ steps.resolve-msrv.outputs.MSRV }}
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: set up python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: '3.12'
42+
43+
- name: resolve MSRV
44+
id: resolve-msrv
45+
run:
46+
echo MSRV=`python -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["rust-version"])'` >> $GITHUB_OUTPUT
47+
48+
test:
49+
needs: [resolve]
50+
name: test rust-${{ matrix.rust-version }}
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
rust-version: [stable, nightly]
55+
include:
56+
- rust-version: ${{ needs.resolve.outputs.MSRV }}
57+
58+
runs-on: ubuntu-latest
59+
60+
env:
61+
RUST_VERSION: ${{ matrix.rust-version }}
62+
63+
steps:
64+
- uses: actions/checkout@v3
65+
66+
- uses: dtolnay/rust-toolchain@master
67+
with:
68+
toolchain: ${{ matrix.rust-version }}
69+
70+
- id: cache-rust
71+
uses: Swatinem/rust-cache@v2
72+
73+
- uses: taiki-e/install-action@cargo-llvm-cov
74+
75+
- run: cargo llvm-cov --all-features --codecov --output-path codecov.json
76+
77+
- uses: codecov/codecov-action@v3
78+
with:
79+
token: ${{ secrets.CODECOV_TOKEN }}
80+
files: codecov.json
81+
env_vars: RUST_VERSION
82+
83+
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
84+
check:
85+
if: always()
86+
needs: [test, lint]
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Decide whether the needed jobs succeeded or failed
90+
uses: re-actors/alls-green@release/v1
91+
with:
92+
jobs: ${{ toJSON(needs) }}
93+
94+
release:
95+
needs: [check]
96+
if: "success() && startsWith(github.ref, 'refs/tags/')"
97+
runs-on: ubuntu-latest
98+
environment: release
99+
100+
steps:
101+
- uses: actions/checkout@v2
102+
103+
- name: install rust stable
104+
uses: dtolnay/rust-toolchain@stable
105+
106+
- uses: Swatinem/rust-cache@v2
107+
108+
- run: cargo publish
109+
env:
110+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.pre-commit-config.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
fail_fast: true
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.0.1
6+
hooks:
7+
- id: check-yaml
8+
- id: check-toml
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace
11+
- id: check-added-large-files
12+
13+
- repo: local
14+
hooks:
15+
- id: format
16+
name: Format
17+
entry: cargo fmt
18+
types: [rust]
19+
language: system
20+
pass_filenames: false
21+
- id: clippy
22+
name: Clippy
23+
entry: cargo clippy -- -D warnings
24+
types: [rust]
25+
language: system
26+
pass_filenames: false
27+
- id: test
28+
name: Test
29+
entry: cargo test
30+
types: [rust]
31+
language: system
32+
pass_filenames: false

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "logfire"
33
version = "0.1.0"
44
edition = "2024"
55
license = "MIT"
6+
rust-version = "1.85"
67

78
[dependencies]
89
log = "0.4"

0 commit comments

Comments
 (0)