Skip to content

Commit 65ec32e

Browse files
committed
Add ci and auto release
1 parent 217d928 commit 65ec32e

File tree

8 files changed

+479
-234
lines changed

8 files changed

+479
-234
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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, runner: macos-latest }
51+
- { target: aarch64-apple-darwin, runner: macos-latest }
52+
- { target: x86_64-unknown-linux-musl, runner: ubuntu-latest }
53+
- { target: aarch64-unknown-linux-musl, runner: ubuntu-latest }
54+
steps:
55+
- uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
- name: Setup protoc
59+
uses: arduino/setup-protoc@v3.0.0
60+
with:
61+
repo-token: ${{ secrets.GITHUB_TOKEN }}
62+
- name: Install musl-tools
63+
if: matrix.runner == 'ubuntu-latest'
64+
run: sudo apt update && sudo apt install -y musl-tools
65+
- name: Add target
66+
run: rustup target add ${{ matrix.target }}
67+
- name: Setup rust toolchain
68+
run: rustup show
69+
- uses: Swatinem/rust-cache@v2
70+
with:
71+
shared-key: build-then-release-${{ matrix.target }}-v1
72+
- name: Build
73+
run: |
74+
cargo build --release --target ${{ matrix.target }}
75+
zip -j pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip ./target/${{ matrix.target }}/release/pproxy
76+
- uses: actions/upload-artifact@v4
77+
name: Upload artifacts
78+
with:
79+
name: pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}
80+
path: pproxy-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip
81+
retention-days: 1
82+
83+
release:
84+
needs: [gen_version, build]
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v3
88+
with:
89+
fetch-depth: 0
90+
- name: Generate changelog
91+
uses: orhun/git-cliff-action@v3
92+
id: git-cliff
93+
with:
94+
config: cliff.toml
95+
args: "-vv --strip header ${{ needs.gen_version.outputs.version == 'prerelease' && '--unreleased' || '--latest' }}"
96+
- uses: actions/download-artifact@v3
97+
- name: Display fetched artifacts
98+
run: ls -R
99+
- uses: softprops/action-gh-release@v2.0.4
100+
name: Emit a Github Release
101+
with:
102+
token: "${{ secrets.GITHUB_TOKEN }}"
103+
body: "${{ steps.git-cliff.outputs.content }}"
104+
tag_name: ${{ needs.gen_version.outputs.version }}
105+
prerelease: ${{ needs.gen_version.outputs.version == 'prerelease' }}
106+
title: ${{ needs.gen_version.outputs.version }}
107+
files: |
108+
LICENSE
109+
pproxy-${{ needs.gen_version.outputs.version }}-x86_64-apple-darwin/*.zip
110+
pproxy-${{ needs.gen_version.outputs.version }}-aarch64-apple-darwin/*.zip
111+
pproxy-${{ needs.gen_version.outputs.version }}-x86_64-unknown-linux-musl/*.zip
112+
pproxy-${{ needs.gen_version.outputs.version }}-aarch64-unknown-linux-musl/*.zip

.github/workflows/check_and_test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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: rustup show
31+
- name: Install nextest
32+
uses: taiki-e/install-action@nextest
33+
- uses: Swatinem/rust-cache@v2
34+
with:
35+
shared-key: check-and-test-${{ matrix.platform }}-v1
36+
- name: Check code format
37+
run: cargo +nightly fmt -- --check
38+
- name: Check the package for errors
39+
run: cargo check --all
40+
- name: Lint rust sources
41+
run: cargo clippy --all-targets --all-features --tests --benches -- -D warnings
42+
- name: Execute rust tests
43+
run: cargo nextest run --all-features

0 commit comments

Comments
 (0)