summaryrefslogtreecommitdiffstats
path: root/.github/workflows/deploy.yml
blob: 3b9cb509a858e2254841a8cc31ec1bdb4b40c2f6 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Based on https://github.com/starship/starship/blob/master/.github/workflows/deploy.yml

name: Deploy
on:
  push:
    tags:
      - "*"

env:
  CRATE_NAME: mdbook-mermaid

jobs:
  # Build sources for every OS
  github_build:
    name: Build release binaries
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-gnu
          - x86_64-unknown-linux-musl
          - x86_64-apple-darwin
          - aarch64-apple-darwin
          - x86_64-pc-windows-msvc
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            name: x86_64-unknown-linux-gnu.tar.gz
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            name: x86_64-unknown-linux-musl.tar.gz
          - target: x86_64-apple-darwin
            os: macOS-latest
            name: x86_64-apple-darwin.tar.gz
          - target: aarch64-apple-darwin
            os: macOS-latest
            name: aarch64-apple-darwin.tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: x86_64-pc-windows-msvc.zip
    runs-on: ${{ matrix.os }}
    steps:
      - name: Setup | Checkout
        uses: actions/checkout@v3

      # Cache files between builds
      - uses: Swatinem/rust-cache@v1

      - name: Setup | Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          profile: minimal
          target: ${{ matrix.target }}

      - uses: Swatinem/rust-cache@v1

      - name: Setup | musl tools
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt install -y musl-tools

      - name: Build | Build
        if: matrix.target != 'x86_64-unknown-linux-musl'
        run: cargo build --release --target ${{ matrix.target }}

      - name: Build | Build (musl)
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: cargo build --release --target ${{ matrix.target }}

      - name: Post Setup | Extract tag name
        shell: bash
        run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/})"
        id: extract_tag

      - name: Post Setup | Prepare artifacts [Windows]
        if: matrix.os == 'windows-latest'
        run: |
          mkdir target/stage
          cd target/${{ matrix.target }}/release
          strip ${{ env.CRATE_NAME }}.exe
          7z a ../../stage/${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }} ${{ env.CRATE_NAME }}.exe
          cd -

      - name: Post Setup | Prepare artifacts [-nix]
        if: matrix.os != 'windows-latest'
        run: |
          mkdir target/stage
          cd target/${{ matrix.target }}/release
          strip ${{ env.CRATE_NAME }}
          tar czvf ../../stage/${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }} ${{ env.CRATE_NAME }}
          cd -

      - name: Post Setup | Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: ${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }}
          path: target/stage/*

  # Create GitHub release with Rust build targets and release notes
  github_release:
    name: Create GitHub Release
    needs: github_build
    runs-on: ubuntu-latest
    steps:
      - name: Setup | Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Setup | Artifacts
        uses: actions/download-artifact@v3

      - name: Setup | Release notes
        run: |
          git log -1 --pretty='%s' > RELEASE.md

      - name: Build | Publish
        uses: softprops/action-gh-release@v1
        with:
          files: ${{ env.CRATE_NAME }}-*/${{ env.CRATE_NAME }}-*
          body_path: RELEASE.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}