Skip to content

Commit bd817c8

Browse files
authored
Sets up automated releases (#3)
1 parent 21884ba commit bd817c8

File tree

3 files changed

+2055
-4
lines changed

3 files changed

+2055
-4
lines changed

.github/workflows/release.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Inspired from https://github.com/SpectralOps/rust-ci-release-template/blob/master/.github/workflows/release.yml
2+
name: Release
3+
4+
on:
5+
push:
6+
tags:
7+
- "v[0-9]+.[0-9]+.[0-9]+"
8+
9+
env:
10+
BIN_NAME: freezer
11+
PROJECT_NAME: freezer
12+
13+
jobs:
14+
dist:
15+
name: Dist
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
build: [x86_64-linux, aarch64-linux, x86_64-windows, x86_64-macos]
21+
include:
22+
- build: x86_64-linux
23+
os: ubuntu-24.04
24+
rust: stable
25+
target: x86_64-unknown-linux-gnu
26+
cross: false
27+
- build: aarch64-linux
28+
os: ubuntu-24.04
29+
rust: stable
30+
target: aarch64-unknown-linux-gnu
31+
cross: true
32+
- build: x86_64-windows
33+
os: windows-2019
34+
rust: stable
35+
target: x86_64-pc-windows-msvc
36+
cross: false
37+
- build: x86_64-macos
38+
os: macos-latest
39+
rust: stable
40+
target: x86_64-apple-darwin
41+
cross: false
42+
43+
steps:
44+
- name: Checkout sources
45+
uses: actions/checkout@v2
46+
47+
- name: Install ${{ matrix.rust }} toolchain
48+
uses: actions-rs/toolchain@v1
49+
with:
50+
profile: minimal
51+
toolchain: ${{ matrix.rust }}
52+
target: ${{ matrix.target }}
53+
override: true
54+
55+
- name: Build release binary
56+
uses: actions-rs/cargo@v1
57+
with:
58+
use-cross: ${{ matrix.cross }}
59+
command: build
60+
args: --release --target ${{ matrix.target }} --locked
61+
62+
- name: Build archive
63+
shell: bash
64+
run: |
65+
mkdir -p dist
66+
if [ "${{ matrix.os }}" == "windows-2019" ]; then
67+
cp target/${{ matrix.target }}/release/$BIN_NAME.exe dist/
68+
else
69+
cp target/${{ matrix.target }}/release/$BIN_NAME dist/
70+
fi
71+
72+
- uses: actions/upload-artifact@v4.4.3
73+
with:
74+
name: bins-${{ matrix.build }}
75+
path: dist
76+
77+
publish:
78+
name: Publish
79+
runs-on: ubuntu-latest
80+
needs: dist
81+
steps:
82+
- name: Checkout sources
83+
uses: actions/checkout@v2
84+
85+
- name: Download artifacts
86+
uses: actions/download-artifact@v4.1.8
87+
88+
- run: ls -al bins-*
89+
90+
- name: Calculate tag name
91+
run: |
92+
name=dev
93+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
94+
name=${GITHUB_REF:10}
95+
fi
96+
echo ::set-output name=val::$name
97+
echo TAG=$name >> $GITHUB_ENV
98+
id: tagname
99+
100+
- name: Build archive
101+
shell: bash
102+
run: |
103+
set -ex
104+
105+
rm -rf tmp
106+
mkdir tmp
107+
mkdir dist
108+
109+
for dir in bins-* ; do
110+
platform=${dir#"bins-"}
111+
unset exe
112+
if [[ $platform =~ "windows" ]]; then
113+
exe=".exe"
114+
fi
115+
pkgname=$PROJECT_NAME-$TAG-$platform
116+
mkdir tmp/$pkgname
117+
mv bins-$platform/$BIN_NAME$exe tmp/$pkgname
118+
chmod +x tmp/$pkgname/$BIN_NAME$exe
119+
120+
if [ "$exe" = "" ]; then
121+
tar cJf dist/$pkgname.tar.xz -C tmp $pkgname
122+
else
123+
(cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname)
124+
fi
125+
done
126+
127+
- name: Release
128+
env:
129+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
run: |
131+
set -ex
132+
gh release create ${{ steps.tagname.outputs.val }} dist/* --title ${{ steps.tagname.outputs.val }} --notes "Release ${{ steps.tagname.outputs.val }}"

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
debug/
88
target/
99

10-
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
11-
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
12-
Cargo.lock
13-
1410
# These are backup files generated by rustfmt
1511
**/*.rs.bk
1612

0 commit comments

Comments
 (0)