summaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: 2ec7c5044e834e6d7bc9d209639a1ed32b45d113 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Based on ripgrep's release action:
# https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml

name: Build Release Binaries
on:
  release:
    types: [created]

jobs:
  build-release:
    name: build-release
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        build: [linux, macos, win-msvc]
        include:
        - build: linux
          os: ubuntu-22.04
          target: x86_64-unknown-linux-gnu
        - build: macos
          os: macos-12
          target: x86_64-apple-darwin
        - build: win-msvc
          os: windows-2022
          target: x86_64-pc-windows-msvc

    steps:
    - uses: actions/checkout@v3
    - uses: dtolnay/rust-toolchain@stable

    - name: Build release binary
      run: cargo build -p typst-cli --release

    - name: Strip binary (Linux and macOS)
      if: matrix.build == 'linux' || matrix.build == 'macos'
      run: strip "target/release/typst"

    - name: Build archive
      shell: bash
      run: |
        directory="typst-${{ matrix.target }}"
        mkdir "$directory"
        cp {README.md,LICENSE,NOTICE} "$directory/"
        if [ "${{ matrix.os }}" = "windows-2022" ]; then
          cp "target/release/typst.exe" "$directory/"
          7z a "$directory.zip" "$directory"
          echo "ASSET=$directory.zip" >> $GITHUB_ENV
        else
          cp "target/release/typst" "$directory/"
          tar czf "$directory.tar.gz" "$directory"
          echo "ASSET=$directory.tar.gz" >> $GITHUB_ENV
        fi

    - name: Upload release archive
      uses: actions/upload-release-asset@v1.0.2
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ github.event.release.upload_url }}
        asset_path: ${{ env.ASSET }}
        asset_name: ${{ env.ASSET }}
        asset_content_type: application/octet-stream