Skip to content

Commit 2a20bfb

Browse files
committed
improve GitHub actions
1 parent 321736f commit 2a20bfb

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: Build
33
on:
44
release:
55
types: [created]
6+
workflow_dispatch:
7+
inputs:
8+
os:
9+
required: true
10+
type: choice
11+
options: ['ubuntu', 'macos', 'windows']
612

713
env:
814
CARGO_TERM_COLOR: always
@@ -11,32 +17,40 @@ jobs:
1117
build:
1218
name: Build binary on ${{ matrix.os }}
1319

14-
runs-on: ${{ matrix.os }}
20+
runs-on: ${{ matrix.os }}-latest
1521
strategy:
1622
fail-fast: false
1723
matrix:
18-
include:
19-
- os: ubuntu-latest
20-
file: target/release/simple_backup
21-
- os: windows-latest
22-
file: target/release/simple_backup.exe
23-
- os: macOS-latest
24-
file: target/release/simple_backup
25-
24+
os: ${{ fromJSON(format('[{0}]', inputs.os || 'ubuntu, macos, windows')) }}
2625

2726
steps:
2827
- name: Checkout
2928
uses: actions/checkout@v4
30-
- name: Build
31-
run: cargo build --verbose
32-
- name: Run tests
33-
run: cargo test --verbose
3429
- name: Build release
3530
run: cargo build --release
31+
32+
- name: Set ENV Windows
33+
if: runner.os == 'Windows'
34+
run: echo "{executable}={target/release/simple_backup.exe}" >> $GITHUB_ENV
35+
- name: Set ENV Linux
36+
if: runner.os == 'Linux'
37+
run: echo "{executable}={target/release/simple_backup}" >> $GITHUB_ENV
38+
- name: Set ENV Mac
39+
if: runner.os == 'Mac'
40+
run: |
41+
mv target/release/simple_backup target/release/simple_backup_mac
42+
echo "{executable}={target/release/simple_backup_mac}" >> $GITHUB_ENV
43+
3644
- name: Run
37-
run: ${{ matrix.file }} --help
38-
- name: Release
45+
run: ${{ env.executable }} --help
46+
- name: Upload Release
3947
uses: softprops/[email protected]
40-
if: startsWith(github.ref, 'refs/tags/')
48+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
49+
with:
50+
files: ${{ env.executable }}
51+
- name: Upload Artifact
52+
uses: actions/upload-artifact@v4
53+
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
4154
with:
42-
files: ${{ matrix.file }}
55+
path: ${{ env.executable }}
56+
retention-days: 2

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
test:
15+
name: Test on ${{ matrix.os }}
16+
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, windows-latest, macOS-latest]
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
- name: Build
26+
run: cargo build --verbose
27+
- name: Run tests
28+
run: cargo test --verbose

0 commit comments

Comments
 (0)