|
1 | | -name: Release Binary |
| 1 | +name: Create Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: |
6 | | - - main |
7 | | - |
8 | | -permissions: |
9 | | - contents: write |
| 5 | + tags: |
| 6 | + - "*" # Trigger for all tag pushes |
10 | 7 |
|
11 | 8 | jobs: |
12 | 9 | release: |
13 | 10 | runs-on: ubuntu-latest |
14 | 11 | steps: |
15 | | - - name: Checkout Repository |
| 12 | + - name: Checkout Code |
16 | 13 | uses: actions/checkout@v3 |
17 | 14 |
|
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}" |
23 | 22 |
|
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 |
26 | 33 |
|
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" |
38 | 36 |
|
39 | | - - name: Upload Binary Asset |
40 | | - uses: actions/upload-release-asset@v1 |
| 37 | + - name: Create Release |
| 38 | + uses: actions/create-release@v1 |
41 | 39 | env: |
42 | 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
43 | 41 | 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