-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (91 loc) · 3.3 KB
/
rust.yml
File metadata and controls
101 lines (91 loc) · 3.3 KB
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
name: Create Release on Every Commit
on:
push:
# This will trigger on every commit push on any branch.
branches:
- 'main'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# 1. Checkout the repository code.
- name: Checkout Code
uses: actions/checkout@v4
# 2. Cache Cargo Registry.
- name: Cache Cargo Registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
# 3. Cache Cargo Git Repositories.
- name: Cache Cargo Git Repositories
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
# 4. Cache Build Artifacts (the target directory).
- name: Cache Build Output
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-
# 5. Build your project with Cargo in release mode.
- name: Build with Cargo
run: cargo build --release
# 6. Locate the compiled binary.
- name: Locate Binary File
id: locate_binary
run: |
# Adjust the binary name as needed. Here we assume the built binary is named "DynaRust"
binary_path=$(find target/release -maxdepth 1 -type f -executable -name 'DynaRust*')
if [ -z "$binary_path" ]; then
echo "Binary file not found!"
exit 1
else
echo "Binary file found: ${binary_path}"
echo "BINARY_PATH=${binary_path}" >> $GITHUB_ENV
fi
# 7. Determine the tag name.
# If the push already is a tag push, respect that tag.
# Otherwise, use the first 7 characters of the commit SHA prefixed with 'v'.
- id: determine_tag
name: Determine Tag Name
shell: bash
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG="${GITHUB_REF##*/}"
echo "Running on tag push. Using tag: ${TAG}"
else
TAG="v${GITHUB_SHA:0:7}"
echo "Not a tag push. Using commit SHA as tag: ${TAG}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
# 8. Create a GitHub Release using the determined tag.
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.determine_tag.outputs.tag }}
release_name: "Release ${{ steps.determine_tag.outputs.tag }}"
draft: false
prerelease: false
# 9. Upload the built binary as a release asset.
- 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: ${{ env.BINARY_PATH }}
asset_name: DynaRust
asset_content_type: application/octet-stream