88jobs :
99 release :
1010 runs-on : ubuntu-latest
11- # Grant the workflow write permission to repository contents.
1211 permissions :
1312 contents : write
1413
1514 steps :
1615 # 1. Checkout the repository code
1716 - name : Checkout Code
18- uses : actions/checkout@v3
17+ uses : actions/checkout@v4
1918
20- # 2. Cache dependencies (example for Node.js projects)
21- - name : Cache Node Modules
19+ # 2. Cache Cargo Registry
20+ - name : Cache Cargo Registry
2221 uses : actions/cache@v3
2322 with :
24- path : node_modules
25- key : ${{ runner.os }}-node- ${{ hashFiles('**/package-lock.json ') }}
23+ path : ~/.cargo/registry
24+ key : ${{ runner.os }}-cargo-registry- ${{ hashFiles('**/Cargo.lock ') }}
2625 restore-keys : |
27- ${{ runner.os }}-node -
26+ ${{ runner.os }}-cargo-registry -
2827
29- # 3. Optionally install dependencies if needed (for example, to build assets)
30- - name : Install Dependencies
31- if : exists('package-lock.json')
32- run : npm ci
28+ # 3. Cache Cargo Git Repositories
29+ - name : Cache Cargo Git Repositories
30+ uses : actions/cache@v3
31+ with :
32+ path : ~/.cargo/git
33+ key : ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
34+ restore-keys : |
35+ ${{ runner.os }}-cargo-git-
36+
37+ # 4. Cache Build Artifacts (the target directory)
38+ - name : Cache Build Output
39+ uses : actions/cache@v3
40+ with :
41+ path : target
42+ key : ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
43+ restore-keys : |
44+ ${{ runner.os }}-cargo-target-
45+
46+ # 5. Build your project with Cargo in release mode
47+ - name : Build with Cargo
48+ run : cargo build --release
3349
34- # 4. Validate and fix the tag name if it matches a 40-character commit SHA
50+ # 6. Locate the compiled binary
51+ - name : Locate Binary File
52+ id : locate_binary
53+ run : |
54+ # Adjust the binary name as needed. Here we assume the built binary is named "DynaRust"
55+ binary_path=$(find target/release -maxdepth 1 -type f -executable -name 'DynaRust*')
56+ if [ -z "$binary_path" ]; then
57+ echo "Binary file not found!"
58+ exit 1
59+ else
60+ echo "Binary file found: ${binary_path}"
61+ echo "BINARY_PATH=${binary_path}" >> $GITHUB_ENV
62+ fi
63+
64+ # 7. Validate and fix the tag name if it matches a 40-character commit SHA
3565 - id : validate_tag
3666 name : Validate and Fix Tag Name
3767 shell : bash
4070 TAG="${GITHUB_REF##*/}"
4171 echo "Original tag: ${TAG}"
4272
43- # If tag is exactly 40 hex characters (i.e. a commit SHA)
73+ # If the tag is exactly 40 hex characters (i.e. a commit SHA),
74+ # adjust the tag by prefixing it with 'v' and shortening it to 7 characters.
4475 if [[ "${TAG}" =~ ^[0-9a-f]{40}$ ]]; then
45- # Adjust the tag name: prefix with 'v' and shorten (commonly to 7 chars)
4676 NEW_TAG="v${TAG:0:7}"
4777 echo "Tag appears to be a commit SHA. Adjusting tag to: ${NEW_TAG}"
4878 TAG="${NEW_TAG}"
@@ -52,14 +82,25 @@ jobs:
5282 # Set the (possibly adjusted) tag as output for later steps
5383 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
5484
55- # 5. Create the GitHub release using the validated/adjusted tag
56- - name : Create Release
85+ # 8. Create the GitHub Release using the validated tag
86+ - name : Create GitHub Release
87+ id : create_release
5788 uses : actions/create-release@v1
5889 env :
59- # Using the default GITHUB_TOKEN. If you encounter permission issues in a fork,
60- # consider using a PAT with the necessary scopes.
6190 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6291 with :
6392 tag_name : ${{ steps.validate_tag.outputs.tag }}
64- release_name : " Automated release for commit ${{ steps.validate_tag.outputs.tag }}"
65- body : " Automated release for commit ${{ steps.validate_tag.outputs.tag }}"
93+ release_name : " Release ${{ steps.validate_tag.outputs.tag }}"
94+ draft : false
95+ prerelease : false
96+
97+ # 9. Upload the built binary as a release asset
98+ - name : Upload Release Asset
99+ uses : actions/upload-release-asset@v1
100+ env :
101+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
102+ with :
103+ upload_url : ${{ steps.create_release.outputs.upload_url }}
104+ asset_path : ${{ env.BINARY_PATH }}
105+ asset_name : DynaRust
106+ asset_content_type : application/octet-stream
0 commit comments