Skip to content

Commit

Permalink
Update bashbrew to 0.1.5 (and use the new bashbrew action)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Nov 17, 2022
1 parent c4baf2d commit 440ac1a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 250 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/.bashbrew/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://github.com/docker-library/official-images/pull/13556#issuecomment-1319181339 🙈
name: 'Shared Bashbrew Action'
description: 'Install the same version of Bashbrew consistently in all other GitHub Actions'
inputs:
build:
default: 'host' # or 'docker' or 'none'
runs:
using: 'composite'
steps:

# these two version numbers are intentionally as close together as I could possibly get them because no matter what I tried, GitHub will not allow me to DRY them (can't have any useful variables in `uses:` and can't even have YAML references to steal it in `env:` or something)
- shell: 'bash -Eeuo pipefail -x {0}'
run: echo BASHBREW_VERSION=v0.1.5 >> "$GITHUB_ENV"
- uses: docker-library/bashbrew@v0.1.5
if: inputs.build == 'host'

- run: docker build --pull --tag oisupport/bashbrew:base "https://github.com/docker-library/bashbrew.git#$BASHBREW_VERSION"
shell: 'bash -Eeuo pipefail -x {0}'
if: inputs.build == 'docker'
15 changes: 4 additions & 11 deletions .github/workflows/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ set -Eeuo pipefail
# NOTE: this is *not* a good example for integrating these tests into your own repository!
# If you want that, check out https://github.com/docker-library/golang/blob/3f2c52653043f067156ce4f41182c2a758c4c857/.github/workflows/ci.yml instead.
#

bashbrewDir="$1"; shift

dir="$(dirname "$BASH_SOURCE")" # ./.github/workflows
oiDir="$(dirname "$dir")" # ./.github
oiDir="$(dirname "$oiDir")" # ./
bashbrewVersion="$(< "$oiDir/bashbrew-version")"
export bashbrewVersion
[ -d "$BASHBREW_SCRIPTS/github-actions" ]

if [ "$#" -eq 0 ]; then
git fetch --quiet https://github.com/docker-library/official-images.git master
Expand All @@ -23,18 +17,17 @@ fi

strategy='{}'
for repo; do
newStrategy="$(GITHUB_REPOSITORY="$repo" GENERATE_STACKBREW_LIBRARY='cat "library/$GITHUB_REPOSITORY"' "$bashbrewDir/scripts/github-actions/generate.sh")"
newStrategy="$(GITHUB_REPOSITORY="$repo" GENERATE_STACKBREW_LIBRARY='cat "library/$GITHUB_REPOSITORY"' "$BASHBREW_SCRIPTS/github-actions/generate.sh")"
newStrategy="$(jq -c --arg repo "$repo" '.matrix.include = [
.matrix.include[]
| ([ .meta.entries[].tags[0] ]) as $tags
| .name = ($tags | join(", "))
# replace "build" steps with something that uses "bashbrew" instead of "docker build"
# https://github.com/docker-library/bashbrew/blob/a40a54d4d81b9fd2e39b4d7ba3fe203e8b022a67/scripts/github-actions/generate.sh#L74-L93
| .runs.prepare += "\ngit clone --depth 1 https://github.com/docker-library/bashbrew.git -b " + ("v" + env.bashbrewVersion | @sh) + " ~/bashbrew\n~/bashbrew/bashbrew.sh --version"
# https://github.com/docker-library/bashbrew/blob/20b5a50a4eafee1e92fadca5f9cbbce6b16d80b1/scripts/github-actions/generate.sh#L79-L105
| .runs.build = (
(if .os | startswith("windows-") then "export BASHBREW_ARCH=windows-amd64 BASHBREW_CONSTRAINTS=" + ([ .meta.entries[].constraints[] ] | join(", ") | @sh) + "\n" else "" end)
+ "export BASHBREW_LIBRARY=\"$PWD/library\"\n"
+ ([ $tags[] | "~/bashbrew/bashbrew.sh build " + @sh ] | join("\n"))
+ ([ $tags[] | "bashbrew build " + @sh ] | join("\n"))
)
# use our local clone of official-images for running tests (so test changes can be tested too, if they live in the PR with the image change)
# https://github.com/docker-library/bashbrew/blob/a40a54d4d81b9fd2e39b4d7ba3fe203e8b022a67/scripts/github-actions/generate.sh#L95
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/munge-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Gather Metadata
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
# ideally this would be "github.event.pull_request.merge_commit_sha" but according to https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#get-a-pull-request if "mergeable" is null (meaning there's a background job in-progress to check mergeability), that value is undefined...
ref: ${{ github.event.pull_request.head.sha }}
Expand Down Expand Up @@ -90,16 +90,17 @@ jobs:
needs: gather
if: fromJSON(needs.gather.outputs.images).count > 0
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
# again, this would ideally be "github.event.pull_request.merge_commit_sha" but we might not have that yet when this runs, so we compromise by checkout out the latest code from the target branch (so we get the latest "diff-pr.sh" script to run)
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
- uses: ./.github/workflows/.bashbrew
with:
build: 'docker'
- name: Prepare Environment
run: |
# this mimics "test-pr.sh", but without running repo-local scripts (to avoid CVE-2020-15228 via the scripts being updated to write nasty things to $GITHUB_ENV)
bashbrewVersion="$(< bashbrew-version)"
docker build --pull --tag oisupport/bashbrew:base "https://github.com/docker-library/bashbrew.git#v$bashbrewVersion"
# this avoids running repo-local scripts (to avoid CVE-2020-15228 via the scripts being updated to write nasty things to $GITHUB_ENV)
docker build --tag oisupport/bashbrew:diff-pr .
- name: Gather Maintainers
env:
Expand Down
25 changes: 10 additions & 15 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@ jobs:
name: Naughty
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/workflows/.bashbrew
- name: Check for Common Issues
run: |
bashbrewVersion="$(< bashbrew-version)"
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b "v$bashbrewVersion" ~/bashbrew
~/bashbrew/bashbrew.sh --version > /dev/null
export PATH="$HOME/bashbrew/bin:$PATH"
bashbrew --version
.github/workflows/naughty.sh
run: .github/workflows/naughty.sh

generate-jobs:
name: Generate Jobs
Expand All @@ -44,19 +39,18 @@ jobs:
strategy: ${{ steps.generate-jobs.outputs.strategy }}
length: ${{ steps.generate-jobs.outputs.length }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/workflows/.bashbrew
- id: generate-jobs
name: Generate Jobs
run: |
bashbrewVersion="$(< bashbrew-version)"
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b "v$bashbrewVersion" ~/bashbrew
strategy="$(.github/workflows/generate.sh ~/bashbrew)"
strategy="$(.github/workflows/generate.sh)"
echo "strategy=$strategy" >> "$GITHUB_OUTPUT"
jq . <<<"$strategy" # sanity check / debugging aid
echo "::set-output name=strategy::$strategy"
length="$(jq <<<"$strategy" -r '.matrix.include | length')"
echo "::set-output name=length::$length"
echo "length=$length" >> "$GITHUB_OUTPUT"
test:
needs: generate-jobs
Expand All @@ -73,7 +67,8 @@ jobs:
echo 'MSYS=winsymlinks:nativestrict' >> "$GITHUB_ENV"
# https://github.com/docker-library/bashbrew/blob/a40a54d4d81b9fd2e39b4d7ba3fe203e8b022a67/scripts/github-actions/generate.sh#L146-L149
if: runner.os == 'Windows'
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/.bashbrew
- name: Prepare Environment
run: ${{ matrix.runs.prepare }}
- name: Pull Dependencies
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FYI, this base image is built via test-pr.sh (from https://github.com/docker-library/bashbrew/tree/master/Dockerfile)
# FYI, this base image is built via ".github/workflows/.bashbrew/action.yml" (from https://github.com/docker-library/bashbrew/tree/master/Dockerfile)
FROM oisupport/bashbrew:base

RUN set -eux; \
Expand Down
1 change: 0 additions & 1 deletion bashbrew-version

This file was deleted.

32 changes: 32 additions & 0 deletions pr-urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -Eeuo pipefail

#
# usage:
# $ ./pr-urls.sh PR-NUMBER
# $ ./pr-urls.sh PR-NUMBER IMAGE1 IMAGE2:TAG1 IMAGE3:TAG2
#
# $ ./pr-urls.sh 12072
# $ ./pr-urls.sh 12072 hello-world:linux
# $ ./pr-urls.sh 12072 | xargs -rt bashbrew build
# $ ./pr-urls.sh 12072 | xargs -rt bashbrew list --uniq
# $ ./pr-urls.sh 12072 | xargs -rt bashbrew list --uniq | xargs -rt ./test/run.sh
#
# (rough replacement for the old "test-pr.sh" script and its associated complexity)
#

pr="$1"
shift

patch="$(wget -qO- "https://github.com/docker-library/official-images/pull/$pr.patch")"

commit="$(grep <<<"$patch" -oE '^From [0-9a-f]+ ' | tail -1 | cut -d' ' -f2)"

if [ "$#" -eq 0 ]; then
files="$(grep <<<"$patch" -oE '^[+]{3} b/library/.+' | cut -d/ -f3 | sort -u)"
set -- $files
fi

for file; do
echo "https://github.com/docker-library/official-images/raw/$commit/library/$file"
done
Loading

0 comments on commit 440ac1a

Please sign in to comment.