Add initial "composite" action for installing Bashbrew

(Also, fix a few minor bugs in `scripts/github-actions/generate.sh` and update the example appropriately)
This commit is contained in:
Tianon Gravi 2022-11-16 10:40:53 -08:00
parent b8eda2b2f6
commit ba00ac06de
4 changed files with 45 additions and 22 deletions

View File

@ -15,26 +15,26 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '>=1.18'
- name: Build
run: |
./bashbrew.sh --version > /dev/null
bin/bashbrew --version
- uses: actions/checkout@v3
- uses: ./ # test our "action.yml" 👀
- name: Smoke Test
run: |
image='https://github.com/docker-library/official-images/raw/master/library/hello-world'
bin/bashbrew list "$image"
bin/bashbrew list --uniq "$image"
bin/bashbrew cat "$image"
bin/bashbrew from --uniq "$image"
bashbrew list "$image"
bashbrew list --uniq "$image"
bashbrew cat "$image"
bashbrew from --uniq "$image"
"$BASHBREW_SCRIPTS/bashbrew-host-arch.sh" # should print "amd64"
arm32v7="$("$BASHBREW_SCRIPTS/bashbrew-arch-to-goenv.sh" arm32v7)"
eval "$arm32v7"
test "$GOARM" = '7'
go-test:
name: Go Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Go Test
run: |
docker build --pull --file Dockerfile.test --tag test .
@ -49,7 +49,7 @@ jobs:
name: Test Dockerfile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build Dockerfile
run: |
docker build --pull .
@ -57,7 +57,7 @@ jobs:
name: Test Dockerfile.release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build Dockerfile.release
run: |
docker build --pull --file Dockerfile.release .

19
action.yml Normal file
View File

@ -0,0 +1,19 @@
# steps:
# - ...
# - uses: docker-library/bashbrew
# - ...
name: 'Install Bashbrew'
description: 'Install the "bashbrew" tool in GITHUB_PATH'
runs:
using: 'composite'
steps:
- uses: actions/setup-go@v3
with:
go-version-file: '${{ github.action_path }}/go.mod'
- run: |
'${{ github.action_path }}/bashbrew.sh' --version > /dev/null
'${{ github.action_path }}/bin/bashbrew' --version
echo '${{ github.action_path }}/bin' >> "$GITHUB_PATH"
echo 'BASHBREW_SCRIPTS=${{ github.action_path }}/scripts' >> "$GITHUB_ENV"
shell: 'bash -Eeuo pipefail -x {0}'

View File

@ -18,14 +18,14 @@ jobs:
outputs:
strategy: ${{ steps.generate-jobs.outputs.strategy }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: docker-library/bashbrew
- id: generate-jobs
name: Generate Jobs
run: |
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
strategy="$(~/bashbrew/scripts/github-actions/generate.sh)"
strategy="$("$BASHBREW_SCRIPTS/github-actions/generate.sh")"
echo "strategy=$strategy" >> "$GITHUB_OUTPUT"
jq . <<<"$strategy" # sanity check / debugging aid
echo "::set-output name=strategy::$strategy"
test:
needs: generate-jobs
@ -33,7 +33,7 @@ jobs:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Prepare Environment
run: ${{ matrix.runs.prepare }}
- name: Pull Dependencies

View File

@ -117,8 +117,12 @@ for tag in $tags; do
'
)"
parent="$(bashbrew parents "$bashbrewImage" | tail -1)" # if there ever exists an image with TWO parents in the same repo, this will break :)
if [ -n "$parent" ]; then
if parent="$(bashbrew parents "$bashbrewImage" | grep "^${tag%%:*}:")" && [ -n "$parent" ]; then
if [ "$(wc -l <<<"$parent")" -ne 1 ]; then
echo >&2 "error: '$tag' has multiple parents in the same repository and this script can't handle that yet!"
echo >&2 "$parent"
exit 1
fi
parentBashbrewImage="${parent##*/}" # account for BASHBREW_NAMESPACE being set
parent="$(bashbrew list --uniq "$parentBashbrewImage")" # normalize
parentMeta="${metas["$parent"]}"