summaryrefslogtreecommitdiff
path: root/.github/workflows/publish.yml
blob: 1a5e19e227400d36c50b4e5934a7ce44f5fb5a3b (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
113
name: Publish

on:
  push:
    branches: [main]
    paths-ignore:
    - '.github/**'
    - '.vscode/**'
    - 'tests/**'
    - '.*'
    - '*.*-dist'
    - '*.js'
    - '*.json'
    - '*.lock'
    - '*.md'
    - '*.neon'
    - '*.xml'
  # Allow manual triggering
  workflow_dispatch:


permissions:
  contents: read


jobs:
  test-docker:
    uses: ./.github/workflows/docker-code-quality.yml

  test-php:
    uses: ./.github/workflows/php-code-quality.yml

  publish:
    name: Publish Docker image ${{ matrix.image.name }}
    needs:
    - test-docker
    - test-php
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    strategy:
      matrix:
        image:
        - name: app
          dockerfile: ./.docker/app/Dockerfile
          repository_dockerhub: supahgreg/tt-rss
          repository_ghcr: ghcr.io/tt-rss/tt-rss
        - name: web-nginx
          dockerfile: ./.docker/web-nginx/Dockerfile
          repository_dockerhub: supahgreg/tt-rss-web-nginx
          repository_ghcr: ghcr.io/tt-rss/tt-rss-web-nginx

    steps:
    - name: Check out code
      uses: actions/checkout@v5

    - name: Get commit timestamp
      run: echo "COMMIT_TIMESTAMP=$(git show -s --format=%ci HEAD)" >> $GITHUB_ENV

    - name: Get commit short SHA
      run: echo "COMMIT_SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

    - name: Log in to GitHub Container Registry
      uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: Log in to Docker Hub
      uses: docker/login-action@v3
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}

    - name: Extract metadata
      id: meta
      uses: docker/metadata-action@v5
      with:
        images: |
          ${{ matrix.image.repository_dockerhub }}
          ${{ matrix.image.repository_ghcr }}
        tags: |
          # update 'latest'
          type=raw,value=latest
          # short SHA with a 'sha-' prefix (e.g. sha-abc123)
          type=sha

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

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

    - name: Build and push to image registries
      id: push
      uses: docker/build-push-action@v6
      with:
        context: .
        file: ${{ matrix.image.dockerfile }}
        platforms: linux/arm64,linux/amd64
        # TODO: clean up build arg and environment variable naming.
        build-args: |
          CI_COMMIT_BRANCH=${{ github.ref_name }}
          CI_COMMIT_SHA=${{ github.sha }}
          CI_COMMIT_SHORT_SHA=${{ env.COMMIT_SHORT_SHA }}
          CI_COMMIT_TIMESTAMP=${{ env.COMMIT_TIMESTAMP }}
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}
        provenance: true
        sbom: true
        push: true