-
-
Notifications
You must be signed in to change notification settings - Fork 4
155 lines (153 loc) · 5.94 KB
/
build_and_release.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
name: Build, test and release
on: push
jobs:
build:
name: Build and test
strategy:
fail-fast: false
matrix:
job:
- { target: x86_64-unknown-linux-gnu, binary_name: linux-amd64, os: ubuntu-latest }
- { target: x86_64-apple-darwin, binary_name: darwin-amd64, os: macos-latest }
- { target: x86_64-pc-windows-msvc, binary_name: windows-amd64.exe, os: windows-latest }
runs-on: ${{ matrix.job.os }}
steps:
- uses: actions/checkout@v4
- name: Install libudev-dev
run: sudo apt-get update && sudo apt-get install libudev-dev
if: matrix.job.os == 'ubuntu-latest'
- name: Cache Rust dependencies
uses: actions/[email protected]
with:
path: target
key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.OS }}-build-
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustc, cargo
toolchain: nightly
override: true
target: ${{ matrix.job.target }}
- name: Run cargo build --release
uses: actions-rs/cargo@v1
with:
args: --release --target=${{ matrix.job.target }}
command: build
- name: Sanitise Git ref for use in filenames
id: sanitise_ref
run: echo "::set-output name=value::$(echo "${{ github.ref_name }}" | tr '/' '_')"
- name: Rename Windows binary to use structured filename
run: |
cp target/${{ matrix.job.target }}/release/litra.exe litra_${{ steps.sanitise_ref.outputs.value }}_${{ matrix.job.binary_name }}
if: runner.os == 'Windows'
- name: Rename Unix binary to use structured filename
run: |
rm target/${{ matrix.job.target }}/release/litra.d
cp target/${{ matrix.job.target }}/release/litra* litra_${{ steps.sanitise_ref.outputs.value }}_${{ matrix.job.binary_name }}
if: runner.os != 'Windows'
- name: Upload binary as artifact
uses: actions/upload-artifact@v4
with:
path: litra_${{ steps.sanitise_ref.outputs.value }}_${{ matrix.job.binary_name }}
name: litra_${{ steps.sanitise_ref.outputs.value }}_${{ matrix.job.binary_name }}
cargo_publish_dry_run:
name: Publish with Cargo in dry-run mode
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Install libudev-dev
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: Cache Rust dependencies
uses: actions/[email protected]
with:
path: target
key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.OS }}-build-
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustc, cargo
toolchain: nightly
override: true
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Set the version to a dummy version to allow publishing
run: cargo set-version 9.9.9
- name: Publish to Crates.io
run: cargo publish --dry-run --allow-dirty
create_github_release:
name: Create release with binary assets
runs-on: ubuntu-latest
needs: build
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- name: Sanitise Git ref for use in filenames
id: sanitise_ref
run: echo "::set-output name=value::$(echo "${{ github.ref_name }}" | tr '/' '_')"
- uses: actions/download-artifact@v4
with:
name: litra_${{ steps.sanitise_ref.outputs.value }}_linux-amd64
- uses: actions/download-artifact@v4
with:
name: litra_${{ steps.sanitise_ref.outputs.value }}_darwin-amd64
- uses: actions/download-artifact@v4
with:
name: litra_${{ steps.sanitise_ref.outputs.value }}_windows-amd64.exe
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: |
litra_${{ steps.sanitise_ref.outputs.value }}_windows-amd64.exe
litra_${{ steps.sanitise_ref.outputs.value }}_darwin-amd64
litra_${{ steps.sanitise_ref.outputs.value }}_linux-amd64
publish_on_homebrew:
name: Publish release on Homebrew
runs-on: ubuntu-latest
needs: create_github_release
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- name: Get released version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- uses: mislav/bump-homebrew-formula-action@v3
with:
formula-name: litra
download-url: https://github.com/timrogers/litra-rs/releases/download/${{ steps.get_version.outputs.VERSION }}/litra_${{ steps.get_version.outputs.VERSION }}_darwin-amd64
homebrew-tap: timrogers/homebrew-tap
push-to: timrogers/homebrew-tap
create-pullrequest: true
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
cargo_publish:
name: Publish with Cargo to Crates.io
runs-on: ubuntu-latest
needs:
- create_github_release
- cargo_publish_dry_run
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Install libudev-dev
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: Cache Rust dependencies
uses: actions/[email protected]
with:
path: target
key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.OS }}-build-
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustc, cargo
toolchain: nightly
override: true
- name: Publish to Crates.io
run: cargo publish --token ${{ secrets.CRATES_IO_API_TOKEN }}