Skip to content

Commit 74a2b08

Browse files
committed
fix: workflow env
1 parent 2efdb9d commit 74a2b08

File tree

1 file changed

+60
-38
lines changed

1 file changed

+60
-38
lines changed

.github/workflows/release.yml

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,87 +24,109 @@ jobs:
2424
strategy:
2525
matrix:
2626
include:
27+
# Nix builds (native)
2728
- target: x86_64-unknown-linux-gnu
28-
os: ubuntu-latest # Use Linux runner for cross-compilation via Docker
29+
os: ubuntu-latest
30+
build_method: nix
2931
asset_name_suffix: linux-x86_64
3032
binary_name_suffix: ""
3133
- target: x86_64-apple-darwin
3234
os: macos-latest
35+
build_method: nix
3336
asset_name_suffix: macos-x86_64
3437
binary_name_suffix: ""
38+
# Cross builds
3539
- target: aarch64-apple-darwin
36-
os: macos-latest # Can build aarch64 on x86_64 macOS runners
40+
os: macos-latest # Cross-compile from x86_64 runner
41+
build_method: cross
3742
asset_name_suffix: macos-aarch64
3843
binary_name_suffix: ""
3944
- target: x86_64-pc-windows-msvc
4045
os: windows-latest
46+
build_method: cross
4147
asset_name_suffix: windows-x86_64.exe
42-
binary_name_suffix: ".exe" # Add .exe for Windows binary name
48+
binary_name_suffix: ".exe"
4349

4450
runs-on: ${{ matrix.os }}
4551
steps:
4652
- name: Checkout code
4753
uses: actions/checkout@v4
4854

49-
# No need to explicitly set up Rust toolchain, actions-rust-cross handles it
50-
# No need to manually install cross
51-
52-
- name: Build binary using actions-rust-cross
53-
uses: houseabsolute/actions-rust-cross@v1
55+
# --- Nix Setup (only runs if build_method is nix) ---
56+
- name: Install Nix
57+
uses: cachix/install-nix-action@v31
58+
if: matrix.build_method == 'nix'
5459
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
61-
- name: Install Linux dependencies
62-
if: runner.os == 'Linux'
63-
run: |
64-
sudo apt-get update
65-
sudo apt-get install -y libssl-dev pkg-config
66-
67-
- name: Install macOS dependencies
68-
if: runner.os == 'macOS'
60+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
61+
# Ensure flakes are enabled (default in recent versions, but explicit is safe)
62+
extra_nix_config: |
63+
experimental-features = nix-command flakes
64+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
65+
66+
# --- Dependency Setup for Cross-Compile (only runs if build_method is cross) ---
67+
- name: Install macOS dependencies (for cross-compile)
68+
# Only needed when cross-compiling aarch64 on an x86_64 macOS runner
69+
if: matrix.build_method == 'cross' && matrix.target == 'aarch64-apple-darwin'
6970
run: |
7071
brew install openssl@3 pkg-config
7172
echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
7273
echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV
7374
75+
# --- Build Steps (conditional) ---
76+
- name: Build binary using Nix
77+
if: matrix.build_method == 'nix'
78+
# Assuming your flake provides the crate binary via the default package `.#rustdocs_mcp_server`
79+
# or adjust the flake output reference as needed (e.g., .#packages.${system}.default)
80+
run: nix build .#${CRATE_NAME} --print-build-logs
7481

82+
- name: Build binary using actions-rust-cross
83+
if: matrix.build_method == 'cross'
84+
uses: houseabsolute/actions-rust-cross@v1
85+
with:
86+
target: ${{ matrix.target }}
87+
args: "--release --verbose"
88+
strip: false # Keep strip false for consistency, especially with cross-compiles
89+
90+
# --- Artifact Handling ---
7591
- name: Determine Artifact Path and Name
7692
id: artifact_details
7793
shell: bash
7894
run: |
7995
BINARY_NAME="${{ env.CRATE_NAME }}${{ matrix.binary_name_suffix }}"
8096
ASSET_NAME="${{ env.CRATE_NAME }}-${{ matrix.asset_name_suffix }}"
81-
# actions-rust-cross places output in the standard target directory
82-
TARGET_DIR="target/${{ matrix.target }}/release"
83-
BINARY_PATH="$TARGET_DIR/$BINARY_NAME"
8497
98+
if [[ "${{ matrix.build_method }}" == "nix" ]]; then
99+
# Nix build output path (adjust if flake output is different)
100+
# Assumes the binary is directly in result/bin/
101+
BINARY_PATH="./result/bin/$BINARY_NAME"
102+
else
103+
# Cross build output path
104+
BINARY_PATH="target/${{ matrix.target }}/release/$BINARY_NAME"
105+
fi
106+
107+
echo "Build method: ${{ matrix.build_method }}"
85108
echo "Calculated binary path: $BINARY_PATH"
86109
echo "Calculated asset name: $ASSET_NAME"
87110
88111
# Check if the binary exists
89112
if [[ ! -f "$BINARY_PATH" ]]; then
90113
echo "Error: Binary not found at $BINARY_PATH"
91-
echo "Listing contents of $TARGET_DIR:"
92-
# Ensure the target directory exists before listing
93-
if [[ -d "$TARGET_DIR" ]]; then
94-
ls -l "$TARGET_DIR"
95-
else
96-
echo "Target directory $TARGET_DIR does not exist."
97-
echo "Listing contents of ./target directory:"
98-
ls -l ./target
99-
fi
114+
echo "Listing contents of potential output directories:"
115+
echo "--- Nix build (./result/bin):"
116+
ls -l ./result/bin || echo "Directory ./result/bin not found or empty."
117+
echo "--- Cross build (target/${{ matrix.target }}/release):"
118+
ls -l target/${{ matrix.target }}/release || echo "Directory target/${{ matrix.target }}/release not found or empty."
100119
exit 1
101120
fi
102121
103-
# Rename binary to the desired asset name for easier upload/download
104-
mv "$BINARY_PATH" "$TARGET_DIR/$ASSET_NAME"
105-
echo "Renamed binary to $TARGET_DIR/$ASSET_NAME"
122+
# Create a temporary directory for consistent artifact upload
123+
mkdir -p ./artifacts_temp
124+
RENAMED_PATH="./artifacts_temp/$ASSET_NAME"
125+
# Move the binary to the temp dir with the final asset name
126+
mv "$BINARY_PATH" "$RENAMED_PATH"
127+
echo "Moved/Renamed binary to $RENAMED_PATH"
106128
107-
echo "asset_path=$TARGET_DIR/$ASSET_NAME" >> $GITHUB_OUTPUT
129+
echo "asset_path=$RENAMED_PATH" >> $GITHUB_OUTPUT
108130
echo "asset_name=$ASSET_NAME" >> $GITHUB_OUTPUT
109131
110132
- name: Upload Artifact

0 commit comments

Comments
 (0)