Skip to content

Commit 1c1c54f

Browse files
authored
Add windows build support
1 parent 361c818 commit 1c1c54f

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

.github/workflows/main.yml

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,67 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest, macos-14, windows-latest]
1616

17+
defaults:
18+
run:
19+
shell: bash
20+
1721
steps:
1822
- uses: actions/checkout@v4
1923

20-
- name: Get Architecture
21-
id: arch
22-
run: echo "ARCH=$(uname -m)" >> $GITHUB_ENV
23-
shell: bash
24+
# Compute OS/arch and pick extension + suffix
25+
- name: Compute metadata
26+
run: |
27+
ARCH="$(uname -m)"
28+
OS="${{ matrix.os }}"
29+
EXT="tar.gz"; SUF=""
30+
if [[ "$OS" == "windows-latest" ]]; then EXT="zip"; SUF=".exe"; fi
31+
32+
NAME="${{ github.event.repository.name }}-${{ github.ref_name }}-${OS}-${ARCH}"
33+
echo "ARCH=$ARCH" >> $GITHUB_ENV
34+
echo "OS=$OS" >> $GITHUB_ENV
35+
echo "EXT=$EXT" >> $GITHUB_ENV
36+
echo "SUF=$SUF" >> $GITHUB_ENV
37+
echo "NAME=$NAME" >> $GITHUB_ENV
2438
25-
- name: Build Binary
39+
- name: Build
40+
run: cargo build --release
41+
42+
- name: Stage artifact
2643
run: |
27-
cargo build --release
2844
mkdir -p dist
29-
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
30-
cp target/release/${{ github.event.repository.name }}.exe dist/${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}.exe
31-
else
32-
cp target/release/${{ github.event.repository.name }} dist/${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}
45+
SRC="target/release/${{ github.event.repository.name }}${SUF}"
46+
if [[ ! -f "$SRC" ]]; then
47+
# Fallback if binary name != repo name
48+
if [[ -n "$SUF" ]]; then
49+
SRC="$(ls -1 target/release/*.exe | head -n1)"
50+
else
51+
SRC="$(ls -1 target/release/* | grep -v '\.rlib$' | grep -v '\.rmeta$' | grep -v '\.dSYM$' | head -n1)"
52+
fi
3353
fi
34-
shell: bash
54+
cp "$SRC" "dist/${NAME}${SUF}"
3555
36-
- name: Archive Binary
56+
- name: Archive
3757
run: |
3858
cd dist
39-
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
40-
zip ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}.zip *.exe
59+
if [[ "$EXT" == "zip" ]]; then
60+
# Windows: use zip if present, otherwise PowerShell
61+
if command -v zip >/dev/null 2>&1; then
62+
zip "${NAME}.zip" "${NAME}${SUF}"
63+
else
64+
pwsh -Command "Compress-Archive -Path '${NAME}${SUF}' -DestinationPath '${NAME}.zip' -Force"
65+
fi
4166
else
42-
tar -czf ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}.tar.gz ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}
67+
tar -czf "${NAME}.tar.gz" "${NAME}"
4368
fi
44-
shell: bash
69+
# Save exact path for upload (no globs!)
70+
echo "ARTIFACT=dist/${NAME}.${EXT}" >> $GITHUB_ENV
4571
4672
- name: Upload release asset
4773
uses: actions/upload-release-asset@v1
4874
with:
4975
upload_url: ${{ github.event.release.upload_url }}
50-
asset_path: |
51-
dist/${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}.*
52-
asset_name: ${{ github.event.repository.name }}-${{ github.ref_name }}-${{ matrix.os }}-${{ env.ARCH }}.${{ matrix.os == 'windows-latest' && 'zip' || 'tar.gz' }}
76+
asset_path: ${{ env.ARTIFACT }}
77+
asset_name: ${{ env.NAME }}.${{ env.EXT }}
5378
asset_content_type: application/octet-stream
5479
env:
5580
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)