aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/ci.yml
blob: 68dab6072eefeca4e7e012b37be7a244878efb8e (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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: CI
on:
  push:
    branches: [ master ]
    tags: "[0-9]+.[0-9]+.[0-9]+"
  pull_request:
    branches: [ master ]
  workflow_dispatch:

env:
  DOTNET_VERSION: '6.0.100'

jobs:
  build:
    name: Build and Test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up .NET
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}

      - name: Set Environment Variables
        run: |
          echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV

      - name: Web
        run: ./bin/build --web-only

      - name: Dotnet
        run: ./bin/build --dotnet-only --version ${{ env.VERSION }}

      - name: Upload Static Web Content
        if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
        uses: actions/upload-artifact@v2
        with:
          name: web-${{ env.VERSION }}
          path: src/web/build
  
  publish:
    name: Publish
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
    strategy:
      matrix:
        runtime: [
          "win-x86",
          "win-x64",
          "win-arm",
          "win-arm64",
          "linux-x86",
          "linux-x64",
          "linux-arm",
          "linux-arm64",
          "linux-musl-x86"
          "linux-musl-x64",
          "linux-musl-arm",
          "linux-musl-arm64",
          "osx-x64",
          "osx-arm64"]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up .NET
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}

      - name: Set Environment Variables
        run: |
          echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV

      - name: Download Static Web Content
        uses: actions/download-artifact@v2
        with:
          name: web-${{ env.VERSION }}
          path: src/slskd/wwwroot

      - name: Build ${{ matrix.runtime }}
        run: bin/publish --no-prebuild --runtime ${{ matrix.runtime }} --version ${{ env.VERSION }}

      - name: Upload Binaries
        uses: actions/upload-artifact@v2
        with:
          name: slskd-${{ env.VERSION }}-${{ matrix.runtime }}
          path: dist/${{ matrix.runtime }}
  
  docker:
    name: Build Docker Image
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set Environment Variables
        run: |
          echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
          echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
          echo "REVISION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
          echo "BUILD_DATE=$(date --iso-8601=s)" >> $GITHUB_ENV

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

      - name: Login to DockerHub
        uses: docker/login-action@v1 
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ secrets.GHCR_USERNAME }}
          password: ${{ secrets.GHCR_PAT }}

      - name: Build and push Canary
        if: "!startsWith(github.ref, 'refs/tags/')"
        uses: docker/build-push-action@v2
        with:
          platforms: linux/amd64,linux/arm64,linux/arm/v7
          push: true
          build-args: |
            TAG=${{ env.TAG }}
            VERSION=${{ env.VERSION }}
            REVISION=${{ env.REVISION }}
            BUILD_DATE=${{ env.BUILD_DATE }}
          tags: |
            slskd/slskd:${{ env.VERSION }}
            slskd/slskd:canary
            ghcr.io/slskd/slskd:${{ env.VERSION }}
            ghcr.io/slskd/slskd:canary
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

      - name: Build and push Release
        if: startsWith(github.ref, 'refs/tags/')
        uses: docker/build-push-action@v2
        with:
          platforms: linux/amd64,linux/arm64,linux/arm/v7
          push: true
          build-args: |
            VERSION=${{ env.VERSION }}
          tags: |
            slskd/slskd:${{ env.VERSION }}
            slskd/slskd:${{ env.TAG }}
            slskd/slskd:canary
            slskd/slskd:latest
            ghcr.io/slskd/slskd:${{ env.VERSION }}
            ghcr.io/slskd/slskd:${{ env.TAG }}
            ghcr.io/slskd/slskd:canary
            ghcr.io/slskd/slskd:latest
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

      # Temp fix
      # https://github.com/docker/build-push-action/issues/252
      # https://github.com/moby/buildkit/issues/1896
      - name: Move cache
        if: 
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache

  release:
    name: Create Release
    runs-on: ubuntu-latest
    needs: [publish, docker]
    if: startsWith(github.ref, 'refs/tags/')
    strategy:
      matrix:
        runtime: [
          "win-x86",
          "win-x64",
          "win-arm",
          "win-arm64",
          "linux-x86",
          "linux-x64",
          "linux-arm",
          "linux-arm64",
          "linux-musl-x86"
          "linux-musl-x64",
          "linux-musl-arm",
          "linux-musl-arm64",
          "osx-x64",
          "osx-arm64"]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Set Environment Variables
        run: |
          echo "TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
          echo "VERSION=$(git describe --tags --abbrev=0).$([[ $GITHUB_REF = refs/tags/* ]] && echo 0 || echo 65534)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
      - name: Download ${{ matrix.runtine }} Binaries
        uses: actions/download-artifact@v2
        with:
          name: slskd-${{ env.VERSION }}-${{ matrix.runtime }}
          path: dist/${{ matrix.runtime }}
      - name: Zip ${{ matrix.runtime }} Binaries
        run: |
          cd dist/${{ matrix.runtime }}
          zip -r ../../slskd-${{ env.TAG }}-${{ matrix.runtime }}.zip .
      - name: Create Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: |
            slskd-${{ env.TAG }}-win-x86.zip
            slskd-${{ env.TAG }}-win-x64.zip
            slskd-${{ env.TAG }}-win-arm.zip
            slskd-${{ env.TAG }}-win-arm64.zip
            slskd-${{ env.TAG }}-linux-x86.zip
            slskd-${{ env.TAG }}-linux-x64.zip
            slskd-${{ env.TAG }}-linux-arm.zip
            slskd-${{ env.TAG }}-linux-arm64.zip
            slskd-${{ env.TAG }}-linux-musl-x86.zip
            slskd-${{ env.TAG }}-linux-musl-x64.zip
            slskd-${{ env.TAG }}-linux-musl-arm.zip
            slskd-${{ env.TAG }}-linux-musl-arm64.zip
            slskd-${{ env.TAG }}-osx-x64.zip
            slskd-${{ env.TAG }}-osx-arm64.zip
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}