Skip to content

Commit 03a578c

Browse files
committed
Add initial GitHub Actions CI
1 parent 8d03909 commit 03a578c

File tree

3 files changed

+132
-14
lines changed

3 files changed

+132
-14
lines changed

.github/workflows/generate.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
bashbrewDir="$1"; shift
5+
6+
if [ "$#" -eq 0 ]; then
7+
git fetch --quiet https://github.com/docker-library/official-images.git master
8+
changes="$(git diff --numstat FETCH_HEAD...HEAD -- library/)"
9+
if [ -z "$changes" ]; then
10+
echo '{}'
11+
exit
12+
fi
13+
repos="$(cut -d$'\t' -f3 <<<"$changes")"
14+
repos="$(xargs -n1 basename <<<"$repos")"
15+
set -- $repos
16+
fi
17+
18+
strategy='{}'
19+
for repo; do
20+
newStrategy="$(GITHUB_REPOSITORY="$repo" GENERATE_STACKBREW_LIBRARY='cat "library/$GITHUB_REPOSITORY"' "$bashbrewDir/scripts/github-actions/generate.sh")"
21+
newStrategy="$(jq -c --arg repo "$repo" '.matrix.include = [
22+
.matrix.include[]
23+
| ([ .meta.entries[].tags[0] ]) as $tags
24+
| .name = ($tags | join(", "))
25+
| .runs.prepare += "\ngit clone --depth 1 https://github.com/docker-library/bashbrew.git ~/bashbrew\n~/bashbrew/bashbrew.sh --version"
26+
| .runs.build = (
27+
(if .os | startswith("windows-") then "export BASHBREW_ARCH=windows-amd64 BASHBREW_CONSTRAINTS=" + ([ .meta.entries[].constraints[] ] | join(", ") | @sh) + "\n" else "" end)
28+
+ "export BASHBREW_LIBRARY=\"$PWD/library\"\n"
29+
+ ([ $tags[] | "~/bashbrew/bashbrew.sh build " + @sh ] | join("\n"))
30+
)
31+
]' <<<"$newStrategy")"
32+
jq -c . <<<"$newStrategy" > /dev/null # sanity check
33+
strategy="$(jq -c --argjson strategy "$strategy" '.matrix.include = ($strategy.matrix.include // []) + .matrix.include' <<<"$newStrategy")"
34+
done
35+
jq -c . <<<"$strategy" > /dev/null # sanity check
36+
37+
if [ -t 1 ]; then
38+
jq <<<"$strategy"
39+
else
40+
cat <<<"$strategy"
41+
fi

.github/workflows/test-pr.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Test PR
2+
3+
on:
4+
pull_request:
5+
6+
defaults:
7+
run:
8+
shell: 'bash -Eeuo pipefail -x {0}'
9+
10+
jobs:
11+
12+
diff:
13+
name: Diff
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- id: diff
18+
run: |
19+
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
20+
~/bashbrew/bashbrew.sh --version > /dev/null
21+
export PATH="$HOME/bashbrew/bin:$PATH"
22+
bashbrew --version
23+
diff="$(./diff-pr.sh 0)"
24+
echo "::set-output name=diff::$diff"
25+
- run: |
26+
# TODO add/update ${{ steps.diff.outputs.diff }} as a comment on the PR
27+
cat <<'TODO'
28+
${{ steps.diff.outputs.diff }}
29+
TODO
30+
31+
generate-jobs:
32+
name: Generate Jobs
33+
runs-on: ubuntu-latest
34+
outputs:
35+
strategy: ${{ steps.generate-jobs.outputs.strategy }}
36+
steps:
37+
- uses: actions/checkout@v2
38+
- id: generate-jobs
39+
name: Generate Jobs
40+
run: |
41+
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
42+
strategy="$(.github/workflows/generate.sh ~/bashbrew)"
43+
jq . <<<"$strategy" # sanity check / debugging aid
44+
echo "::set-output name=strategy::$strategy"
45+
46+
test:
47+
needs: generate-jobs
48+
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
49+
name: ${{ matrix.name }}
50+
runs-on: ${{ matrix.os }}
51+
steps:
52+
- uses: actions/checkout@v2
53+
- name: Prepare Environment
54+
run: ${{ matrix.runs.prepare }}
55+
- name: Pull Dependencies
56+
run: ${{ matrix.runs.pull }}
57+
- name: Build ${{ matrix.name }}
58+
run: ${{ matrix.runs.build }}
59+
- name: History ${{ matrix.name }}
60+
run: ${{ matrix.runs.history }}
61+
- name: Test ${{ matrix.name }}
62+
run: ${{ matrix.runs.test }}
63+
- name: '"docker images"'
64+
run: ${{ matrix.runs.images }}

diff-pr.sh

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ shopt -s dotglob
55
# make sure we can GTFO
66
trap 'echo >&2 Ctrl+C captured, exiting; exit 1' SIGINT
77

8+
# if bashbrew is missing, bail early with a sane error
9+
bashbrew --version > /dev/null
10+
811
usage() {
912
cat <<-EOUSAGE
1013
usage: $0 [PR number] [repo[:tag]]
@@ -57,7 +60,8 @@ fi
5760
pull="$1" # PR number
5861
shift
5962

60-
#dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
63+
diffDir="$(readlink -f "$BASH_SOURCE")"
64+
diffDir="$(dirname "$diffDir")"
6165

6266
tempDir="$(mktemp -d)"
6367
trap "rm -rf '$tempDir'" EXIT
@@ -67,12 +71,19 @@ git clone --quiet \
6771
https://github.com/docker-library/official-images.git \
6872
oi
6973

70-
git -C oi fetch --quiet \
71-
origin "pull/$pull/merge":pull
74+
if [ "$pull" != '0' ]; then
75+
git -C oi fetch --quiet \
76+
origin "pull/$pull/merge":refs/heads/pull
77+
else
78+
git -C oi fetch --quiet --update-shallow \
79+
"$diffDir" HEAD:refs/heads/pull
80+
fi
7281

73-
images=( "$@" )
74-
if [ "${#images[@]}" -eq 0 ]; then
75-
images=( $(git -C oi/library diff --name-only HEAD...pull -- . | xargs -n1 basename) )
82+
if [ "$#" -eq 0 ]; then
83+
images="$(git -C oi/library diff --name-only HEAD...pull -- .)"
84+
[ -n "$images" ] || exit 0
85+
images="$(xargs -n1 basename <<<"$images")"
86+
set -- $images
7687
fi
7788

7889
export BASHBREW_CACHE="${BASHBREW_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bashbrew}"
@@ -146,7 +157,8 @@ copy-tar() {
146157

147158
local d dockerfiles=()
148159
for d in "$src"/*/.bashbrew-dockerfile-name; do
149-
local bf="$(< "$d")" dDir="$(dirname "$d")"
160+
local bf; bf="$(< "$d")"
161+
local dDir; dDir="$(dirname "$d")"
150162
dockerfiles+=( "$dDir/$bf" )
151163
if [ "$bf" = 'Dockerfile' ]; then
152164
# if "Dockerfile.builder" exists, let's check that too (busybox, hello-world)
@@ -205,7 +217,8 @@ copy-tar() {
205217
# "find: warning: -path ./xxx/ will not match anything because it ends with /."
206218
local findGlobbedPath="${f%/}"
207219
findGlobbedPath="${findGlobbedPath#./}"
208-
globbed=( $(cd "$dDir" && find -path "./$findGlobbedPath") )
220+
local globbedStr; globbedStr="$(cd "$dDir" && find -path "./$findGlobbedPath")"
221+
local -a globbed=( $globbedStr )
209222
if [ "${#globbed[@]}" -eq 0 ]; then
210223
globbed=( "$f" )
211224
fi
@@ -243,9 +256,9 @@ git -C temp init --quiet
243256
git -C temp config user.name 'Bogus'
244257
git -C temp config user.email 'bogus@bogus'
245258

246-
bashbrew list "${images[@]}" | sort -uV > temp/_bashbrew-list || :
247-
bashbrew cat --format "$archesListTemplate" "${images[@]}" | sort -V > temp/_bashbrew-arches || :
248-
bashbrew cat --format "$sharedTagsListTemplate" "${images[@]}" | grep -vE '^$' | sort -V > temp/_bashbrew-shared-tags || :
259+
bashbrew list "${images[@]}" 2>>temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || :
260+
bashbrew cat --format "$archesListTemplate" "${images[@]}" 2>>temp/_bashbrew.err | sort -V > temp/_bashbrew-arches || :
261+
bashbrew cat --format "$sharedTagsListTemplate" "${images[@]}" 2>>temp/_bashbrew.err | grep -vE '^$' | sort -V > temp/_bashbrew-shared-tags || :
249262
for image in "${images[@]}"; do
250263
if script="$(bashbrew cat -f "$template" "$image")"; then
251264
mkdir tar
@@ -260,9 +273,9 @@ git -C temp commit --quiet --allow-empty -m 'initial' || :
260273
git -C oi checkout --quiet pull
261274

262275
git -C temp rm --quiet -rf . || :
263-
bashbrew list "${images[@]}" | sort -uV > temp/_bashbrew-list || :
264-
bashbrew cat --format "$archesListTemplate" "${images[@]}" | sort -V > temp/_bashbrew-arches || :
265-
bashbrew cat --format "$sharedTagsListTemplate" "${images[@]}" | grep -vE '^$' | sort -V > temp/_bashbrew-shared-tags || :
276+
bashbrew list "${images[@]}" 2>>temp/_bashbrew.err | sort -uV > temp/_bashbrew-list || :
277+
bashbrew cat --format "$archesListTemplate" "${images[@]}" 2>>temp/_bashbrew.err | sort -V > temp/_bashbrew-arches || :
278+
bashbrew cat --format "$sharedTagsListTemplate" "${images[@]}" 2>>temp/_bashbrew.err | grep -vE '^$' | sort -V > temp/_bashbrew-shared-tags || :
266279
script="$(bashbrew cat -f "$template" "${images[@]}")"
267280
mkdir tar
268281
( eval "$script" | tar -xiC tar )

0 commit comments

Comments
 (0)