ci: fix build error on windows #66
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
push: | |
branches: [ master, release ] | |
tags: | |
- "v*" | |
env: | |
CARGO_TERM_COLOR: always | |
RUSTFLAGS: -Dwarnings | |
RUST_BACKTRACE: 1 | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
create_release: | |
runs-on: ubuntu-latest | |
outputs: | |
release_tag: ${{ steps.create_release.outputs.release_tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: create_release | |
run: | | |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
echo "release_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
gh release create --generate-notes "${GITHUB_REF#refs/tags/}" | |
else | |
echo "release_tag=nightly" >> $GITHUB_OUTPUT | |
gh release delete --cleanup-tag --yes nightly | |
gh release create --generate-notes --prerelease --title "Development Build" nightly | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ env.GITHUB_REPOSITORY }} | |
build_assets: | |
permissions: | |
id-token: write | |
contents: write | |
attestations: write | |
needs: create_release | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
name: xsnippet-api-x86_64-linux.gz | |
- target: aarch64-unknown-linux-gnu | |
os: ubuntu-latest | |
name: xsnippet-api-aarch64-linux.gz | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
name: xsnippet-api-x86_64-windows.exe.7z | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
name: xsnippet-api-aarch64-macos.gz | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Setup PostgreSQL | |
uses: ikalnytskyi/action-setup-postgres@v6 | |
- id: detect_host | |
run: | | |
echo "host=$(rustc -vV | grep host: | awk '{print $2}')" >> $GITHUB_OUTPUT | |
- name: Build | |
if: ${{ steps.detect_host.outputs.host == matrix.target }} | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release --target ${{ matrix.target }} | |
- name: Build (cross-compile) | |
if: ${{ steps.detect_host.outputs.host != matrix.target }} | |
run: | | |
cargo install cross | |
cross build --release --target ${{ matrix.target }} | |
- id: upload | |
name: Upload artifacts | |
run: | | |
pushd target/${{ matrix.target }}/release | |
if [[ "${{ matrix.target }}" =~ "windows" ]]; then | |
7z a ${{ matrix.name }} xsnippet-api.exe | |
else | |
tar cvzf ${{ matrix.name }} xsnippet-api | |
fi | |
gh release upload ${{ needs.create_release.outputs.release_tag }} ${{ matrix.name }} | |
popd | |
echo "asset_path=target/${{ matrix.target }}/release/${{ matrix.name }}" >> $GITHUB_OUTPUT | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ env.GITHUB_REPOSITORY }} | |
- uses: actions/attest-build-provenance@v1 | |
with: | |
subject-path: ${{ steps.upload.outputs.asset_path }} |