Skip to content

Commit 872e603

Browse files
committed
Add initial GitHub Actions CI
1 parent 8d03909 commit 872e603

File tree

8 files changed

+254
-132
lines changed

8 files changed

+254
-132
lines changed

.github/workflows/generate.sh

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

.github/workflows/naughty.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
if [ "$#" -eq 0 ]; then
5+
changes="$(.github/workflows/pr-changed-files.sh library/)"
6+
repos="$(xargs -rn1 basename <<<"$changes")"
7+
set -- $repos
8+
fi
9+
10+
if [ "$#" -eq 0 ]; then
11+
echo >&2 'No changes detected, skipping.'
12+
exit
13+
fi
14+
15+
export BASHBREW_LIBRARY="$PWD/library"
16+
17+
bashbrew from --uniq "$@" > /dev/null
18+
19+
if badTags="$(bashbrew list "$@" | grep -E ':.+latest.*|:.*latest.+')" && [ -n "$badTags" ]; then
20+
echo >&2
21+
echo >&2 "Incorrectly formatted 'latest' tags detected:"
22+
echo >&2 ' ' $badTags
23+
echo >&2
24+
echo >&2 'Read https://github.com/docker-library/official-images#tags-and-aliases for more details.'
25+
echo >&2
26+
exit 1
27+
fi
28+
29+
naughtyFrom="$(./naughty-from.sh "$@")"
30+
if [ -n "$naughtyFrom" ]; then
31+
echo >&2
32+
echo >&2 "Invalid 'FROM' + 'Architectures' combinations detected:"
33+
echo >&2
34+
echo >&2 "$naughtyFrom"
35+
echo >&2
36+
echo >&2 'Read https://github.com/docker-library/official-images#multiple-architectures for more details.'
37+
echo >&2
38+
exit 1
39+
fi
40+
41+
naughtyConstraints="$(./naughty-constraints.sh "$@")"
42+
if [ -n "$naughtyConstraints" ]; then
43+
echo >&2
44+
echo >&2 "Invalid 'FROM' + 'Constraints' combinations detected:"
45+
echo >&2
46+
echo >&2 "$naughtyConstraints"
47+
echo >&2
48+
exit 1
49+
fi
50+
51+
naughtyCommits="$(./naughty-commits.sh "$@")"
52+
if [ -n "$naughtyCommits" ]; then
53+
echo >&2
54+
echo >&2 "Unpleasant commits detected:"
55+
echo >&2
56+
echo >&2 "$naughtyCommits"
57+
echo >&2
58+
exit 1
59+
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
git fetch --quiet https://github.com/docker-library/official-images.git master
5+
git diff --numstat FETCH_HEAD...HEAD -- "$@" | cut -d$'\t' -f3-

.github/workflows/test-pr.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
naughty:
13+
name: Naughty
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- run: |
18+
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
19+
~/bashbrew/bashbrew.sh --version > /dev/null
20+
export PATH="$HOME/bashbrew/bin:$PATH"
21+
bashbrew --version
22+
.github/workflows/naughty.sh
23+
24+
label:
25+
name: Label
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v2
29+
- id: labels
30+
name: Generate List
31+
run: |
32+
labels="$(.github/workflows/pr-changed-files.sh library/)"
33+
labels="$(jq -Rsc 'rtrimstr("\n") | split("\n") as $labels | { labels: $labels, count: ($labels | length) }' <<<"$labels")"
34+
jq . <<<"$labels"
35+
echo "::set-output name=labels::$labels"
36+
# TODO add the "new-image" label as appropriate
37+
- name: Apply Labels
38+
uses: actions/github-script@0.9.0
39+
with:
40+
script: |
41+
const data = ${{ steps.labels.outputs.labels }}
42+
github.issues.addLabels({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
issue_number: context.payload.pull_request.number,
46+
labels: data.labels,
47+
})
48+
if: fromJSON(steps.labels.outputs.labels).count > 0
49+
50+
diff:
51+
name: Diff
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v2
55+
- id: diff
56+
name: Run ./diff-pr.sh
57+
run: |
58+
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
59+
~/bashbrew/bashbrew.sh --version > /dev/null
60+
export PATH="$HOME/bashbrew/bin:$PATH"
61+
bashbrew --version
62+
diff="$(./diff-pr.sh 0)"
63+
# "Body is too long (maximum is 65536 characters)" (so we'll check for some fudge room and pre-filter the diff)
64+
diff="$(jq -Rcs 'rtrimstr("\n") | { diff: (if length < 65000 then . else "TODO diff too large for GitHub comment!" end), length: length }' <<<"$diff")"
65+
echo "::set-output name=diff::$diff"
66+
- name: Comment
67+
uses: actions/github-script@0.9.0
68+
with:
69+
script: |
70+
const data = ${{ steps.diff.outputs.diff }}
71+
const body = "<details>\n<summary>Diff for " + context.payload.pull_request.head.sha + ":</summary>\n\n```diff\n" + data.diff + "\n```\n\n</details>"
72+
const { data: comments } = await github.issues.listComments({
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
issue_number: context.payload.pull_request.number,
76+
})
77+
comments.forEach((comment) => {
78+
if (comment.user.login === 'github-actions[bot]') {
79+
github.issues.deleteComment({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
comment_id: comment.id,
83+
})
84+
}
85+
})
86+
github.issues.createComment({
87+
owner: context.repo.owner,
88+
repo: context.repo.repo,
89+
issue_number: context.payload.pull_request.number,
90+
body: body,
91+
})
92+
if: fromJSON(steps.diff.outputs.diff).length > 0
93+
# TODO delete comments even if we don't have a diff so that if we go from accidental diff to no diff it deletes the comment appropriately?
94+
95+
generate-jobs:
96+
name: Generate Jobs
97+
runs-on: ubuntu-latest
98+
outputs:
99+
strategy: ${{ steps.generate-jobs.outputs.strategy }}
100+
steps:
101+
- uses: actions/checkout@v2
102+
- id: generate-jobs
103+
name: Generate Jobs
104+
run: |
105+
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
106+
strategy="$(.github/workflows/generate.sh ~/bashbrew)"
107+
jq . <<<"$strategy" # sanity check / debugging aid
108+
echo "::set-output name=strategy::$strategy"
109+
110+
test:
111+
needs: generate-jobs
112+
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
113+
name: ${{ matrix.name }}
114+
runs-on: ${{ matrix.os }}
115+
steps:
116+
- uses: actions/checkout@v2
117+
- name: Prepare Environment
118+
run: ${{ matrix.runs.prepare }}
119+
- name: Pull Dependencies
120+
run: ${{ matrix.runs.pull }}
121+
- name: Build ${{ matrix.name }}
122+
run: ${{ matrix.runs.build }}
123+
- name: History ${{ matrix.name }}
124+
run: ${{ matrix.runs.history }}
125+
- name: Test ${{ matrix.name }}
126+
run: ${{ matrix.runs.test }}
127+
- name: '"docker images"'
128+
run: ${{ matrix.runs.images }}

.travis.sh

Lines changed: 0 additions & 101 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Docker Official Images
22

3-
[![Build Status](https://travis-ci.org/docker-library/official-images.svg?branch=master)](https://travis-ci.org/docker-library/official-images)
4-
53
## Table of Contents
64

75
<!-- AUTOGENERATED TOC -->

0 commit comments

Comments
 (0)