Skip to content

Commit 74b873d

Browse files
committed
Add CI and release workflows using GitHub Actions.
For every push, the CI workflow will build and test the project. For every v* tag, the release workflow will create a draft release, and build the binary in release mode. Jobs are launched in Linux, macOS, and Windows.
1 parent f4a4d8a commit 74b873d

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
8+
jobs:
9+
ci:
10+
name: rust ${{ matrix.rust }} on ${{ matrix.os }}
11+
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
rust:
16+
- stable
17+
- beta
18+
- 1.46.0
19+
os:
20+
- ubuntu-latest
21+
- windows-latest
22+
- macos-latest
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- name: Use rust ${{ matrix.rust }}
28+
uses: actions-rs/toolchain@v1
29+
with:
30+
profile: minimal
31+
toolchain: ${{ matrix.rust }}
32+
override: true
33+
components: rustfmt, clippy
34+
35+
- name: cargo build
36+
uses: actions-rs/cargo@v1
37+
with:
38+
command: build
39+
40+
- name: cargo test
41+
uses: actions-rs/cargo@v1
42+
with:
43+
command: test
44+
45+
- name: Check fmt
46+
uses: actions-rs/cargo@v1
47+
with:
48+
command: fmt
49+
args: --all -- --check
50+
51+
- name: Clippy
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: clippy
55+
args: -- -D warnings

.github/workflows/release.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Release Assets
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
release_draft:
10+
name: Create Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- id: create_release
14+
uses: actions/create-release@v1
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
with:
18+
tag_name: ${{ github.ref }}
19+
release_name: Draft ${{ github.ref }}
20+
draft: true
21+
outputs:
22+
upload_url: ${{ steps.create_release.outputs.upload_url }}
23+
24+
build:
25+
name: Binary for ${{ matrix.os }}
26+
needs: release_draft
27+
runs-on: ${{ matrix.os }}
28+
strategy:
29+
matrix:
30+
os: [ ubuntu-latest, macos-latest, windows-latest ]
31+
include:
32+
- os: ubuntu-latest
33+
package: hdcquery-linux-ARCH.tar.gz
34+
- os: macos-latest
35+
package: hdcquery-macos-ARCH.tar.gz
36+
- os: windows-latest
37+
package: hdcquery-windows-ARCH.zip
38+
steps:
39+
- uses: actions/checkout@v2
40+
41+
- name: Use rust ${{ matrix.rust }}
42+
uses: actions-rs/toolchain@v1
43+
with:
44+
profile: minimal
45+
toolchain: stable
46+
47+
- name: Build binary
48+
uses: actions-rs/cargo@v1
49+
with:
50+
command: build
51+
args: --release
52+
53+
- name: Test binary
54+
uses: actions-rs/cargo@v1
55+
with:
56+
command: run
57+
args: --release -- show rustlang/rust
58+
59+
- name: Package for Windows
60+
if: matrix.os == 'windows-latest'
61+
run: |
62+
choco install zip
63+
cd target/release
64+
zip ../../${{ matrix.package }} hdcquery.exe
65+
66+
- name: Package for Linux/UNIX
67+
if: matrix.os != 'windows-latest'
68+
run: |
69+
set -xe
70+
strip target/release/hdcquery
71+
tar -czf ${{ matrix.package }} -C target/release hdcquery
72+
73+
- id: asset_name_generator
74+
name: Set asset name
75+
shell: bash
76+
run: |
77+
echo "::set-output name=name::${{ matrix.package }}" | sed "s/ARCH/$(uname -m)/g"
78+
79+
- uses: actions/upload-release-asset@v1
80+
with:
81+
upload_url: ${{ needs.release_draft.outputs.upload_url }}
82+
asset_path: ${{ matrix.package }}
83+
asset_name: ${{ steps.asset_name_generator.outputs.name }}
84+
asset_content_type: application/octet-stream
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)