-
Notifications
You must be signed in to change notification settings - Fork 2
146 lines (139 loc) · 4.78 KB
/
ci.yaml
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
name: CI/CD Workflow
on:
push:
branches:
- main
pull_request:
branches:
- "*"
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: "${{ matrix.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
- name: Run pre-build scripts
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
- name: Run tests
run: cargo test
build:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: test
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: "${{ matrix.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
- name: Run pre-build scripts
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
- name: Build Release
run: cargo build --release
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-binary"
path: target/release/smrec
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-binary"
- name: Get version from Cargo.toml
id: get_version
run: echo "::set-output name=version::$(grep '^version =' Cargo.toml | awk -F\" '{print $2}')"
- name: Prepare asset
run: |
mkdir -p ./release
mv ./${{ matrix.os }}-${{ matrix.arch }}-binary ./release/smrec
cd release
zip -r ../smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip .
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: smrec v${{ steps.get_version.outputs.version }} - ${{ matrix.os }} ${{ matrix.arch }}
body: "Automatic changelog generation will be applied in the future. This is an auto generated release note."
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_name: smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_content_type: application/zip
- name: Error Handling
if: failure()
run: echo "An error has occurred during the release process"
publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Publish to Crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: "--token ${{ secrets.CRATES_IO_TOKEN }}"