Skip to content

Commit 1312773

Browse files
committed
feat: initial commit
0 parents  commit 1312773

23 files changed

+5575
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Build then release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
branches:
8+
- "master"
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
gen_version:
15+
name: Generate version
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version: ${{ steps.generated-tag.outputs.tag }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
- name: Get latest tag
24+
id: get-latest-tag
25+
run: |
26+
echo "tag=`gh release list -L 1 | cut -f 1`" >> $GITHUB_OUTPUT
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Bump version
30+
id: generated-tag
31+
uses: actions/github-script@v6
32+
with:
33+
script: |
34+
if (context.ref.startsWith("refs/tags/")) {
35+
let tag = context.ref.replace("refs/tags/", "");
36+
core.setOutput('tag', tag);
37+
console.log(`This event pushed a tag ${tag}, return directly.`)
38+
return
39+
}
40+
console.log('Use default tag "prerelease".')
41+
core.setOutput('tag', 'prerelease');
42+
43+
build:
44+
needs: gen_version
45+
name: Build
46+
runs-on: ${{ matrix.runner }}
47+
strategy:
48+
matrix:
49+
include:
50+
- target: x86_64-apple-darwin
51+
runner: macos-latest
52+
build_env: {}
53+
- target: aarch64-apple-darwin
54+
runner: macos-latest
55+
build_env: {}
56+
- target: x86_64-unknown-linux-musl
57+
runner: ubuntu-latest
58+
build_env: {}
59+
- target: aarch64-unknown-linux-musl
60+
runner: ubuntu-latest
61+
build_env:
62+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-Clink-self-contained=yes -Clinker=rust-lld"
63+
CC_aarch64_unknown_linux_musl: clang
64+
AR_aarch64_unknown_linux_musl: llvm-ar
65+
66+
steps:
67+
- uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
70+
- name: Setup protoc
71+
uses: arduino/setup-protoc@v3.0.0
72+
with:
73+
repo-token: ${{ secrets.GITHUB_TOKEN }}
74+
- name: Install musl-tools
75+
if: matrix.runner == 'ubuntu-latest'
76+
run: sudo apt update && sudo apt install -y musl-tools
77+
- name: Install cross build deps for aarch64-unknown-linux-musl
78+
if: matrix.target == 'aarch64-unknown-linux-musl'
79+
run: sudo apt update && sudo apt install -y clang llvm gcc-aarch64-linux-gnu
80+
- name: Add target
81+
run: rustup target add ${{ matrix.target }}
82+
- name: Setup rust toolchain
83+
run: rustup show
84+
- uses: Swatinem/rust-cache@v2
85+
with:
86+
shared-key: build-then-release-${{ matrix.target }}-v1
87+
- name: Build
88+
env: ${{ matrix.build_env }}
89+
run: |
90+
cargo build --release --target ${{ matrix.target }}
91+
- name: Compress
92+
run: |
93+
zip -j pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip ./target/${{ matrix.target }}/release/pproxy
94+
- uses: actions/upload-artifact@v4
95+
name: Upload artifacts
96+
with:
97+
name: pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}
98+
path: pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip
99+
retention-days: 1
100+
101+
release:
102+
needs: [gen_version, build]
103+
runs-on: ubuntu-latest
104+
permissions:
105+
contents: write
106+
steps:
107+
- uses: actions/checkout@v3
108+
with:
109+
fetch-depth: 0
110+
- name: Generate changelog
111+
uses: orhun/git-cliff-action@v3
112+
id: git-cliff
113+
with:
114+
config: cliff.toml
115+
args: "-vv --strip header ${{ needs.gen_version.outputs.version == 'prerelease' && '--unreleased' || '--latest' }}"
116+
- uses: actions/download-artifact@v4
117+
- name: Display fetched artifacts
118+
run: ls -R
119+
- uses: softprops/action-gh-release@v2.0.6
120+
name: Emit a Github Release
121+
with:
122+
token: "${{ secrets.GITHUB_TOKEN }}"
123+
body: "${{ steps.git-cliff.outputs.content }}"
124+
tag_name: ${{ needs.gen_version.outputs.version }}
125+
prerelease: ${{ needs.gen_version.outputs.version == 'prerelease' }}
126+
title: ${{ needs.gen_version.outputs.version }}
127+
files: |
128+
LICENSE
129+
pproxy-${{ needs.gen_version.outputs.version }}-x86_64-apple-darwin/*.zip
130+
pproxy-${{ needs.gen_version.outputs.version }}-aarch64-apple-darwin/*.zip
131+
pproxy-${{ needs.gen_version.outputs.version }}-x86_64-unknown-linux-musl/*.zip
132+
pproxy-${{ needs.gen_version.outputs.version }}-aarch64-unknown-linux-musl/*.zip

.github/workflows/check_and_test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Check and test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
jobs:
15+
test:
16+
name: Check and test
17+
strategy:
18+
matrix:
19+
platform: [ubuntu-latest]
20+
runs-on: ${{ matrix.platform }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Setup protoc
26+
uses: arduino/setup-protoc@v3.0.0
27+
with:
28+
repo-token: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Setup rust toolchain
30+
run: |
31+
rustup install nightly
32+
rustup component add rustfmt --toolchain nightly
33+
rustup show
34+
- name: Install nextest
35+
uses: taiki-e/install-action@nextest
36+
- uses: Swatinem/rust-cache@v2
37+
with:
38+
shared-key: check-and-test-${{ matrix.platform }}-v1
39+
- name: Check code format
40+
run: cargo +nightly fmt -- --check
41+
- name: Check the package for errors
42+
run: cargo check --all
43+
- name: Lint rust sources
44+
run: cargo clippy --all-targets --all-features --tests --benches -- -D warnings
45+
- name: Execute rust tests
46+
run: cargo nextest run --all-features

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

.pre-commit-config.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
fail_fast: false
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.6.0
5+
hooks:
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: check-symlinks
9+
- id: check-yaml
10+
- id: end-of-file-fixer
11+
- id: fix-byte-order-marker
12+
- id: mixed-line-ending
13+
- id: trailing-whitespace
14+
- repo: local
15+
hooks:
16+
- id: buf-format
17+
name: protobuf format
18+
description: Format protobuf files with buf.
19+
entry: bash -c 'buf format --write'
20+
language: system
21+
files: \.proto$
22+
- id: buf-lint
23+
name: protobuf lint
24+
description: Lint protobuf files for errors.
25+
entry: bash -c 'buf lint'
26+
language: system
27+
files: \.proto$
28+
- id: taplo
29+
name: taplo format
30+
description: Format Cargo.toml files with taplo.
31+
entry: bash -c 'taplo format --check'
32+
language: rust
33+
files: Cargo.toml$
34+
- id: cargo-fmt
35+
name: cargo fmt
36+
description: Format files with rustfmt.
37+
entry: bash -c 'cargo +nightly fmt -- --check'
38+
language: rust
39+
files: \.rs$
40+
- id: cargo-deny
41+
name: cargo deny check
42+
description: Check cargo dependencies
43+
entry: bash -c 'cargo deny check -d'
44+
language: rust
45+
files: \.rs$
46+
- id: typos
47+
name: typos
48+
description: check typo
49+
entry: bash -c 'typos'
50+
language: rust
51+
files: \.*$
52+
pass_filenames: false
53+
- id: cargo-check
54+
name: cargo check
55+
description: Check the package for errors.
56+
entry: bash -c 'cargo check --all'
57+
language: rust
58+
files: \.rs$
59+
pass_filenames: false
60+
- id: cargo-clippy
61+
name: cargo clippy
62+
description: Lint rust sources
63+
entry: bash -c 'cargo clippy --all-targets --all-features --tests --benches -- -D warnings'
64+
language: rust
65+
files: \.rs$
66+
pass_filenames: false

0 commit comments

Comments
 (0)