Skip to content

Commit 24c0498

Browse files
committed
Add ci/cd config
1 parent e2cac86 commit 24c0498

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

.github/workflows/Build.yml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Build on push and pull request.
2+
# create a draft release with built binaries and changelog, when a tag like "v0.1.0" is pushed.
3+
4+
name: Build
5+
6+
on: [push, pull_request, workflow_dispatch]
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
create-draft-release:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
release_upload_url: ${{ steps.create-draft-release.outputs.upload_url }}
16+
17+
steps:
18+
- name: Create draft release
19+
id: create-draft-release
20+
uses: ncipollo/release-action@v1
21+
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
22+
with:
23+
draft: true
24+
generateReleaseNotes: true
25+
26+
build-and-upload-artifact:
27+
needs: create-draft-release
28+
runs-on: ${{ matrix.os }}
29+
30+
strategy:
31+
matrix:
32+
include:
33+
- os: ubuntu-latest
34+
target: x86_64-unknown-linux-gnu
35+
artifact-name: ubuntu-x86_64-gnu
36+
prebuild-config: |
37+
sudo apt-get update
38+
sudo apt-get install -y libasound2-dev
39+
40+
- os: windows-latest
41+
target: x86_64-pc-windows-msvc
42+
artifact-name: windows-x86_64-msvc
43+
44+
- os: macos-latest
45+
target: x86_64-apple-darwin
46+
artifact-name: macos-x86_64
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
51+
- name: Set exe extension for Windows
52+
run: echo "EXE=.exe" >> $env:GITHUB_ENV
53+
if: startsWith(matrix.os, 'windows')
54+
55+
- name: Install `rust` toolchain
56+
uses: actions-rs/toolchain@v1
57+
with:
58+
toolchain: stable
59+
override: true
60+
profile: minimal
61+
target: ${{ matrix.target }}
62+
63+
- name: Prebuild config
64+
run: ${{ matrix.prebuild-config }}
65+
66+
- name: Build
67+
run: cargo build --release --target=${{ matrix.target }}
68+
69+
- name: Run tests
70+
run: cargo test --release
71+
72+
- name: Upload artifact
73+
uses: actions/upload-artifact@v3
74+
with:
75+
name: ${{ matrix.artifact-name }}
76+
path: target/${{ matrix.target }}/release/mfp${{ env.EXE }}
77+
78+
- name: Get version from tag
79+
id: extract-version
80+
run: |
81+
echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
82+
shell: bash
83+
84+
- name: Upload artifact to release
85+
uses: shogo82148/actions-upload-release-asset@v1
86+
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
87+
with:
88+
upload_url: ${{ needs.create-draft-release.outputs.release_upload_url }}
89+
asset_name: mfp-${{ steps.extract-version.outputs.version }}-${{ matrix.artifact-name }}${{ env.EXE }}
90+
asset_path: target/${{ matrix.target }}/release/mfp${{ env.EXE }}

.github/workflows/Publish.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# When:
2+
# - A release is published, or ...
3+
# - A draft release is changed to a release, or ...
4+
# - A pre-release is changed to a release
5+
#
6+
# Do:
7+
# - Publish to crates.io
8+
9+
name: Publish
10+
11+
on:
12+
release:
13+
types: [released]
14+
15+
env:
16+
CARGO_TERM_COLOR: always
17+
18+
jobs:
19+
publish-on-windows:
20+
runs-on: windows-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Install `rust` toolchain
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
toolchain: stable
29+
override: true
30+
profile: minimal
31+
target: x86_64-pc-windows-msvc
32+
33+
- name: Publish to crates.io
34+
run: cargo publish --token ${{ secrets.CARGO_TOKEN }}

0 commit comments

Comments
 (0)