-
Notifications
You must be signed in to change notification settings - Fork 6
184 lines (167 loc) · 5.86 KB
/
build.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: build
on:
workflow_dispatch: # 手动触发
push:
branches: ["master"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["master"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- target: x86_64-apple-darwin
host: macos-latest
build: |
cargo build --release --target x86_64-apple-darwin && \
mkdir build && \
cp target/x86_64-apple-darwin/release/wol build/wol && \
strip -x build/wol
- target: aarch64-apple-darwin
host: macos-latest
build: |
cargo build --release --target aarch64-apple-darwin && \
mkdir build && \
cp target/aarch64-apple-darwin/release/wol build/wol && \
strip -x build/wol
- target: x86_64-pc-windows-msvc
host: windows-latest
build: |
cargo build --release --target x86_64-pc-windows-msvc
md build
copy target/x86_64-pc-windows-msvc/release/wol.exe build/wol.exe
- target: aarch64-pc-windows-msvc
host: windows-latest
build: |
cargo build --release --target aarch64-pc-windows-msvc
md build
copy target/aarch64-pc-windows-msvc/release/wol.exe build/wol.exe
- target: x86_64-unknown-linux-gnu
host: ubuntu-latest
build: |
cargo install cross --force --git https://github.com/cross-rs/cross && \
cross build --release --target x86_64-unknown-linux-gnu && \
mkdir build && \
cp target/x86_64-unknown-linux-gnu/release/wol build/wol && \
strip -x build/wol
- target: x86_64-unknown-linux-musl
host: ubuntu-latest
build: |
cargo install cross --force --git https://github.com/cross-rs/cross && \
cross build --release --target x86_64-unknown-linux-musl && \
mkdir build && \
cp target/x86_64-unknown-linux-musl/release/wol build/wol && \
strip -x build/wol
- target: aarch64-unknown-linux-gnu
host: ubuntu-latest
build: |
cargo install cross --force --git https://github.com/cross-rs/cross && \
cross build --release --target aarch64-unknown-linux-gnu && \
mkdir build && \
cp target/aarch64-unknown-linux-gnu/release/wol build/wol
- target: aarch64-unknown-linux-musl
host: ubuntu-latest
build: |
cargo install cross --force --git https://github.com/cross-rs/cross && \
cross build --release --target aarch64-unknown-linux-musl && \
mkdir build && \
cp target/aarch64-unknown-linux-musl/release/wol build/wol
name: build ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ matrix.settings.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.settings.target }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: latest
cache: "yarn"
cache-dependency-path: web/yarn.lock
- name: Build web
run: yarn && yarn build
working-directory: web
- name: Move web files to www
run: mv web/dist/* www
- name: Build server
run: ${{ matrix.settings.build }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: wol-${{ matrix.settings.target }}
path: build/
if-no-files-found: error
publish:
runs-on: ubuntu-latest
needs:
- build
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifact
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure of downloaded files
run: ls -R
working-directory: artifacts
- name: Pack as zip file
run: ls | xargs -I filename zip -r -m filename.zip filename
working-directory: artifacts
- name: Display structure of zip files
run: ls -R
working-directory: artifacts
- name: Release
uses: softprops/action-gh-release@v2
with:
files: artifacts/*.zip
docker:
runs-on: ubuntu-latest
needs:
- publish
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup docker buildx
uses: docker/setup-buildx-action@v3
# https://github.com/docker/login-action
- name: Login to ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/nashaofu/wol:latest