Skip to content

Commit a93b364

Browse files
authored
Merge pull request #179 from xsnippet/release
ci: fix build error on windows
2 parents 8c7f829 + 3dc6e4a commit a93b364

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

.github/workflows/release.yml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,40 @@ jobs:
7575
- name: Setup PostgreSQL
7676
uses: ikalnytskyi/action-setup-postgres@v6
7777

78-
- id: build
78+
- id: detect_host
7979
run: |
80-
export HOST=$(rustc -vV | grep host: | awk '{print $2}')
81-
if [ "$HOST" = "$TARGET" ]; then
82-
cargo build --release --target ${TARGET}
83-
else
84-
cargo install cross
85-
cross build --release --target ${TARGET}
86-
fi
80+
echo "host=$(rustc -vV | grep host: | awk '{print $2}')" >> $GITHUB_OUTPUT
81+
82+
- name: Build
83+
if: ${{ steps.detect_host.outputs.host == matrix.target }}
84+
uses: actions-rs/cargo@v1
85+
with:
86+
command: build
87+
args: --release --target ${{ matrix.target }}
8788

88-
pushd target/${TARGET}/release
89-
if [[ "$TARGET" =~ "windows" ]]; then
90-
7z a $ASSET_NAME xsnippet-api.exe
89+
- name: Build (cross-compile)
90+
if: ${{ steps.detect_host.outputs.host != matrix.target }}
91+
run: |
92+
cargo install cross
93+
cross build --release --target ${{ matrix.target }}
94+
95+
- id: upload
96+
name: Upload artifacts
97+
run: |
98+
pushd target/${{ matrix.target }}/release
99+
if [[ "${{ matrix.target }}" =~ "windows" ]]; then
100+
7z a ${{ matrix.name }} xsnippet-api.exe
91101
else
92-
tar cvzf $ASSET_NAME xsnippet-api
102+
tar cvzf ${{ matrix.name }} xsnippet-api
93103
fi
94-
gh release upload $RELEASE_TAG $ASSET_NAME
104+
gh release upload ${{ needs.create_release.outputs.release_tag }} ${{ matrix.name }}
95105
popd
96106
97-
echo "asset_path=target/${TARGET}/release/$ASSET_NAME" >> $GITHUB_OUTPUT
107+
echo "asset_path=target/${{ matrix.target }}/release/${{ matrix.name }}" >> $GITHUB_OUTPUT
98108
env:
99-
ASSET_NAME: ${{ matrix.name }}
100109
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101110
GH_REPO: ${{ env.GITHUB_REPOSITORY }}
102-
TARGET: ${{ matrix.target }}
103-
RELEASE_TAG: ${{ needs.create_release.outputs.release_tag }}
104111

105112
- uses: actions/attest-build-provenance@v1
106113
with:
107-
subject-path: ${{ steps.build.outputs.asset_path }}
114+
subject-path: ${{ steps.upload.outputs.asset_path }}

0 commit comments

Comments
 (0)