aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/ci.yml
blob: d4a328a4402f5517aadd7e8a033b53ecb750e4c9 (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
name: CI
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  workflow_dispatch:

jobs:
  build:
    name: Build and Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Web
        run: ./bin/build --web-only
      - name: Dotnet
        run: ./bin/build --dotnet-only
      - name: Upload Static Web Content
        uses: actions/upload-artifact@v2
        with:
          name: web
          path: src/slskd/wwwroot
  publish:
    name: Publish Build Artifacts
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/master'
    strategy:
      matrix:
        runtime: ["win-x64", "linux-x64", "linux-musl-x64", "linux-arm64", "osx-x64"]
    steps:
      - uses: actions/checkout@v2
      - name: Set Environment Variables
        run: |
          echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
          csproj=$(cat src/slskd/slskd.csproj)
          pattern='<VersionPrefix>(.*)<\/VersionPrefix>'
          [[ "$csproj" =~ $pattern ]]
          echo "APP_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
      - uses: actions/download-artifact@v2
        with:
          name: web
          path: src/slskd/wwwroot
      - name: Publish ${{ matrix.runtime }}
        run: bin/publish --no-prebuild --runtime ${{ matrix.runtime }} --version-suffix ${{ env.SHORT_SHA }}
      - name: Upload a Build Artifact
        uses: actions/upload-artifact@v2
        with:
          name: slskd-${{ env.APP_VERSION }}.${{ env.SHORT_SHA }}-${{ matrix.runtime }}
          path: dist/${{ matrix.runtime }}
  docker:
    name: Build Docker Image
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/master'
    steps:
      - uses: actions/checkout@v2
      - name: Set Environment Variables
        run: |
          echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
          csproj=$(cat src/slskd/slskd.csproj)
          pattern='<VersionPrefix>(.*)<\/VersionPrefix>'
          [[ "$csproj" =~ $pattern ]]
          echo "APP_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
      - name: Docker Build
        run: docker build -t slskd/slskd:${{ env.APP_VERSION }}.${{ env.SHORT_SHA }} .
      - name: Login to Docker Hub
        run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
      - name: Docker Push SHA Tag
        run: docker push slskd/slskd:${{ env.APP_VERSION }}.${{ env.SHORT_SHA }}