Skip to content

Commit 5525d02

Browse files
authored
Merge pull request #71 from ruby/rewrite-multiarch
Rewrite multiarch workflow with matrix build
2 parents e9b0880 + 81b3eac commit 5525d02

1 file changed

Lines changed: 34 additions & 89 deletions

File tree

.github/workflows/build_multiarch.yml

Lines changed: 34 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ env:
2222

2323
jobs:
2424
build_amd64:
25-
if: "${{ inputs.ruby_version }} && !'nightly' == ${{ inputs.ruby_version }}"
25+
strategy:
26+
matrix:
27+
dev_suffix: [ '', '-dev' ]
2628

2729
runs-on: ubuntu-latest
2830

@@ -36,7 +38,7 @@ jobs:
3638
push_tags: |
3739
${{ inputs.ruby_version }}-${{ inputs.ubuntu_version }}-amd64-${{ github.sha }}
3840
${{ inputs.ruby_version }}-dev-${{ inputs.ubuntu_version }}-amd64-${{ github.sha }}
39-
dev_suffix: "-dev"
41+
dev_suffix: ${{ matrix.dev_suffix }}
4042
only_development: false
4143
optflags: ''
4244
cppflags: ''
@@ -45,24 +47,25 @@ jobs:
4547
steps:
4648
- uses: actions/checkout@v4.1.0
4749

48-
- uses: "./.github/actions/build_image"
49-
if: "!${{ env.only_development }}"
50-
with:
51-
ruby_version: "${{ env.ruby_version }}"
52-
nightly: "${{ env.nightly }}"
53-
image_version_suffix: "${{ env.image_version_suffix }}"
54-
ubuntu_version: "${{ env.ubuntu_version }}"
55-
tag_suffix: "${{ env.tag_suffix }}"
56-
latest_tag: 'true'
50+
- run: |
51+
if [ "${{ env.dev_suffix }}" = "-dev" ]; then
52+
echo "target=development" >> $GITHUB_ENV
53+
echo "latest_tag=false" >> $GITHUB_ENV
54+
else
55+
echo "target=ruby" >> $GITHUB_ENV
56+
echo "latest_tag=true" >> $GITHUB_ENV
57+
fi
5758
5859
- uses: "./.github/actions/build_image"
60+
if: "!${{ env.only_development }}"
5961
with:
6062
ruby_version: "${{ env.ruby_version }}"
6163
nightly: "${{ env.nightly }}"
6264
image_version_suffix: "${{ env.image_version_suffix }}${{ env.dev_suffix }}"
6365
ubuntu_version: "${{ env.ubuntu_version }}"
6466
tag_suffix: "${{ env.tag_suffix }}"
65-
target: development
67+
latest_tag: ${{ env.latest_tag }}
68+
target: ${{ env.target }}
6669

6770
- uses: "./.github/actions/push_image"
6871
if: "${{ env.push }}"
@@ -79,7 +82,9 @@ jobs:
7982
push_tags: "${{ env.push_tags }}"
8083

8184
build_arm64:
82-
if: "${{ inputs.ruby_version }} && !'nightly' == ${{ inputs.ruby_version }}"
85+
strategy:
86+
matrix:
87+
dev_suffix: [ '', '-dev' ]
8388

8489
runs-on: ubuntu-latest
8590

@@ -93,7 +98,7 @@ jobs:
9398
push_tags: |
9499
${{ inputs.ruby_version }}-${{ inputs.ubuntu_version }}-arm64-${{ github.sha }}
95100
${{ inputs.ruby_version }}-dev-${{ inputs.ubuntu_version }}-arm64-${{ github.sha }}
96-
dev_suffix: "-dev"
101+
dev_suffix: ${{ matrix.dev_suffix }}
97102
only_development: false
98103
optflags: ''
99104
cppflags: ''
@@ -102,26 +107,26 @@ jobs:
102107
steps:
103108
- uses: actions/checkout@v4.1.0
104109

105-
- uses: "./.github/actions/build_image"
106-
if: "!${{ env.only_development }}"
107-
with:
108-
ruby_version: "${{ env.ruby_version }}"
109-
nightly: "${{ env.nightly }}"
110-
image_version_suffix: "${{ env.image_version_suffix }}"
111-
ubuntu_version: "${{ env.ubuntu_version }}"
112-
tag_suffix: "${{ env.tag_suffix }}"
113-
arch: 'linux/arm64'
114-
latest_tag: 'true'
110+
- run: |
111+
if [ "${{ env.dev_suffix }}" = "-dev" ]; then
112+
echo "target=development" >> $GITHUB_ENV
113+
echo "latest_tag=false" >> $GITHUB_ENV
114+
else
115+
echo "target=ruby" >> $GITHUB_ENV
116+
echo "latest_tag=true" >> $GITHUB_ENV
117+
fi
115118
116119
- uses: "./.github/actions/build_image"
120+
if: "!${{ env.only_development }}"
117121
with:
118122
ruby_version: "${{ env.ruby_version }}"
119123
nightly: "${{ env.nightly }}"
120124
image_version_suffix: "${{ env.image_version_suffix }}${{ env.dev_suffix }}"
121125
ubuntu_version: "${{ env.ubuntu_version }}"
122126
tag_suffix: "${{ env.tag_suffix }}"
123127
arch: 'linux/arm64'
124-
target: development
128+
latest_tag: ${{ env.latest_tag }}
129+
target: ${{ env.target }}
125130

126131
- uses: "./.github/actions/push_image"
127132
if: "${{ env.push }}"
@@ -138,69 +143,9 @@ jobs:
138143
push_tags: "${{ env.push_tags }}"
139144

140145
deploy_multiarch:
141-
if: "${{ inputs.ruby_version }} && !'nightly' == ${{ inputs.ruby_version }}"
142-
143-
runs-on: ubuntu-latest
144-
145-
needs:
146-
- build_amd64
147-
- build_arm64
148-
149-
env:
150-
ruby_version: "${{ inputs.ruby_version }}"
151-
ubuntu_version: "${{ inputs.ubuntu_version }}"
152-
registry_name: rubylang
153-
154-
steps:
155-
- uses: actions/checkout@v4.1.0
156-
157-
- name: Login to ${{ env.registry_name }}
158-
run: |-
159-
case x"${{ env.registry_name }}" in
160-
xrubylang)
161-
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
162-
;;
163-
xghcr.io/ruby)
164-
echo $GHCR_ACCESS_TOKEN | docker login ghcr.io -u $GHCR_USER --password-stdin
165-
;;
166-
*)
167-
echo "ERROR: Unknown registry_name parameter: $registry_name" >&2
168-
exit 1
169-
;;
170-
esac
171-
172-
- name: Create manifest for ${{ env.registry_name }}
173-
run: |-
174-
rake docker:manifest:create \
175-
registry_name="${{ env.registry_name }}" \
176-
ruby_version="${{ env.ruby_version }}" \
177-
ubuntu_version="${{ env.ubuntu_version }}" \
178-
architectures="amd64 arm64" \
179-
manifest_suffix=${{ github.sha }} \
180-
latest_tag=true
181-
rake docker:manifest:create \
182-
registry_name="${{ env.registry_name }}" \
183-
ruby_version="${{ env.ruby_version }}" \
184-
ubuntu_version="${{ env.ubuntu_version }}" \
185-
architectures="amd64 arm64" \
186-
image_version_suffix=-dev \
187-
manifest_suffix=${{ github.sha }}
188-
189-
- name: Push manifest to ${{ env.registry_name }}
190-
run: |-
191-
rake docker:manifest:push \
192-
registry_name="${{ env.registry_name }}" \
193-
ruby_version="${{ env.ruby_version }}" \
194-
ubuntu_version="${{ env.ubuntu_version }}" \
195-
latest_tag=true
196-
rake docker:manifest:push \
197-
registry_name="${{ env.registry_name }}" \
198-
ruby_version="${{ env.ruby_version }}" \
199-
ubuntu_version="${{ env.ubuntu_version }}" \
200-
image_version_suffix=-dev
201-
202-
deploy_multiarch_ghcr:
203-
if: "${{ inputs.ruby_version }} && !'nightly' == ${{ inputs.ruby_version }}"
146+
strategy:
147+
matrix:
148+
registry_name: [ rubylang, ghcr.io/ruby ]
204149

205150
runs-on: ubuntu-latest
206151

@@ -211,7 +156,7 @@ jobs:
211156
env:
212157
ruby_version: "${{ inputs.ruby_version }}"
213158
ubuntu_version: "${{ inputs.ubuntu_version }}"
214-
registry_name: ghcr.io/ruby
159+
registry_name: "${{ matrix.registry_name }}"
215160

216161
steps:
217162
- uses: actions/checkout@v4.1.0

0 commit comments

Comments
 (0)