summaryrefslogtreecommitdiffstats
path: root/.github/workflows/cd.yml
blob: 31ef76f4238b7506020ccd0649a668d6153f9f6d (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
name: CD

on:
  push:
    tags:
      - "v*.*.*"

jobs:
  publish:
    name: Publishing ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    container: ${{ matrix.container }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-latest
            target: x86_64-apple-darwin
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            container: rust
            dependencies: "libssl-dev libasound2-dev libdbus-1-dev"
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            container: rustembedded/cross:aarch64-unknown-linux-gnu
            cross_arch: "arm64"
            pkg_config_path: "/usr/lib/aarch64-linux-gnu/pkgconfig/"
            dependencies: "libssl-dev:arm64 libasound2-dev:arm64 libdbus-1-dev:arm64"
          - os: ubuntu-latest
            target: armv7-unknown-linux-gnueabihf
            cross_arch: "armhf"
            pkg_config_path: "/usr/lib/arm-linux-gnueabihf/pkgconfig/"
            container: rustembedded/cross:armv7-unknown-linux-gnueabihf
            dependencies: "libssl-dev:armhf libasound2-dev:armhf libdbus-1-dev:armhf"
          - os: windows-latest
            target: x86_64-pc-windows-msvc

    steps:
      - name: Checkout source
        uses: actions/checkout@v2

      - name: Set up cross compilation
        if: matrix.cross_arch
        run: |
          dpkg --add-architecture ${{ matrix.cross_arch }}
          echo "PKG_CONFIG_PATH=${{ matrix.pkg_config_path }}" >> $GITHUB_ENV
          echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV

      - name: Install Linux dependencies
        if: matrix.dependencies
        run: apt update && apt install -y ${{ matrix.dependencies }}

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

      - name: Build
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --locked --release --target ${{ matrix.target }}

      - name: Package
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          case ${{ matrix.target }} in
          *-pc-windows-*)
            7z -y a hackernews_tui-${{ matrix.target }}.zip hackernews_tui.exe
            sha256sum hackernews_tui-${{ matrix.target }}.zip > hackernews_tui-${{ matrix.target }}.sha256
            ;;
          *)
            tar czvf hackernews_tui-${{ matrix.target }}.tar.gz hackernews_tui
            shasum -a 256 hackernews_tui-${{ matrix.target }}.tar.gz > hackernews_tui-${{ matrix.target }}.sha256
            ;;
          esac;

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: target/${{ matrix.target }}/release/hackernews_tui-*
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}