Skip to content

Commit 2712633

Browse files
Merge #119
119: ci: add action to build and release binaries r=burrbull a=duskmoon314 Add action similar to [the one used in svd2rust](rust-embedded/svd2rust#608). In brief, the action does these work: 1. triggered when a new tag or commit is pushed 2. build and compress binaries 3. create a release and attach binaries Currently, only 4 target platforms are supported: amd64 (Linux, Windows, macOS) and arm64 (macOS) Co-authored-by: Campbell He <[email protected]>
2 parents 980607c + 0670a25 commit 2712633

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- v*.*.*
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
include:
15+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, suffix: .tar.gz }
16+
- { target: x86_64-apple-darwin, os: macos-latest, suffix: .tar.gz }
17+
- { target: aarch64-apple-darwin, os: macos-latest, suffix: .tar.gz }
18+
- { target: x86_64-pc-windows-msvc, os: windows-latest, suffix: .zip }
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: stable
25+
profile: minimal
26+
target: ${{ matrix.target }}
27+
override: true
28+
- name: Cache Dependencies
29+
uses: Swatinem/rust-cache@v1
30+
with:
31+
key: ${{ matrix.target }}
32+
- uses: actions-rs/cargo@v1
33+
with:
34+
command: build
35+
args: --target ${{ matrix.target }} --release
36+
37+
- name: (Not Windows) Move executables and compress
38+
if: ${{ matrix.os != 'windows-latest' }}
39+
run: |
40+
mkdir ${{ matrix.target }}
41+
for bin in src/bin/*.rs; do
42+
mv target/${{ matrix.target }}/release/$(basename $bin .rs) ${{ matrix.target }};
43+
done
44+
tar -zcvf ${{ matrix.target }}.tar.gz ${{ matrix.target }}
45+
46+
- name: (Windows) Move executables and compress
47+
if: ${{ matrix.os == 'windows-latest' }}
48+
run: |
49+
mkdir ${{ matrix.target }}
50+
$bins = Get-ChildItem -Path src/bin -Recurse -Filter "*.rs"
51+
foreach ($b in $bins) {
52+
Move-Item -Path ("target/${{ matrix.target }}/release/" + $b.BaseName + ".exe") -Destination "${{ matrix.target }}/"
53+
}
54+
Compress-Archive -Path ${{ matrix.target }} -DestinationPath ${{ matrix.target }}.zip
55+
56+
- uses: actions/upload-artifact@v3
57+
with:
58+
name: ${{ matrix.target }}
59+
path: ${{ matrix.target }}${{ matrix.suffix }}
60+
61+
release:
62+
name: release
63+
runs-on: ubuntu-latest
64+
needs: [build]
65+
steps:
66+
- uses: actions/checkout@v3
67+
- uses: actions/download-artifact@v3
68+
with:
69+
path: artifacts
70+
- run: ls -R ./artifacts
71+
72+
- name: Set current date as environment variable
73+
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
74+
75+
- id: changelog-reader
76+
uses: mindsers/[email protected]
77+
with:
78+
version: ${{ (github.ref_type == 'tag' && github.ref_name) || 'Unreleased' }}
79+
80+
- uses: softprops/action-gh-release@v1
81+
with:
82+
tag_name: ${{ steps.changelog-reader.outputs.version }}
83+
name: ${{ (github.ref_type == 'tag' && steps.changelog-reader.outputs.version) || format('Prereleased {0}', env.CURRENT_DATE) }}
84+
body: ${{ steps.changelog-reader.outputs.changes }}
85+
prerelease: ${{ steps.changelog-reader.outputs.status == 'unreleased' }}
86+
files: |
87+
artifacts/**/*

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Action to build binaries and release for every version tag and latest commit
13+
1014
## [v0.3.5] - 2022-02-12
1115

1216
### Added

0 commit comments

Comments
 (0)