Skip to content

Commit cd85920

Browse files
author
Oleg
committed
Try extract version from latest and current version and prepare a the tag when needed
1 parent ea9853a commit cd85920

File tree

1 file changed

+49
-58
lines changed

1 file changed

+49
-58
lines changed

.github/workflows/build.yml

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@ name: Rebuild Bowtie Image
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: >
8-
A specific version of the implementation you want to build.
9-
10-
If the implementation has historical version support (i.e. a `matrix-versions.json` file)
11-
and your specified version is included in that file then only that version of the implementation
12-
will be built and if you don't specify any version over here then all of its versions from that
13-
file will be built.
14-
15-
If no file is found then just the latest version of the implementation will be built.
16-
required: false
17-
type: string
185
pull_request:
196
push:
207
branches-ignore:
@@ -28,10 +15,11 @@ concurrency:
2815
cancel-in-progress: true
2916

3017
jobs:
31-
list:
18+
meta:
3219
runs-on: ubuntu-latest
3320
outputs:
34-
images: ${{ steps.images-matrix.outputs.images }}
21+
latest-version: ${{ steps.version.outputs.value }}
22+
implementation-name: ${{ steps.impl.outputs.name }}
3523
steps:
3624
- uses: actions/checkout@v4
3725

@@ -40,56 +28,35 @@ jobs:
4028
with:
4129
enable-cache: true
4230

43-
- name: Calculate which impages to build
44-
id: images-matrix
31+
- name: Compute implementation name
32+
id: impl
33+
run: echo "name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT
34+
35+
- name: Compute latest implementation version
36+
id: version
4537
run: |
46-
version=${{ inputs.version }}
47-
matrix_versions_file="matrix-versions.json"
48-
MATRIX="[]"
49-
if [ -f "$matrix_versions_file" ]; then
50-
versions=$(cat "$matrix_versions_file" | jq -c)
51-
if [ -n "$version" ]; then
52-
if echo "$versions" | jq -e --arg version "$version" 'index($version) != null' > /dev/null; then
53-
MATRIX="[{"version": $version}]"
54-
else
55-
echo "No such version ('$version') found in the \`matrix-versions.json\` file of $implementation. Please provide a correct version."
56-
exit 1
57-
fi
58-
else
59-
MATRIX=$(jq --argjson vers "$versions" '["version": $vers[]}]')
60-
fi
61-
else
62-
MATRIX='[{"version": "latest"}]'
63-
fi
64-
echo "images=$(echo $MATRIX | jq -c .)" >> $GITHUB_OUTPUT
38+
version=$(uvx --from 'bowtie-json-schema' --python 3.13 bowtie info \
39+
--implementation ${{ steps.impl.outputs.name }} \
40+
--format json | jq '.version // empty')
41+
echo "value=${version}" >> $GITHUB_OUTPUT
6542
6643
build:
67-
needs: list
44+
needs: meta
6845

69-
# Particularly for .NET (which we special case below),
70-
# we need a newer buildah than what's in 22.04 (which is buildah 1.23.1)
71-
# so that it properly sets TARGETARCH and therefore multi-architecture
72-
# container image builds know which architecture we're building for.
73-
# See https://github.com/containers/buildah/pull/4295.
74-
runs-on: ubuntu-24.04
46+
runs-on: ubuntu-latest
47+
48+
outputs:
49+
current-version: ${{ steps.current-version.outputs.value }}
7550

7651
permissions:
7752
id-token: write
7853
contents: read
7954
attestations: write
8055
packages: write
8156

82-
strategy:
83-
fail-fast: false
84-
matrix:
85-
include: ${{ fromJson(needs.list.outputs.images) }}
86-
8757
steps:
8858
- uses: actions/checkout@v4
8959

90-
- run: echo "name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT
91-
id: impl
92-
9360
- name: Install qemu
9461
run: |
9562
sudo apt-get update
@@ -102,11 +69,9 @@ jobs:
10269
context: '.'
10370
containerfiles: |
10471
Dockerfile
105-
image: ${{ steps.impl.outputs.name }}
106-
tags: ${{ matrix.version }} ${{ github.sha }}
72+
image: ${{ needs.meta.outputs.implementation-name }}
73+
tags: ${{ github.sha }}
10774
archs: amd64, arm64
108-
build-args: |
109-
${{ format('IMPLEMENTATION_VERSION={0}', matrix.version) }}
11075

11176
- name: Set DOCKER_HOST so podman-built images are findable
11277
run: |
@@ -125,6 +90,14 @@ jobs:
12590
uvx --from 'bowtie-json-schema' --python 3.13 bowtie smoke -i "localhost/${{ steps.build_image.outputs.image-with-tag }}" --format json
12691
uvx --from 'bowtie-json-schema' --python 3.13 bowtie smoke -i "localhost/${{ steps.build_image.outputs.image-with-tag }}" --format markdown >> $GITHUB_STEP_SUMMARY
12792
93+
- name: Collect current version
94+
id: current-version
95+
run: |
96+
version=$(uvx --from 'bowtie-json-schema' --python 3.13 bowtie info \
97+
--implementation "localhost/${{ steps.build_image.outputs.image-with-tag }}" \
98+
--format json | jq '.version // empty')
99+
echo "value=${version}" >> $GITHUB_OUTPUT
100+
128101
- name: Log in to ghcr.io
129102
uses: redhat-actions/podman-login@v1
130103
with:
@@ -138,7 +111,7 @@ jobs:
138111
uses: redhat-actions/push-to-registry@v2
139112
with:
140113
image: ${{ steps.build_image.outputs.image }}
141-
tags: ${{ steps.build_image.outputs.tags }}
114+
tags: ${{ steps.current-version.outputs.value }} ${{ github.sha }} ${{ github.ref == 'refs/heads/main' && 'latest' || '' }}
142115
registry: ${{ env.IMAGE_REGISTRY }}
143116
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
144117

@@ -150,11 +123,29 @@ jobs:
150123
push-to-registry: true
151124
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
152125

126+
version-changed:
127+
needs: [build, meta]
128+
runs-on: ubuntu-latest
129+
130+
if: github.event_name == 'pull_request' && needs.build.outputs.current-version != needs.meta.outputs.latest-version
131+
132+
permissions:
133+
contents: write
134+
135+
steps:
136+
- name: Checkout current head
137+
uses: actions/checkout@v4
138+
with:
139+
ref: ${{ github.event.pull_request.base.ref }}
140+
141+
- name: Mark the current head with the latest version before the update
142+
run: git tag v${{ needs.build.outputs.current-version }} && git push origin v${{ needs.build.outputs.current-version }}
143+
153144
automerge:
154-
needs: build
145+
needs: [build, version-changed]
155146
runs-on: ubuntu-latest
156147

157-
if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]'
148+
if: (!cancelled() && github.event_name == 'pull_request' && github.actor == 'dependabot[bot]')
158149

159150
permissions:
160151
contents: write

0 commit comments

Comments
 (0)