aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/publish.yml
blob: d3fed5e7eb59994349c5a1306e25a4094a33db0e (plain)
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
name: Make release & publish Docker image

on:
  push:
    tags:
    - 'v*'

jobs:
  publish:
    strategy:
      matrix:
        runner-platform:
          - ubuntu-latest
          - self-hosted
        include:
          - runner-platform: ubuntu-latest
            build-arch: linux/amd64
            tagged-platform: amd64
          - runner-platform: self-hosted
            build-arch: linux/arm64
            tagged-platform: arm64
    runs-on: ${{ matrix.runner-platform }}
    steps:
      - name: Set up Buildx
        uses: docker/setup-buildx-action@v1

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

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

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: codetheweb/muse:${{ github.sha }}-${{ matrix.tagged-platform }}
          platforms: ${{ matrix.build-arch }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache,mode=min

  combine:
    name: Combine platform tags
    runs-on: ubuntu-latest
    needs: publish
    steps:
      - uses: actions/checkout@v1

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

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

      - name: Get tags
        id: get-tags
        uses: Surgo/docker-smart-tag-action@v1
        with:
          docker_image: codetheweb/muse

      - name: Combine tags
        run: docker buildx imagetools create $(echo '${{ steps.get-tags.outputs.tag }}' | tr "," "\0" | xargs -0 printf -- '-t %s ') 'codetheweb/muse:${{ github.sha }}-arm64' 'codetheweb/muse:${{ github.sha }}-amd64'

      - name: Update Docker Hub description
        uses: peter-evans/[email protected]
        env:
          DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
          DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
          DOCKERHUB_REPOSITORY: codetheweb/muse

  release:
    name: Create GitHub release
    runs-on: ubuntu-latest
    needs: combine
    steps:
      - uses: actions/checkout@v2

      - name: Get version from tag
        id: tag_name
        run: |
          echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
        shell: bash

      - name: Get Changelog Entry
        id: changelog_reader
        uses: mindsers/changelog-reader-action@v2
        with:
          version: ${{ steps.tag_name.outputs.current_version }}
          path: ./CHANGELOG.md

      - name: Create/update release
        uses: ncipollo/release-action@v1
        with:
          tag: v${{ steps.changelog_reader.outputs.version }}
          name: Release v${{ steps.changelog_reader.outputs.version }}
          body: ${{ steps.changelog_reader.outputs.changes }}
          prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }}
          draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }}
          allowUpdates: true
          token: ${{ secrets.GH_PAT }}