Skip to content

Commit 5797005

Browse files
authored
Merge pull request #363 from gradle/cobexer/validate-for-upstream-submission
Validate for upstream submission
2 parents 8cf5841 + cf9cf68 commit 5797005

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
indent_size = 4
11+
indent_style = space
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
# Markdown files sometimes need trailing whitespaces.
16+
[*.md]
17+
trim_trailing_whitespace = false
18+
19+
[*.{yml,yaml}]
20+
indent_size = 2
21+
22+
[*.sh]
23+
indent_size = 4
24+
indent_style = tab
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Official Images Updates
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- "master"
8+
- "8"
9+
- "7"
10+
- "6"
11+
pull_request:
12+
13+
permissions: {}
14+
15+
jobs:
16+
library-gradle:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v5
23+
with:
24+
fetch-depth: 0 # we need all branches so we can read Dockerfiles from them
25+
- name: Provision best available generate-stackbrew-library.sh
26+
env:
27+
EVENT_NAME: ${{ github.event_name }}
28+
CURRENT_COMMIT: ${{ github.sha }}
29+
BASE_REF: ${{ github.event.pull_request.base.ref }}
30+
# if the script was modified in the current PR, use that version; otherwise, use the version from master
31+
shell: bash
32+
run: |
33+
if [ "${EVENT_NAME}" == "pull_request" ] && [ "$(git diff --name-only "origin/$BASE_REF..$CURRENT_COMMIT" -- 'generate-stackbrew-library.sh' | wc -l)" -gt 0 ]; then
34+
echo "Using modified generate-stackbrew-library.sh"
35+
else
36+
echo "Using generate-stackbrew-library.sh from master branch"
37+
git checkout origin/master -- generate-stackbrew-library.sh
38+
fi
39+
- name: Generate library file
40+
uses: docker://bash:latest
41+
with:
42+
# See https://github.com/docker-library/bashbrew?tab=readme-ov-file#installing
43+
args: |
44+
-c "\
45+
apk add --no-cache jq git curl ca-certificates && \
46+
git config --global --add safe.directory '*' && \
47+
curl -fsSL -o /usr/local/bin/bashbrew https://github.com/docker-library/bashbrew/releases/download/v0.1.13/bashbrew-amd64 && \
48+
chmod +x /usr/local/bin/bashbrew && \
49+
bashbrew --version && \
50+
./generate-stackbrew-library.sh ${BASE_SHA:+--substitute ${BASE_SHA} ${CURRENT_COMMIT}} > library-gradle \
51+
"
52+
env:
53+
CURRENT_COMMIT: ${{ github.sha }}
54+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
55+
- name: Archive library file
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: gradle
59+
path: library-gradle

generate-stackbrew-library.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ set -o errexit -o nounset -o pipefail
99
jq --version > /dev/null
1010
bashbrew --version > /dev/null
1111

12+
declare -A SUBSTITUTIONS=()
13+
14+
while [[ "$#" -gt 0 ]]; do
15+
case $1 in
16+
--substitute) SUBSTITUTIONS["$2"]="$3"; shift 2 ; echo "WARNING: using substitution, the result can't be submitted to the official images repository" ;;
17+
--help|-h) echo "Usage: ./generate-stackbrew-library.sh [options]
18+
Options:
19+
--substitute <source_sha> <replacement_sha> Substitute <source_sha> with <replacement_sha> during library generation (can be specified multiple times)
20+
--help|-h. Show this help message" >&2; exit 0 ;;
21+
*) echo >&2 "error: unknown argument: $1"; exit 1 ;;
22+
esac
23+
shift
24+
done
25+
1226
branches=(
1327
'master'
1428
'8'
@@ -33,6 +47,10 @@ for branch in "${branches[@]}"; do
3347
esac
3448

3549
commit="$(git rev-parse "refs/remotes/$gitRemote/$branch")"
50+
if [ -v "SUBSTITUTIONS[$commit]" ]; then
51+
commit="${SUBSTITUTIONS[$commit]}"
52+
echo "note: substituting commit $commit for branch $branch" >&2
53+
fi
3654
common="$(
3755
cat <<-EOC
3856
GitFetch: refs/heads/$branch
@@ -108,6 +126,7 @@ for branch in "${branches[@]}"; do
108126

109127
firstVersion=
110128
for dir in "${directories[@]}"; do
129+
echo "branch $branch dir: $dir" >&2
111130
# shellcheck disable=SC2001
112131
dir="$(echo "$dir" | sed -e 's/[[:space:]]*$//')"
113132

@@ -219,6 +238,9 @@ for branch in "${branches[@]}"; do
219238
*)
220239
lts="${fromTag%%-*}"
221240
currentFrom="$(awk <<<"$dockerfile" -F '[=[:space:]]+' 'toupper($1) == "COPY" && $2 == "--from" { print $3; exit }')"
241+
if [ -z "$currentFrom" ]; then # if the current LTS is also the latest Java version, there may be no COPY --from
242+
currentFrom="$from"
243+
fi
222244
currentFromTag="${currentFrom##*:}"
223245
current="${currentFromTag%%-*}"
224246
;;
@@ -251,6 +273,9 @@ for branch in "${branches[@]}"; do
251273
if [ "$jdk" = 'jdk-lts-and-current' ] && [ "$variant" != 'graal' ]; then
252274
# *technically*, we could re-use "currentFrom" that we scraped above, but there's a lot of conditional logic between here and there so it's safer to just re-scrape it
253275
copyFrom="$(awk <<<"$dockerfile" -F '[=[:space:]]+' 'toupper($1) == "COPY" && $2 == "--from" { print $3; exit }')"
276+
if [ -z "$copyFrom" ]; then # if the current LTS is also the latest Java version, there may be no COPY --from
277+
copyFrom="$from"
278+
fi
254279
copyFromArches="${archesLookupCache[$copyFrom]:-}"
255280
if [ -z "$copyFromArches" ]; then
256281
copyFromArches="$(bashbrew cat --format '{{ join ", " .TagEntry.Architectures }}' "https://github.com/docker-library/official-images/raw/HEAD/library/$copyFrom")"

0 commit comments

Comments
 (0)