Skip to content

Commit 30c868a

Browse files
committed
Add ci and auto release
1 parent 217d928 commit 30c868a

File tree

8 files changed

+500
-234
lines changed

8 files changed

+500
-234
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
steps:
105+
- uses: actions/checkout@v3
106+
with:
107+
fetch-depth: 0
108+
- name: Generate changelog
109+
uses: orhun/git-cliff-action@v3
110+
id: git-cliff
111+
with:
112+
config: cliff.toml
113+
args: "-vv --strip header ${{ needs.gen_version.outputs.version == 'prerelease' && '--unreleased' || '--latest' }}"
114+
- uses: actions/download-artifact@v4
115+
- name: Display fetched artifacts
116+
run: ls -R
117+
- uses: softprops/action-gh-release@v2.0.4
118+
name: Emit a Github Release
119+
with:
120+
token: "${{ secrets.GITHUB_TOKEN }}"
121+
body: "${{ steps.git-cliff.outputs.content }}"
122+
tag_name: ${{ needs.gen_version.outputs.version }}
123+
prerelease: ${{ needs.gen_version.outputs.version == 'prerelease' }}
124+
title: ${{ needs.gen_version.outputs.version }}
125+
files: |
126+
LICENSE
127+
pproxy-${{ needs.gen_version.outputs.version }}-x86_64-apple-darwin/*.zip
128+
pproxy-${{ needs.gen_version.outputs.version }}-aarch64-apple-darwin/*.zip
129+
pproxy-${{ needs.gen_version.outputs.version }}-x86_64-unknown-linux-musl/*.zip
130+
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

0 commit comments

Comments
 (0)