summaryrefslogtreecommitdiffstats
path: root/.github/workflows/publish-docker.yml
blob: 092b6b3e972d043d585614d4071a52929b4ec3bd (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
name: Publish Docker
run-name: "Publish Docker (gitlint_version=${{ inputs.gitlint_version }})"

on:
  workflow_call:
    inputs:
      gitlint_version:
        description: "Gitlint version to build docker image for"
        required: true
        type: string
      docker_image_tag:
        description: "Docker image tag"
        required: true
        type: string
      push_to_dockerhub:
        description: "Push to dockerhub.com"
        required: false
        type: boolean
        default: false
  workflow_dispatch:
    inputs:
      gitlint_version:
        description: "Gitlint version to build docker image for"
        type: string
      docker_image_tag:
        description: "Docker image tag"
        required: true
        type: choice
        options:
          - "latest_dev"
          - "latest"
          - "Use $gitlint_version"
        default: "Use $gitlint_version"
      push_to_dockerhub:
        description: "Push to dockerhub.com"
        required: false
        type: boolean
        default: false

jobs:
  publish_docker:
    runs-on: "ubuntu-latest"
    steps:
      - name: Determine docker tag
        id: set_tag
        run: |
          if [[ "${{ inputs.docker_image_tag }}" == "Use $gitlint_version" ]]; then
            echo "docker_image_tag=${{ inputs.gitlint_version }}" >> $GITHUB_OUTPUT
          else
            echo "docker_image_tag=${{ inputs.docker_image_tag }}" >> $GITHUB_OUTPUT
          fi

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: jorisroovers
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build docker image
        uses: docker/build-push-action@v4
        with:
          build-args: GITLINT_VERSION=${{ inputs.gitlint_version }}
          tags: jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }}

      - name: Test docker image
        run: |
          gitlint_version=$(docker run --ulimit nofile=1024 -v $(pwd):/repo jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }} --version)
          [ "$gitlint_version" == "gitlint, version ${{ inputs.gitlint_version }}" ]


      # This won't actually rebuild the docker image, but just push the previously built and cached image
      - name: Push docker image
        uses: docker/build-push-action@v4
        with:
          push: ${{ inputs.push_to_dockerhub }}
          build-args: GITLINT_VERSION=${{ inputs.gitlint_version }}
          tags: jorisroovers/gitlint:${{ steps.set_tag.outputs.docker_image_tag }}
        if: inputs.push_to_dockerhub