55 tags :
66 - ' v*.*.*' # Trigger on version tags like v1.0.0
77 workflow_dispatch : # Allows manual triggering
8+ inputs :
9+ version :
10+ description : ' The version tag to use for the release (e.g., v1.0.0)'
11+ required : true
12+ type : string
813
914permissions :
10- contents : write # Needed to create releases and upload assets
15+ contents : write # Needed for softprops/action-gh-release to create releases and upload assets
1116
1217env :
1318 CARGO_TERM_COLOR : always
1419 CRATE_NAME : rustdocs_mcp_server
1520
1621jobs :
17- create_release :
18- name : Create Release
19- runs-on : ubuntu-latest
20- outputs :
21- upload_url : ${{ steps.create_release.outputs.upload_url }}
22- steps :
23- - name : Create Release
24- id : create_release
25- uses : actions/create-release@v1
26- env :
27- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
28- with :
29- tag_name : ${{ github.ref_name }}
30- release_name : Release ${{ github.ref_name }}
31- body : |
32- Automated release for ${{ github.ref_name }}
33- draft : false
34- prerelease : false
35-
36- build_release :
37- name : Build Release Assets
38- needs : create_release
22+ build_assets :
23+ name : Build Asset (${{ matrix.target }})
3924 strategy :
4025 matrix :
4126 include :
4227 - target : x86_64-unknown-linux-gnu
43- os : ubuntu-latest
28+ os : ubuntu-latest # Use Linux runner for cross-compilation via Docker
4429 asset_name_suffix : linux-x86_64
30+ binary_name_suffix : " "
4531 - target : x86_64-apple-darwin
4632 os : macos-latest
4733 asset_name_suffix : macos-x86_64
34+ binary_name_suffix : " "
4835 - target : aarch64-apple-darwin
4936 os : macos-latest # Can build aarch64 on x86_64 macOS runners
5037 asset_name_suffix : macos-aarch64
38+ binary_name_suffix : " "
5139 - target : x86_64-pc-windows-msvc
5240 os : windows-latest
53- asset_name_suffix : windows-x86_64.exe # Add .exe for Windows
41+ asset_name_suffix : windows-x86_64.exe
42+ binary_name_suffix : " .exe" # Add .exe for Windows binary name
5443
5544 runs-on : ${{ matrix.os }}
5645 steps :
5746 - name : Checkout code
5847 uses : actions/checkout@v4
5948
60- - name : Set up Rust toolchain
61- uses : dtolnay/rust-toolchain@stable
62- with :
63- targets : ${{ matrix.target }} # Ensure the target is installed for the host
64-
65- - name : Install cross-rs
66- if : runner.os != 'Windows' # cross doesn't work on Windows runners directly for MSVC target
67- run : cargo install cross --git https://github.com/cross-rs/cross --rev 1131999 # Use specific rev for stability
49+ # No need to explicitly set up Rust toolchain, actions-rust-cross handles it
50+ # No need to manually install cross
6851
69- - name : Build binary (cross)
70- if : runner.os != 'Windows'
71- run : cross build --release --target ${{ matrix.target }} --verbose
72- env :
73- # Set linker for Linux MUSL if needed, otherwise default GNU is fine
74- # For macOS, default linker works
75- CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER : gcc
76- # Add other specific env vars if needed for cross-compilation
77-
78- - name : Build binary (native Windows)
79- if : runner.os == 'Windows'
80- run : cargo build --release --target ${{ matrix.target }} --verbose
52+ - name : Build binary using actions-rust-cross
53+ uses : houseabsolute/actions-rust-cross@v1
54+ with :
55+ # command: 'build' # Default is build
56+ target : ${{ matrix.target }}
57+ args : " --release --verbose"
58+ strip : false # Set to true if you want to strip binaries where possible (not cross-compiled ones)
59+ # cross-version: latest # Default is latest release, usually fine
60+ # use-rust-cache: true # Default is true, uses Swatinem/rust-cache
8161
8262 - name : Determine Artifact Path and Name
8363 id : artifact_details
8464 shell : bash
8565 run : |
86- BINARY_NAME="${{ env.CRATE_NAME }}"
87- ASSET_SUFFIX="${{ matrix.asset_name_suffix }}"
66+ BINARY_NAME="${{ env.CRATE_NAME }}${{ matrix.binary_name_suffix }}"
67+ ASSET_NAME="${{ env.CRATE_NAME }}-${{ matrix.asset_name_suffix }}"
68+ # actions-rust-cross places output in the standard target directory
8869 TARGET_DIR="target/${{ matrix.target }}/release"
89-
90- if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
91- BINARY_PATH="$TARGET_DIR/$BINARY_NAME.exe"
92- ASSET_NAME="$BINARY_NAME-$ASSET_SUFFIX" # Suffix already includes .exe
93- else
94- BINARY_PATH="$TARGET_DIR/$BINARY_NAME"
95- ASSET_NAME="$BINARY_NAME-$ASSET_SUFFIX"
96- fi
70+ BINARY_PATH="$TARGET_DIR/$BINARY_NAME"
9771
9872 echo "Calculated binary path: $BINARY_PATH"
9973 echo "Calculated asset name: $ASSET_NAME"
10074
10175 # Check if the binary exists
10276 if [[ ! -f "$BINARY_PATH" ]]; then
10377 echo "Error: Binary not found at $BINARY_PATH"
104- # List directory contents for debugging
10578 echo "Listing contents of $TARGET_DIR:"
106- ls -l "$TARGET_DIR"
79+ # Ensure the target directory exists before listing
80+ if [[ -d "$TARGET_DIR" ]]; then
81+ ls -l "$TARGET_DIR"
82+ else
83+ echo "Target directory $TARGET_DIR does not exist."
84+ echo "Listing contents of ./target directory:"
85+ ls -l ./target
86+ fi
10787 exit 1
10888 fi
10989
110- echo "binary_path=$BINARY_PATH" >> $GITHUB_OUTPUT
90+ # Rename binary to the desired asset name for easier upload/download
91+ mv "$BINARY_PATH" "$TARGET_DIR/$ASSET_NAME"
92+ echo "Renamed binary to $TARGET_DIR/$ASSET_NAME"
93+
94+ echo "asset_path=$TARGET_DIR/$ASSET_NAME" >> $GITHUB_OUTPUT
11195 echo "asset_name=$ASSET_NAME" >> $GITHUB_OUTPUT
11296
97+ - name : Upload Artifact
98+ uses : actions/upload-artifact@v4
99+ with :
100+ name : ${{ steps.artifact_details.outputs.asset_name }} # Use asset name for artifact name
101+ path : ${{ steps.artifact_details.outputs.asset_path }}
102+ if-no-files-found : error # Error if the artifact isn't found
103+
104+ release :
105+ name : Create GitHub Release
106+ needs : build_assets
107+ runs-on : ubuntu-latest
108+ steps :
109+ - name : Download all artifacts
110+ uses : actions/download-artifact@v4
111+ with :
112+ path : artifacts # Download all artifacts to a directory named 'artifacts'
113+
114+ - name : List downloaded artifacts for debugging
115+ run : |
116+ echo "Listing downloaded artifacts:"
117+ find artifacts -type f
118+ echo "---"
113119
114- - name : Upload Release Asset
115- uses : actions/upload-release-asset@v1
116- env :
117- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
120+ - name : Create Release and Upload Assets
121+ uses : softprops/action-gh-release@v2
118122 with :
119- upload_url : ${{ needs.create_release.outputs.upload_url }}
120- asset_path : ${{ steps.artifact_details.outputs.binary_path }}
121- asset_name : ${{ steps.artifact_details.outputs.asset_name }}
122- asset_content_type : application/octet-stream
123+ # Use the input version for manual triggers, otherwise use the tag ref
124+ tag_name : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}
125+ name : Release ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}
126+ body : |
127+ Automated release for ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.ref_name }}
128+ draft : false
129+ prerelease : false
130+ files : artifacts/*/* # Upload all files from all subdirectories within artifacts
0 commit comments