1name: Publish Docker
2
3on:
4  push:
5    branches: [master, beta, nightly]
6    tags: [v*]
7
8jobs:
9  build-docker:
10    name: Build Docker Image
11    runs-on: ubuntu-latest
12    if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
13    steps:
14      - name: Checkout Code
15        uses: actions/checkout@v2
16
17      - name: Prepare
18        id: prepare
19        run: |
20          if [[ $GITHUB_REF == refs/tags/* ]]; then
21            echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
22          elif [[ $GITHUB_REF == refs/heads/master ]]; then
23            echo ::set-output name=tag::latest
24          else
25            echo ::set-output name=tag::${GITHUB_REF#refs/heads/}
26          fi
27          if [[ $GITHUB_REF == refs/tags/*-beta ]]; then
28            echo ::set-output name=branch::beta
29          elif [[ $GITHUB_REF == refs/tags/* ]]; then
30            echo ::set-output name=branch::master
31          else
32            echo ::set-output name=branch::${GITHUB_REF#refs/heads/}
33          fi
34          echo ::set-output name=commit::${GITHUB_SHA}
35          echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
36          echo ::set-output name=docker_platforms::linux/amd64,linux/arm64/v8,linux/arm/v7,linux/arm/v6
37          echo ::set-output name=docker_image::${{ secrets.DOCKER_REPO }}/tautulli
38
39      - name: Set Up QEMU
40        uses: docker/setup-qemu-action@v1
41
42      - name: Set up Docker Buildx
43        uses: docker/setup-buildx-action@v1
44        id: buildx
45        with:
46          version: latest
47
48      - name: Cache Docker Layers
49        uses: actions/cache@v2
50        with:
51          path: /tmp/.buildx-cache
52          key: ${{ runner.os }}-buildx-${{ github.sha }}
53          restore-keys: |
54            ${{ runner.os }}-buildx-
55
56      - name: Login to DockerHub
57        uses: docker/login-action@v1
58        if: success()
59        with:
60          username: ${{ secrets.DOCKER_USERNAME }}
61          password: ${{ secrets.DOCKER_PASSWORD }}
62
63      - name: Login to GitHub Container Registry
64        uses: docker/login-action@v1
65        if: success()
66        with:
67          registry: ghcr.io
68          username: ${{ secrets.DOCKER_USERNAME }}
69          password: ${{ secrets.GHCR_TOKEN }}
70
71      - name: Docker Build and Push
72        uses: docker/build-push-action@v2
73        if: success()
74        with:
75          context: .
76          file: ./Dockerfile
77          push: true
78          platforms: ${{ steps.prepare.outputs.docker_platforms }}
79          build-args: |
80            TAG=${{ steps.prepare.outputs.tag }}
81            BRANCH=${{ steps.prepare.outputs.branch }}
82            COMMIT=${{ steps.prepare.outputs.commit }}
83            BUILD_DATE=${{ steps.prepare.outputs.build_date }}
84          tags: |
85            ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.tag }}
86            ghcr.io/${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.tag }}
87          cache-from: type=local,src=/tmp/.buildx-cache
88          cache-to: type=local,dest=/tmp/.buildx-cache
89
90  discord:
91    name: Discord Notification
92    needs: build-docker
93    if: always() && !contains(github.event.head_commit.message, '[skip ci]')
94    runs-on: ubuntu-latest
95    steps:
96      - name: Get Build Job Status
97        uses: technote-space/workflow-conclusion-action@v2.2
98
99      - name: Combine Job Status
100        id: status
101        run: |
102          failures=(neutral, skipped, timed_out, action_required)
103          if [[ ${array[@]} =~ $WORKFLOW_CONCLUSION ]]; then
104            echo ::set-output name=status::failure
105          else
106            echo ::set-output name=status::$WORKFLOW_CONCLUSION
107          fi
108
109      - name: Post Status to Discord
110        uses: sarisia/actions-status-discord@v1
111        with:
112          webhook: ${{ secrets.DISCORD_WEBHOOK }}
113          status: ${{ steps.status.outputs.status }}
114          title: ${{ github.workflow }}
115          nofail: true
116