Skip to content

Commit 4f4ad25

Browse files
authored
Merge pull request #57 from infosiftr/github-composite-action
Add initial "composite" action for installing Bashbrew
2 parents b8eda2b + ba00ac0 commit 4f4ad25

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

.github/workflows/ci.yml

+15-15
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ jobs:
1515
name: Build
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
19-
- uses: actions/setup-go@v3
20-
with:
21-
go-version: '>=1.18'
22-
- name: Build
23-
run: |
24-
./bashbrew.sh --version > /dev/null
25-
bin/bashbrew --version
18+
- uses: actions/checkout@v3
19+
- uses: ./ # test our "action.yml" 👀
2620
- name: Smoke Test
2721
run: |
2822
image='https://github.com/docker-library/official-images/raw/master/library/hello-world'
29-
bin/bashbrew list "$image"
30-
bin/bashbrew list --uniq "$image"
31-
bin/bashbrew cat "$image"
32-
bin/bashbrew from --uniq "$image"
23+
bashbrew list "$image"
24+
bashbrew list --uniq "$image"
25+
bashbrew cat "$image"
26+
bashbrew from --uniq "$image"
27+
28+
"$BASHBREW_SCRIPTS/bashbrew-host-arch.sh" # should print "amd64"
29+
30+
arm32v7="$("$BASHBREW_SCRIPTS/bashbrew-arch-to-goenv.sh" arm32v7)"
31+
eval "$arm32v7"
32+
test "$GOARM" = '7'
3333
go-test:
3434
name: Go Test
3535
runs-on: ubuntu-latest
3636
steps:
37-
- uses: actions/checkout@v2
37+
- uses: actions/checkout@v3
3838
- name: Go Test
3939
run: |
4040
docker build --pull --file Dockerfile.test --tag test .
@@ -49,15 +49,15 @@ jobs:
4949
name: Test Dockerfile
5050
runs-on: ubuntu-latest
5151
steps:
52-
- uses: actions/checkout@v2
52+
- uses: actions/checkout@v3
5353
- name: Build Dockerfile
5454
run: |
5555
docker build --pull .
5656
dockerfile-release:
5757
name: Test Dockerfile.release
5858
runs-on: ubuntu-latest
5959
steps:
60-
- uses: actions/checkout@v2
60+
- uses: actions/checkout@v3
6161
- name: Build Dockerfile.release
6262
run: |
6363
docker build --pull --file Dockerfile.release .

action.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# steps:
2+
# - ...
3+
# - uses: docker-library/bashbrew
4+
# - ...
5+
6+
name: 'Install Bashbrew'
7+
description: 'Install the "bashbrew" tool in GITHUB_PATH'
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- uses: actions/setup-go@v3
12+
with:
13+
go-version-file: '${{ github.action_path }}/go.mod'
14+
- run: |
15+
'${{ github.action_path }}/bashbrew.sh' --version > /dev/null
16+
'${{ github.action_path }}/bin/bashbrew' --version
17+
echo '${{ github.action_path }}/bin' >> "$GITHUB_PATH"
18+
echo 'BASHBREW_SCRIPTS=${{ github.action_path }}/scripts' >> "$GITHUB_ENV"
19+
shell: 'bash -Eeuo pipefail -x {0}'

scripts/github-actions/example-ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ jobs:
1818
outputs:
1919
strategy: ${{ steps.generate-jobs.outputs.strategy }}
2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v3
22+
- uses: docker-library/bashbrew
2223
- id: generate-jobs
2324
name: Generate Jobs
2425
run: |
25-
git clone --depth 1 https://github.com/docker-library/bashbrew.git -b master ~/bashbrew
26-
strategy="$(~/bashbrew/scripts/github-actions/generate.sh)"
26+
strategy="$("$BASHBREW_SCRIPTS/github-actions/generate.sh")"
27+
echo "strategy=$strategy" >> "$GITHUB_OUTPUT"
2728
jq . <<<"$strategy" # sanity check / debugging aid
28-
echo "::set-output name=strategy::$strategy"
2929
3030
test:
3131
needs: generate-jobs
3232
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
3333
name: ${{ matrix.name }}
3434
runs-on: ${{ matrix.os }}
3535
steps:
36-
- uses: actions/checkout@v2
36+
- uses: actions/checkout@v3
3737
- name: Prepare Environment
3838
run: ${{ matrix.runs.prepare }}
3939
- name: Pull Dependencies

scripts/github-actions/generate.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ for tag in $tags; do
117117
'
118118
)"
119119

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

0 commit comments

Comments
 (0)