Skip to content

Commit bd047c6

Browse files
authored
Update rust.yml
1 parent 907506b commit bd047c6

1 file changed

Lines changed: 28 additions & 31 deletions

File tree

.github/workflows/rust.yml

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
name: Release Binary
1+
name: Create Release
22

33
on:
44
push:
5-
branches:
6-
- main
7-
8-
permissions:
9-
contents: write
5+
tags:
6+
- "*" # Trigger for all tag pushes
107

118
jobs:
129
release:
1310
runs-on: ubuntu-latest
1411
steps:
15-
- name: Checkout Repository
12+
- name: Checkout Code
1613
uses: actions/checkout@v3
1714

18-
- name: Setup Rust Toolchain
19-
uses: actions-rs/toolchain@v1
20-
with:
21-
toolchain: stable
22-
override: true
15+
- id: validate_tag
16+
name: Validate and Fix Tag Name
17+
shell: bash
18+
run: |
19+
# Extract the tag name from the ref (removing 'refs/tags/')
20+
TAG="${GITHUB_REF##*/}"
21+
echo "Original tag: ${TAG}"
2322
24-
- name: Build the Binary
25-
run: cargo build --release
23+
# Check if the tag is exactly 40 hex characters (a commit SHA)
24+
if [[ "${TAG}" =~ ^[0-9a-f]{40}$ ]]; then
25+
# If true, adjust the tag name.
26+
# Here we prefix with 'v' and use the first 7 characters (as is common for abbreviated SHAs).
27+
NEW_TAG="v${TAG:0:7}"
28+
echo "Tag appears to be a commit SHA. Adjusting tag to: ${NEW_TAG}"
29+
TAG="${NEW_TAG}"
30+
else
31+
echo "Tag is valid: ${TAG}"
32+
fi
2633
27-
- name: Create GitHub Release
28-
id: create_release
29-
uses: actions/create-release@v1
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
with:
33-
tag_name: ${{ github.sha }}
34-
release_name: Release ${{ github.sha }}
35-
body: "Automated release for commit ${{ github.sha }}"
36-
draft: false
37-
prerelease: false
34+
# Set the adjusted tag as an output for later steps
35+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
3836
39-
- name: Upload Binary Asset
40-
uses: actions/upload-release-asset@v1
37+
- name: Create Release
38+
uses: actions/create-release@v1
4139
env:
4240
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4341
with:
44-
upload_url: ${{ steps.create_release.outputs.upload_url }}
45-
asset_path: ./target/release/my_binary
46-
asset_name: my_binary-${{ github.sha }}
47-
asset_content_type: application/octet-stream
42+
tag_name: ${{ steps.validate_tag.outputs.tag }}
43+
release_name: "Release ${{ steps.validate_tag.outputs.tag }}"
44+
body: "Changelog for release ${{ steps.validate_tag.outputs.tag }}"

0 commit comments

Comments
 (0)