Skip to content

Commit 9205000

Browse files
authored
Merge pull request #7937 from docker-library/github-actions
Add initial GitHub Actions CI
2 parents d112ff9 + 39cc4e2 commit 9205000

File tree

8 files changed

+277
-132
lines changed

8 files changed

+277
-132
lines changed

.github/workflows/generate.sh

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

.github/workflows/naughty.sh

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

.github/workflows/pr-labels.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
git fetch --quiet https://github.com/docker-library/official-images.git master
5+
6+
changes="$(git diff --numstat FETCH_HEAD...HEAD -- library/ | cut -d$'\t' -f3-)"
7+
set -- $changes
8+
9+
if [ "$#" -eq 0 ]; then
10+
echo >&2 'No library/ changes detected, skipping labels.'
11+
exit
12+
fi
13+
14+
if newImages="$(git diff --name-only --diff-filter=A FETCH_HEAD...HEAD -- "$@")" && [ -n "$newImages" ]; then
15+
echo >&2
16+
echo >&2 "NEW IMAGES: $newImages"
17+
echo >&2
18+
set -- "$@" 'new-image'
19+
fi
20+
21+
IFS=$'\n'
22+
echo "$*"

.github/workflows/test-pr.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
- name: Check for Common Issues
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+
.github/workflows/naughty.sh
24+
25+
label:
26+
name: Label
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
- id: labels
31+
name: Generate List
32+
run: |
33+
labels="$(.github/workflows/pr-labels.sh)"
34+
labels="$(jq -Rsc 'rtrimstr("\n") | split("\n") | { labels: ., count: length }' <<<"$labels")"
35+
jq . <<<"$labels"
36+
echo "::set-output name=labels::$labels"
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+
# TODO consider instead creating a Gist (although that requires a separate type of token, so much less interesting)
65+
diff="$(jq -Rcs 'rtrimstr("\n") | { diff: (if length < 65000 then . else "TODO diff too large for GitHub comment!\nSee: http://github.com/" + env.GITHUB_REPOSITORY + "/actions/runs/" + env.GITHUB_RUN_ID end), length: length }' <<<"$diff")"
66+
echo "::set-output name=diff::$diff"
67+
- name: Delete Old Comments
68+
uses: actions/github-script@0.9.0
69+
with:
70+
script: |
71+
const { data: comments } = await github.issues.listComments({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
issue_number: context.payload.pull_request.number,
75+
})
76+
comments.forEach((comment) => {
77+
if (comment.user.login === 'github-actions[bot]') {
78+
github.issues.deleteComment({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
comment_id: comment.id,
82+
})
83+
}
84+
})
85+
- name: Create Diff Comment
86+
uses: actions/github-script@0.9.0
87+
with:
88+
script: |
89+
const data = ${{ steps.diff.outputs.diff }}
90+
const body = "<details>\n<summary>Diff for " + context.payload.pull_request.head.sha + ":</summary>\n\n```diff\n" + data.diff + "\n```\n\n</details>"
91+
github.issues.createComment({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
issue_number: context.payload.pull_request.number,
95+
body: body,
96+
})
97+
if: fromJSON(steps.diff.outputs.diff).length > 0
98+
99+
generate-jobs:
100+
name: Generate Jobs
101+
runs-on: ubuntu-latest
102+
outputs:
103+
strategy: ${{ steps.generate-jobs.outputs.strategy }}
104+
steps:
105+
- uses: actions/checkout@v2
106+
- id: generate-jobs
107+
name: Generate Jobs
108+
run: |
109+
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
110+
strategy="$(.github/workflows/generate.sh ~/bashbrew)"
111+
jq . <<<"$strategy" # sanity check / debugging aid
112+
echo "::set-output name=strategy::$strategy"
113+
114+
test:
115+
needs: generate-jobs
116+
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
117+
name: ${{ matrix.name }}
118+
runs-on: ${{ matrix.os }}
119+
steps:
120+
- uses: actions/checkout@v2
121+
- name: Prepare Environment
122+
run: ${{ matrix.runs.prepare }}
123+
- name: Pull Dependencies
124+
run: ${{ matrix.runs.pull }}
125+
- name: Build ${{ matrix.name }}
126+
run: ${{ matrix.runs.build }}
127+
- name: History ${{ matrix.name }}
128+
run: ${{ matrix.runs.history }}
129+
- name: Test ${{ matrix.name }}
130+
run: ${{ matrix.runs.test }}
131+
- name: '"docker images"'
132+
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)