From ba00ac06de76a632b29d402da84a0ece9a1d5acc Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 16 Nov 2022 10:40:53 -0800 Subject: [PATCH] Add initial "composite" action for installing Bashbrew (Also, fix a few minor bugs in `scripts/github-actions/generate.sh` and update the example appropriately) --- .github/workflows/ci.yml | 30 +++++++++++++-------------- action.yml | 19 +++++++++++++++++ scripts/github-actions/example-ci.yml | 10 ++++----- scripts/github-actions/generate.sh | 8 +++++-- 4 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 action.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f0c1eea..82f92300 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 . diff --git a/action.yml b/action.yml new file mode 100644 index 00000000..88ac9685 --- /dev/null +++ b/action.yml @@ -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}' diff --git a/scripts/github-actions/example-ci.yml b/scripts/github-actions/example-ci.yml index 14b8e3ee..b1ad256b 100644 --- a/scripts/github-actions/example-ci.yml +++ b/scripts/github-actions/example-ci.yml @@ -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 diff --git a/scripts/github-actions/generate.sh b/scripts/github-actions/generate.sh index 0eb77468..0ddfb0f6 100755 --- a/scripts/github-actions/generate.sh +++ b/scripts/github-actions/generate.sh @@ -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"]}"