Skip to content

Commit f394257

Browse files
committed
Add default rust workflows from SpectralOps/rust-ci-release-template and run cargo fmt.
1 parent 82e03b3 commit f394257

File tree

3 files changed

+217
-37
lines changed

3 files changed

+217
-37
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,6 @@ jobs:
2929
with:
3030
command: check
3131

32-
test:
33-
name: Test Suite
34-
strategy:
35-
matrix:
36-
os: [ubuntu-latest, macos-latest, windows-latest]
37-
rust: [stable]
38-
runs-on: ${{ matrix.os }}
39-
steps:
40-
- name: Checkout sources
41-
uses: actions/checkout@v2
42-
43-
- name: Install stable toolchain
44-
uses: actions-rs/toolchain@v1
45-
with:
46-
profile: minimal
47-
toolchain: ${{ matrix.rust }}
48-
override: true
49-
50-
- uses: Swatinem/rust-cache@v1
51-
52-
- name: Run cargo test
53-
uses: actions-rs/cargo@v1
54-
with:
55-
command: test
56-
57-
5832
lints:
5933
name: Lints
6034
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: Release
2+
on:
3+
# schedule:
4+
# - cron: '0 0 * * *' # midnight UTC
5+
6+
push:
7+
tags:
8+
- 'v[0-9]+.[0-9]+.[0-9]+'
9+
## - release
10+
11+
env:
12+
BIN_NAME: rust-unityextractor
13+
PROJECT_NAME: rust-unityextractor
14+
REPO_NAME: ticpu/rust-unityextractor
15+
16+
jobs:
17+
dist:
18+
name: Dist
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
fail-fast: false # don't fail other jobs if one fails
22+
matrix:
23+
build: [x86_64-linux, x86_64-windows]
24+
include:
25+
- build: x86_64-linux
26+
os: ubuntu-20.04
27+
rust: stable
28+
target: x86_64-unknown-linux-gnu
29+
cross: false
30+
- build: x86_64-windows
31+
os: windows-2019
32+
rust: stable
33+
target: x86_64-pc-windows-msvc
34+
cross: false
35+
36+
steps:
37+
- name: Checkout sources
38+
uses: actions/checkout@v2
39+
with:
40+
submodules: true
41+
42+
- name: Install ${{ matrix.rust }} toolchain
43+
uses: actions-rs/toolchain@v1
44+
with:
45+
profile: minimal
46+
toolchain: ${{ matrix.rust }}
47+
target: ${{ matrix.target }}
48+
override: true
49+
50+
- name: Run cargo test
51+
uses: actions-rs/cargo@v1
52+
with:
53+
use-cross: ${{ matrix.cross }}
54+
command: test
55+
args: --release --locked --target ${{ matrix.target }}
56+
57+
- name: Build release binary
58+
uses: actions-rs/cargo@v1
59+
with:
60+
use-cross: ${{ matrix.cross }}
61+
command: build
62+
args: --release --locked --target ${{ matrix.target }}
63+
64+
- name: Strip release binary (linux and macos)
65+
if: matrix.build == 'x86_64-linux' || matrix.build == 'x86_64-macos'
66+
run: strip "target/${{ matrix.target }}/release/$BIN_NAME"
67+
68+
- name: Strip release binary (arm)
69+
if: matrix.build == 'aarch64-linux'
70+
run: |
71+
docker run --rm -v \
72+
"$PWD/target:/target:Z" \
73+
rustembedded/cross:${{ matrix.target }} \
74+
aarch64-linux-gnu-strip \
75+
/target/${{ matrix.target }}/release/$BIN_NAME
76+
77+
- name: Build archive
78+
shell: bash
79+
run: |
80+
mkdir dist
81+
if [ "${{ matrix.os }}" = "windows-2019" ]; then
82+
cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/"
83+
else
84+
cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/"
85+
fi
86+
87+
- uses: actions/[email protected]
88+
with:
89+
name: bins-${{ matrix.build }}
90+
path: dist
91+
92+
publish:
93+
name: Publish
94+
needs: [dist]
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Checkout sources
98+
uses: actions/checkout@v2
99+
with:
100+
submodules: false
101+
102+
- uses: actions/download-artifact@v2
103+
# with:
104+
# path: dist
105+
# - run: ls -al ./dist
106+
- run: ls -al bins-*
107+
108+
- name: Calculate tag name
109+
run: |
110+
name=dev
111+
if [[ $GITHUB_REF == refs/tags/v* ]]; then
112+
name=${GITHUB_REF:10}
113+
fi
114+
echo ::set-output name=val::$name
115+
echo TAG=$name >> $GITHUB_ENV
116+
id: tagname
117+
118+
- name: Build archive
119+
shell: bash
120+
run: |
121+
set -ex
122+
123+
rm -rf tmp
124+
mkdir tmp
125+
mkdir dist
126+
127+
for dir in bins-* ; do
128+
platform=${dir#"bins-"}
129+
unset exe
130+
if [[ $platform =~ "windows" ]]; then
131+
exe=".exe"
132+
fi
133+
pkgname=$PROJECT_NAME-$TAG-$platform
134+
mkdir tmp/$pkgname
135+
# cp LICENSE README.md tmp/$pkgname
136+
mv bins-$platform/$BIN_NAME$exe tmp/$pkgname
137+
chmod +x tmp/$pkgname/$BIN_NAME$exe
138+
139+
if [ "$exe" = "" ]; then
140+
tar cJf dist/$pkgname.tar.xz -C tmp $pkgname
141+
else
142+
(cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname)
143+
fi
144+
done
145+
146+
- name: Upload binaries to release
147+
uses: svenstaro/upload-release-action@v2
148+
with:
149+
repo_token: ${{ secrets.GITHUB_TOKEN }}
150+
file: dist/*
151+
file_glob: true
152+
tag: ${{ steps.tagname.outputs.val }}
153+
overwrite: true
154+
155+
- name: Extract version
156+
id: extract-version
157+
run: |
158+
printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}"
159+
160+
- uses: mislav/bump-homebrew-formula-action@v1
161+
with:
162+
formula-path: ${{env.PROJECT_NAME}}.rb
163+
homebrew-tap: ${{ env.BREW_TAP }}
164+
download-url: "https://github.com/${{ env.REPO_NAME }}/releases/download/${{ steps.extract-version.outputs.tag-name }}/${{env.PROJECT_NAME}}-${{ steps.extract-version.outputs.tag-name }}-x86_64-macos.tar.xz"
165+
commit-message: updating formula for ${{ env.PROJECT_NAME }}
166+
env:
167+
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
168+
#
169+
# you can use this initial file in your homebrew-tap if you don't have an initial formula:
170+
# <projectname>.rb
171+
#
172+
# class <Projectname capitalized> < Formula
173+
# desc "A test formula"
174+
# homepage "http://www.example.com"
175+
# url "-----"
176+
# version "-----"
177+
# sha256 "-----"
178+
179+
# def install
180+
# bin.install "<bin-name>"
181+
# end
182+
# end
183+
184+
185+
# Uncomment this section if you want to release your package to crates.io
186+
# Before publishing, make sure you have filled out the following fields:
187+
# license or license-file, description, homepage, documentation, repository, readme.
188+
# Read more: https://doc.rust-lang.org/cargo/reference/publishing.html
189+
190+
# - name: Install ${{ matrix.rust }} toolchain
191+
# uses: actions-rs/toolchain@v1
192+
# with:
193+
# profile: minimal
194+
# toolchain: ${{ matrix.rust }}
195+
# target: ${{ matrix.target }}
196+
# - run: cargo publish --token ${CRATES_TOKEN}
197+
# env:
198+
# CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}

src/main.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use argparse::{ArgumentParser, StoreTrue, Store};
1+
use argparse::{ArgumentParser, Store, StoreTrue};
22
use flate2::read::GzDecoder;
3+
use log::{info, LevelFilter};
4+
use simple_logger::SimpleLogger;
5+
use std::collections::HashMap;
36
use std::fs::File;
4-
use std::io::{Read};
7+
use std::io::Read;
58
use std::path::PathBuf;
69
use tar::Archive;
710
use tokio::fs;
8-
use log::{info, LevelFilter};
9-
use simple_logger::SimpleLogger;
10-
use std::collections::HashMap;
1111

1212
#[tokio::main]
1313
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -16,19 +16,27 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1616
let mut input_path = String::new();
1717
{
1818
let mut parser = ArgumentParser::new();
19-
parser.set_description("Unitypackage extractor");
20-
parser.refer(&mut verbose)
19+
parser.set_description("Unity package extractor");
20+
parser
21+
.refer(&mut verbose)
2122
.add_option(&["-v"], StoreTrue, "Verbose mode");
22-
parser.refer(&mut input_path)
23-
.add_argument("input", Store, "Unitypackage (.tar.gz) file")
23+
parser
24+
.refer(&mut input_path)
25+
.add_argument("input", Store, "*.unitypackage file")
2426
.required();
2527
parser.parse_args_or_exit();
2628
}
2729

2830
if verbose {
29-
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
31+
SimpleLogger::new()
32+
.with_level(LevelFilter::Info)
33+
.init()
34+
.unwrap();
3035
} else {
31-
SimpleLogger::new().with_level(LevelFilter::Error).init().unwrap();
36+
SimpleLogger::new()
37+
.with_level(LevelFilter::Error)
38+
.init()
39+
.unwrap();
3240
}
3341

3442
// Open the unitypackage file

0 commit comments

Comments
 (0)