summaryrefslogtreecommitdiffhomepage
path: root/.github/workflows/unitctl.yml
blob: e8e5adf876e4752fcb1f5319c34da0c2cdbfdc05 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

name: unitctl

on:
  pull_request:
    paths:
      - tools/unitctl/**
      - docs/unit-openapi.yaml
  push:
    branches:
      - master
    tags:
      - '[0-9]+.[0-9]+.[0-9]+'
  workflow_dispatch:
    inputs:
      version:
        type: string
        description: "Semver tag"
        required: true

permissions:
  contents: write

jobs:
  test:
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        working-directory: tools/unitctl
    env:
      MAKE: make
      CARGO: cargo
      VERSION:
      SHORT_VERSION:
    strategy:
      fail-fast: false
      matrix:
        include:
          - build: linux-x86_64
            os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - build: macos-aarch64
            os: macos-latest
            target: aarch64-apple-darwin
    steps:
      - uses: actions/checkout@v4

      - run: rustup update stable
      - run: rustup target add ${{ matrix.target }}

      - name: Install cross
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        uses: taiki-e/install-action@v2
        with:
          tool: cross

      - name: Install macOS depedencies
        if: startsWith(matrix.os, 'macos')
        run: |
          brew install make gnu-sed grep gawk
          echo "MAKE=gmake" >> $GITHUB_ENV

      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 21

      - run: ${{ env.MAKE }} list-targets

      - name: Generate openapi
        run: ${{ env.MAKE }} openapi-generate
      - name: Test ${{ matrix.os }}
        run: ${{ env.MAKE }} test

  build:
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        working-directory: tools/unitctl
    env:
      MAKE: make
      CARGO: cargo
      VERSION:
      SHORT_VERSION:
    strategy:
      fail-fast: false
      matrix:
        include:
          - build: linux-aarch64
            os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
          - build: linux-x86_64
            os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - build: macos-aarch64
            os: macos-latest
            target: aarch64-apple-darwin
          - build: macos-x86_64
            os: macos-latest
            target: x86_64-apple-darwin

    steps:
      - uses: actions/checkout@v4

      - run: rustup update stable
      - run: rustup target add ${{ matrix.target }}

      - name: Install cross
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        uses: taiki-e/install-action@v2
        with:
          tool: cross

      - uses: Swatinem/rust-cache@v2
        with:
          prefix-key: rust-${{ matrix.build }}
          workspaces: ./tools/unitctl -> target
          save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }}

      - name: Configure linux arm dependencies
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          cat <<EOF > Cross.toml
          [target.aarch64-unknown-linux-gnu]
          pre-build = [
              "dpkg --add-architecture \$CROSS_DEB_ARCH",
              "apt-get update && apt-get install --assume-yes libssl-dev:\$CROSS_DEB_ARCH"
          ]
          EOF

          cat Cross.toml
          echo "CARGO=cross" >> $GITHUB_ENV

      - name: Install macOS dependencies
        if: startsWith(matrix.os, 'macos')
        run: |
          brew install make gnu-sed grep gawk
          echo "MAKE=gmake" >> $GITHUB_ENV

      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 21

      - run: ${{ env.MAKE }} list-targets

      - name: Make unitctl (${{ env.MAKE }}, ${{ matrix.target }})
        run: ${{ env.MAKE }} ${{ matrix.target }}

      - name: Get the version from the tag
        run: |
          version=${version:=${{ github.ref_name }}}
          short="${version#*/}"
          echo $version; echo $short
          echo "VERSION=$version" >> $GITHUB_ENV
          echo "SHORT_VERSION=$short" >> $GITHUB_ENV

      - name: Generate sha256 sum
        run: |
          shasum -a 256 ./target/${{ matrix.target }}/release/unitctl > unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}.sha256
          mv ./target/${{ matrix.target }}/release/unitctl unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}

      - name: Upload sha256 sum
        uses: actions/upload-artifact@v4
        with:
          name: unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}.sha256
          path: tools/unitctl/unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}.sha256

      - name: Upload unitctl
        uses: actions/upload-artifact@v4
        with:
          name: unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}
          path: tools/unitctl/unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}

  release:
    # Create a draft release if a tag
    if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          merge-multiple: true

      - name: Create GitHub release
        uses: ncipollo/release-action@v1
        with:
          artifacts: "unitctl-*"
          # false if triggered by a tag
          prerelease: ${{github.event_name == 'workflow_dispatch' && true}}
          tag: ${{(github.event_name == 'workflow_dispatch' && inputs.version) || github.ref_name}}
          name: unitctl/${{(github.event_name=='workflow_dispatch' && inputs.version) || github.ref_name}}
          body: >
            ## Unitctl

            This is a released binary of unitctl.

            Unitctl is an official command line tool for managing Unit installations.


            ## Unit

            For the current release of the NGINX Unit application server check the
            [Unit Installation Guide](https://unit.nginx.org/installation/) and the
            [Unit Quickstart Guide](https://github.com/nginx/unit/).

          allowUpdates: true