-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (73 loc) · 2.45 KB
/
Copy pathruby.yml
File metadata and controls
82 lines (73 loc) · 2.45 KB
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
name: Ruby
on:
push:
branches: [main]
paths:
- ruby/Dockerfile
- .github/workflows/ruby.yml
pull_request:
paths:
- ruby/Dockerfile
- .github/workflows/ruby.yml
workflow_dispatch:
inputs:
force:
description: Rebuild all images
type: boolean
default: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/ruby
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
ruby-version:
- "3.3.10"
- "3.4.8"
- "3.4.9"
- "4.0.1"
- "4.0.2"
steps:
- uses: actions/checkout@v6
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- name: Check if Dockerfile changed
id: dockerfile
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
else
BASE="${{ github.event.before }}"
fi
if git diff --name-only "$BASE" "${{ github.sha }}" -- ruby/Dockerfile | grep -q .; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Check if image exists
id: check
run: |
if docker buildx imagetools inspect "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ruby-version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- uses: docker/login-action@v4
if: github.event_name != 'pull_request' && (steps.check.outputs.exists != 'true' || steps.dockerfile.outputs.changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.force))
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v7
if: steps.check.outputs.exists != 'true' || steps.dockerfile.outputs.changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.force)
with:
context: ruby
platforms: linux/amd64,linux/arm64
build-args: RUBY_VERSION=${{ matrix.ruby-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ruby-version }}