summaryrefslogtreecommitdiffstats
path: root/.github/workflows/release.yml
blob: 70bae535d51591a8d7feb9e1d7aa9929d5f626ae (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
125
126
name: release
on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

env:
  CARGO_INCREMENTAL: 0

jobs:
  release:
    name: ${{ matrix.target }}
    permissions:
      contents: write
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            deb: true
          - os: ubuntu-latest
            target: arm-unknown-linux-musleabihf
          - os: ubuntu-latest
            target: armv7-unknown-linux-musleabihf
          - os: ubuntu-latest
            target: aarch64-unknown-linux-musl
            deb: true

          - os: macos-11
            target: x86_64-apple-darwin
          - os: macos-11
            target: aarch64-apple-darwin

          - os: windows-latest
            target: x86_64-pc-windows-msvc
          - os: windows-latest
            target: aarch64-pc-windows-msvc
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set artifact name
        shell: bash
        run: |
          version="$(git describe --tags --match='v*.*.*' --always)"
          name="zoxide-$version-${{ matrix.target }}"
          echo "ARTIFACT_NAME=$name" >> $GITHUB_ENV

          echo "version: $version"
          echo "artifact: $name"

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

      - name: Setup cache
        uses: Swatinem/rust-cache@v1

      - name: Build binary
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --locked --target=${{ matrix.target }} --color=always --verbose
          use-cross: ${{ runner.os == 'Linux' }}

      - name: Install cargo-deb
        if: ${{ matrix.deb == true }}
        uses: actions-rs/cargo@v1
        with:
          command: install
          args: cargo-deb --locked

      - name: Build deb
        if: ${{ matrix.deb == true }}
        uses: actions-rs/cargo@v1
        with:
          command: deb
          args: --no-build --no-strip --output=. --target=${{ matrix.target }}

      - name: Package (*nix)
        if: runner.os != 'Windows'
        run: >
          tar -cv
          CHANGELOG.md LICENSE README.md
          man/
          -C contrib/ completions/ -C ../
          -C target/${{ matrix.target }}/release/ zoxide
          | gzip --best > '${{ env.ARTIFACT_NAME }}.tar.gz'
      - name: Package (Windows)
        if: runner.os == 'Windows'
        run: >
          7z a ${{ env.ARTIFACT_NAME }}.zip
          CHANGELOG.md LICENSE README.md
          ./man/
          ./contrib/completions/
          ./target/${{ matrix.target }}/release/zoxide.exe

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: ${{ matrix.target }}
          path: |
            *.deb
            *.tar.gz
            *.zip

      - name: Create release
        if: startsWith(github.event.head_commit.message, 'chore(release)')
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          files: |
            *.deb
            *.tar.gz
            *.zip
          name: ${{ github.event.head_commit.id }}
          tag_name: ""