aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/build-release.yml
blob: 1b84fc3716cfa41742752e899c177671b5650756 (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
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
name: Build and Release

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: linux
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            artifact_name: linux-musl
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: windows

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          targets: ${{ matrix.target }}

      - name: Cache cargo dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-

      - name: Build for target
        run: cargo build --release --target ${{ matrix.target }}
        env:
          CARGO_TARGET_DIR: target

      - name: Prepare artifacts
        shell: bash
        run: |
          mkdir -p artifacts/${{ matrix.artifact_name }}

          if [ "${{ matrix.os }}" = "windows-latest" ]; then
            # Windows artifacts
            cp target/${{ matrix.target }}/release/cobill.exe artifacts/${{ matrix.artifact_name }}/ || true
            cp target/${{ matrix.target }}/release/cobill_comp.ps1 artifacts/${{ matrix.artifact_name }}/ || true
          else
            # Linux artifacts
            cp target/${{ matrix.target }}/release/cobill artifacts/${{ matrix.artifact_name }}/ || true
            cp target/${{ matrix.target }}/release/cobill_comp.sh artifacts/${{ matrix.artifact_name }}/ || true
            cp target/${{ matrix.target }}/release/cobill_comp.zsh artifacts/${{ matrix.artifact_name }}/ || true
            cp target/${{ matrix.target }}/release/cobill_comp.fish artifacts/${{ matrix.artifact_name }}/ || true

            # Make Linux binaries executable
            chmod +x artifacts/${{ matrix.artifact_name }}/cobill || true
            chmod +x artifacts/${{ matrix.artifact_name }}/cobill_comp.sh || true
            chmod +x artifacts/${{ matrix.artifact_name }}/cobill_comp.zsh || true
            chmod +x artifacts/${{ matrix.artifact_name }}/cobill_comp.fish || true
          fi

      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.artifact_name }}-binaries
          path: artifacts/${{ matrix.artifact_name }}/
          retention-days: 7

  release:
    needs: build
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Create release
        uses: softprops/action-gh-release@v1
        with:
          files: |
            artifacts/linux/*
            artifacts/linux-musl/*
            artifacts/windows/*
          tag_name: v${{ github.run_number }}
          name: Release v${{ github.run_number }}
          body: |
            Automated release from master branch

            Build number: ${{ github.run_number }}
            Commit: ${{ github.sha }}
          draft: false
          prerelease: false