-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (95 loc) · 3.47 KB
/
rust.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
name: Rust Build and Release
on:
push:
branches:
- main
jobs:
build:
name: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [windows]
include:
- build: windows
os: windows-2019
rust: 1.76.0
target: x86_64-pc-windows-gnu
archive-name: windows.7z
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Build binary
run: cargo build --verbose --release --target ${{ matrix.target }}
env:
RUST_BACKTRACE: 1
- name: Extract info from Cargo.toml
id: extract_info
shell: bash
run: |
echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r .packages[0].version)" >> $GITHUB_ENV
echo "PACKAGE_NAME=$(cargo metadata --format-version=1 --no-deps | jq -r .packages[0].name)" >> $GITHUB_ENV
- name: Strip binary (linux and macos)
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "target/${{ matrix.target }}/release/${{ env.PACKAGE_NAME }}"
- name: Build archive
shell: bash
run: |
mkdir archive
cp LICENSE README.md archive/
cd archive
if [ "${{ matrix.build }}" = "windows" ]; then
cp "../target/${{ matrix.target }}/release/${{ env.PACKAGE_NAME }}.exe" ./
7z a "${{ matrix.archive-name }}" LICENSE README.md ${{ env.PACKAGE_NAME }}.exe
else
cp "../target/${{ matrix.target }}/release/${{ env.PACKAGE_NAME }}" ./
tar -czf "${{ matrix.archive-name }}" LICENSE README.md ${{ env.PACKAGE_NAME }}
fi
- name: Upload archive as workflow artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.archive-name }}
path: archive/${{ matrix.archive-name }}
release:
name: Release
runs-on: ubuntu-20.04
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Extract info from Cargo.toml
id: extract_info
run: |
echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r .packages[0].version)" >> $GITHUB_ENV
echo "PACKAGE_NAME=$(cargo metadata --format-version=1 --no-deps | jq -r .packages[0].name)" >> $GITHUB_ENV
- name: Download all build artifacts
uses: actions/download-artifact@v3
with:
path: downloaded_artifacts
- name: List downloaded artifacts
run: ls -R downloaded_artifacts
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: "v${{ env.VERSION }}"
name: "${{ env.PACKAGE_NAME }}-${{ env.VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload ${{ env.PACKAGE_NAME }}-windows.7z to Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: downloaded_artifacts/windows.7z/windows.7z
asset_name: ${{ env.PACKAGE_NAME }}-windows.7z
asset_content_type: application/x-7z-compressed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}