Skip to content

Commit 31313da

Browse files
nashtsaicaiq1nyu
authored andcommitted
feat: setup a rust project repo
feat: refactor Dockerfile contents
1 parent e279533 commit 31313da

25 files changed

+5540
-78
lines changed

.cargo/config.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# NOTES: `cargo search` will not work as crates source has been overwritten, need to specify `--registry` flag,
2+
# i.e., `cargo search <CRATE> --registry crates-io`
3+
[source.crates-io]
4+
replace-with = 'ustc'
5+
6+
[source.ustc]
7+
# requires cargo 1.68+ to enable sparse index
8+
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"
9+
#registry = "https://mirrors.ustc.edu.cn/crates.io-index"
10+
11+
12+
[target.x86_64-unknown-linux-musl]
13+
linker = "rust-lld"
14+
# rustflags = ["-C", "target-feature=+crt-static"]
15+
16+
[target.aarch64-unknown-linux-musl]
17+
linker = "rust-lld"
18+
# rustflags = ["-C", "target-feature=+crt-static"]
19+
20+
[target.x86_64-unknown-linux-gnu]
21+
# linker = "rust-lld"
22+
# rustflags = ["-C", "target-feature=+crt-static"]
23+
24+
[target.aarch64-unknown-linux-gnu]
25+
# linker = "rust-lld"
26+
# rustflags = ["-C", "target-feature=+crt-static"]
27+
28+
[target.x86_64-pc-windows-msvc]
29+
rustflags = ["-C", "target-feature=+crt-static"]

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
.git/
4+
target/
5+
# Cargo.lock

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
## Bug description
11+
12+
<!-- A clear and concise description of what the bug is. -->
13+
14+
- Would you like to work on a fix? [y/n]
15+
16+
## To Reproduce
17+
18+
Steps to reproduce the behavior:
19+
20+
1. ...
21+
2. ...
22+
3. ...
23+
4. ...
24+
25+
<!-- Make sure you are able to reproduce the bug in the main branch, too. -->
26+
27+
## Expected behavior
28+
29+
<!-- A clear and concise description of what you expected to happen. -->
30+
31+
## Screenshots
32+
33+
<!-- If applicable, add screenshots to help explain your problem. -->
34+
35+
## Environment
36+
37+
<!-- Please fill the following information. -->
38+
39+
- OS: [e.g. Ubuntu 20.04]
40+
- apt-dts version: [e.g. 0.1.0]
41+
42+
## Additional context
43+
44+
<!-- Add any other context about the problem here. -->

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
## Motivations
11+
12+
<!--
13+
If your feature request is related to a problem, please describe it.
14+
-->
15+
16+
- Would you like to implement this feature? [y/n]
17+
18+
## Solution
19+
20+
<!-- Describe the solution you'd like. -->
21+
22+
## Alternatives
23+
24+
<!-- Describe any alternative solutions or features you've considered. -->
25+
26+
## Additional context
27+
28+
<!-- Add any other context or screenshots about the feature request here. -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- Please explain the changes you made -->
2+
3+
<!--
4+
Please, make sure:
5+
- you have read the contributing guidelines:
6+
https://github.com/apecloud/ape-dts/blob/main/docs/CONTRIBUTING.md
7+
- you have formatted the code using rustfmt:
8+
https://github.com/rust-lang/rustfmt
9+
- you have checked that all tests pass, by running `cargo test --workspace`
10+
- you have updated the changelog (if needed):
11+
https://github.com/apecloud/ape-dts/blob/main/CHANGELOG.md
12+
-->

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
# Look for `Cargo.toml` and `Cargo.lock` in the root directory
5+
directory: "/"
6+
# Check for updates every Monday
7+
schedule:
8+
interval: "weekly"
9+
open-pull-requests-limit: 10
10+
- package-ecosystem: "github-actions"
11+
directory: "/"
12+
# Check for updates every Monday
13+
schedule:
14+
interval: "weekly"
15+
open-pull-requests-limit: 10

.github/workflows/audit.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Security audit
2+
3+
on:
4+
schedule:
5+
# Runs at 00:00 UTC everyday
6+
- cron: '0 0 * * *'
7+
push:
8+
paths:
9+
- '**/Cargo.toml'
10+
- '**/Cargo.lock'
11+
pull_request:
12+
13+
jobs:
14+
audit:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
# Ensure that the latest version of Cargo is installed
20+
- name: Install Rust toolchain
21+
uses: dtolnay/rust-toolchain@stable
22+
- uses: Swatinem/rust-cache@v2
23+
- uses: actions-rs/audit-check@v1
24+
with:
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+

.github/workflows/cd.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: CD # Continuous Deployment
2+
3+
on:
4+
push:
5+
tags:
6+
- '[v]?[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
{% if crate_type == "bin" %}
10+
publish:
11+
name: Publishing for {{ "${{ matrix.job.os " }}}}
12+
runs-on: {{ "${{ matrix.job.os " }}}}
13+
strategy:
14+
matrix:
15+
rust: [stable]
16+
job:
17+
- os: macos-latest
18+
os-name: macos
19+
target: x86_64-apple-darwin
20+
architecture: x86_64
21+
binary-postfix: ""
22+
use-cross: false
23+
- os: macos-latest
24+
os-name: macos
25+
target: aarch64-apple-darwin
26+
architecture: arm64
27+
binary-postfix: ""
28+
use-cross: false
29+
- os: ubuntu-latest
30+
os-name: linux
31+
target: x86_64-unknown-linux-gnu
32+
architecture: x86_64
33+
binary-postfix: ""
34+
use-cross: false
35+
- os: windows-latest
36+
os-name: windows
37+
target: x86_64-pc-windows-msvc
38+
architecture: x86_64
39+
binary-postfix: ".exe"
40+
use-cross: false
41+
- os: ubuntu-latest
42+
os-name: linux
43+
target: aarch64-unknown-linux-gnu
44+
architecture: arm64
45+
binary-postfix: ""
46+
use-cross: true
47+
- os: ubuntu-latest
48+
os-name: linux
49+
target: i686-unknown-linux-gnu
50+
architecture: i686
51+
binary-postfix: ""
52+
use-cross: true
53+
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v3
57+
- name: Install Rust toolchain
58+
uses: actions-rs/toolchain@v1
59+
with:
60+
toolchain: {{ "${{ matrix.rust " }}}}
61+
target: {{ "${{ matrix.job.target " }}}}
62+
profile: minimal
63+
override: true
64+
- uses: Swatinem/rust-cache@v2
65+
- name: Cargo build
66+
uses: actions-rs/cargo@v1
67+
with:
68+
command: build
69+
use-cross: {{ "${{ matrix.job.use-cross " }}}}
70+
toolchain: {{ "${{ matrix.rust " }}}}
71+
args: --release --target {{ "${{ matrix.job.target " }}}}
72+
73+
- name: install strip command
74+
shell: bash
75+
run: |
76+
if [[ {{ "${{ matrix.job.target " }}}} == aarch64-unknown-linux-gnu ]]; then
77+
sudo apt update
78+
sudo apt-get install -y binutils-aarch64-linux-gnu
79+
fi
80+
- name: Packaging final binary
81+
shell: bash
82+
run: |
83+
cd target/{{ "${{ matrix.job.target " }}}}/release
84+
85+
####### reduce binary size by removing debug symbols #######
86+
BINARY_NAME={{project-name}}{{ "${{ matrix.job.binary-postfix " }}}}
87+
if [[ {{ "${{ matrix.job.target " }}}} == aarch64-unknown-linux-gnu ]]; then
88+
GCC_PREFIX="aarch64-linux-gnu-"
89+
else
90+
GCC_PREFIX=""
91+
fi
92+
"$GCC_PREFIX"strip $BINARY_NAME
93+
94+
########## create tar.gz ##########
95+
RELEASE_NAME={{project-name}}-${GITHUB_REF/refs\/tags\//}-{{ "${{ matrix.job.os-name " }}}}-{{ "${{ matrix.job.architecture " }}}}
96+
tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
97+
98+
########## create sha256 ##########
99+
if [[ {{ "${{ runner.os " }}}} == 'Windows' ]]; then
100+
certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
101+
else
102+
shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256
103+
fi
104+
- name: Releasing assets
105+
uses: softprops/action-gh-release@v1
106+
with:
107+
files: |
108+
target/{{ "${{ matrix.job.target " }}}}/release/{{project-name}}-*.tar.gz
109+
target/{{ "${{ matrix.job.target " }}}}/release/{{project-name}}-*.sha256
110+
env:
111+
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN " }}}}
112+
{% endif %}
113+
publish-cargo:
114+
name: Publishing to Cargo
115+
runs-on: ubuntu-latest
116+
steps:
117+
- name: Checkout repository
118+
uses: actions/checkout@v3
119+
- name: Install Rust toolchain
120+
uses: dtolnay/rust-toolchain@stable
121+
- uses: Swatinem/rust-cache@v2
122+
- run: cargo publish
123+
env:
124+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI # Continuous Integration
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
11+
test:
12+
name: Test Suite
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
- name: Install Rust toolchain
18+
uses: dtolnay/rust-toolchain@stable
19+
- uses: Swatinem/rust-cache@v2
20+
- name: Run tests
21+
run: cargo test --all-features --workspace
22+
23+
rustfmt:
24+
name: Rustfmt
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
- name: Install Rust toolchain
30+
uses: dtolnay/rust-toolchain@stable
31+
with:
32+
components: rustfmt
33+
- uses: Swatinem/rust-cache@v2
34+
- name: Check formatting
35+
run: cargo fmt --all --check
36+
37+
clippy:
38+
name: Clippy
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v3
43+
- name: Install Rust toolchain
44+
uses: dtolnay/rust-toolchain@stable
45+
with:
46+
components: clippy
47+
- uses: Swatinem/rust-cache@v2
48+
- name: Clippy check
49+
run: cargo clippy --all-targets --all-features --workspace -- -D warnings
50+
51+
docs:
52+
name: Docs
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v3
57+
- name: Install Rust toolchain
58+
uses: dtolnay/rust-toolchain@stable
59+
- uses: Swatinem/rust-cache@v2
60+
- name: Check documentation
61+
env:
62+
RUSTDOCFLAGS: -D warnings
63+
run: cargo doc --no-deps --document-private-items --all-features --workspace --examples
64+

0 commit comments

Comments
 (0)