-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (117 loc) · 4.2 KB
/
release.yml
File metadata and controls
138 lines (117 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Build, Test, and Release
on:
pull_request:
push:
branches:
- main
tags:
- 'v*.*.*'
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
# commitlint
- name: Lint commit messages
uses: wagoid/commitlint-github-action@v6
with:
configFile: .commitlintrc.json
env:
COMMIT_RANGE: ${{ github.event.before }}..${{ github.event.after }}
# rustfmt
- name: Check Rust code formatting
run: cargo fmt --all --check
# clippy
- name: Lint Rust code
run: cargo clippy --all-targets --all-features --locked -- -D warnings
release:
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- { target: aarch64-unknown-linux-gnu , os: ubuntu-22.04-arm }
- { target: aarch64-unknown-linux-musl , os: ubuntu-22.04-arm }
- { target: aarch64-apple-darwin , os: macos-14 }
- { target: x86_64-pc-windows-gnu , os: windows-2022 }
- { target: x86_64-pc-windows-msvc , os: windows-2022 }
- { target: aarch64-pc-windows-msvc , os: windows-11-arm }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-22.04 }
- { target: x86_64-unknown-linux-musl , os: ubuntu-22.04 }
env:
BUILD_CMD: cargo
steps:
- name: Checkout source code
uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
toolchain: "${{ contains(matrix.job.target, 'windows-') && '1.88.0' || 'stable' }}"
- name: Show toolchain info
shell: bash
run: |
gcc --version || true
rustc -V
cargo -V
rustup show
- name: Build binary
shell: bash
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
- name: Strip binary (if non-Windows)
if: ${{ !contains(matrix.job.target, 'windows') }}
shell: bash
run: |
strip target/${{ matrix.job.target }}/release/genlint || echo "strip failed"
- name: Run tests
shell: bash
run: $BUILD_CMD test --locked --release --target=${{ matrix.job.target }}
- name: Package artifacts
shell: bash
run: |
BIN_NAME=genlint
VERSION=${GITHUB_REF##*/}
FOLDER_NAME="${BIN_NAME}-${VERSION}-${{ matrix.job.target }}"
mkdir -p dist "$FOLDER_NAME"
if [[ "${{ matrix.job.target }}" == *"windows"* ]]; then
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}.exe" "$FOLDER_NAME/"
else
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "$FOLDER_NAME/"
fi
cp -r completions/* "$FOLDER_NAME/" || echo "no completions"
cp -r man/* "$FOLDER_NAME/" || echo "no manpages"
if [[ "${{ matrix.job.target }}" == *"windows"* ]]; then
7z a "dist/${FOLDER_NAME}.zip" "./${FOLDER_NAME}/*"
else
tar -czf "dist/${FOLDER_NAME}.tar.gz" "$FOLDER_NAME"
fi
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.job.target }}
path: |
dist/*
- name: Check for release
id: is-release
shell: bash
run: |
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
- name: Get token
uses: actions/create-github-app-token@v3
if: steps.is-release.outputs.IS_RELEASE
id: get_token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Upload release assets
uses: softprops/action-gh-release@v2
if: ${{ steps.get_token.outcome == 'success' }}
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ steps.get_token.outputs.token }}