diff --git a/.github/.patch_files b/.github/.patch_files new file mode 100644 index 0000000..06ce170 --- /dev/null +++ b/.github/.patch_files @@ -0,0 +1,29 @@ +.github/.patch_files +.github/.syncignore +.github/CODEOWNERS +.github/dependabot.yml +.github/labels.yml +.github/workflows/approve-bot-pr.yml +.github/workflows/codeql-analysis.yml +.github/workflows/go-get-update.yml +.github/workflows/label-pr.yml +.github/workflows/lint-yaml.yml +.github/workflows/lint.yml +.github/workflows/synchronize-labels.yml +.github/workflows/test-pull-request.yml +.github/workflows/update-dependencies.yml +.github/workflows/update-dependencies-from-metadata.yml +.github/workflows/update-github-config.yml +.gitignore +LICENSE +NOTICE +README.md +go.mod +go.sum +scripts/.util/builders.sh +scripts/.util/git.sh +scripts/.util/print.sh +scripts/.util/tools.json +scripts/.util/tools.sh +scripts/integration.sh +scripts/unit.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..bf49a9d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +--- +version: 2 +updates: +- package-ecosystem: gomod + directory: "/" + schedule: + interval: daily diff --git a/.github/labels.yml b/.github/labels.yml index c8c9b0a..0a331a9 100644 --- a/.github/labels.yml +++ b/.github/labels.yml @@ -16,6 +16,9 @@ - name: documentation description: This issue relates to writing documentation color: D4C5F9 +- name: help wanted + description: Extra attention is needed + color: 008672 - name: semver:major description: A change requiring a major version bump color: 6b230e diff --git a/.github/workflows/create-draft-release.yml b/.github/workflows/create-draft-release.yml index 4b027e3..281809f 100644 --- a/.github/workflows/create-draft-release.yml +++ b/.github/workflows/create-draft-release.yml @@ -37,10 +37,32 @@ jobs: printf "Output: %s\n" "${builders}" printf "builders=%s\n" "${builders}" >> "$GITHUB_OUTPUT" + integration: + name: Integration Tests + runs-on: ubuntu-22.04 + needs: unit + strategy: + matrix: + builder: ${{ fromJSON(needs.unit.outputs.builders) }} + fail-fast: false # don't cancel all test jobs when one fails + steps: + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.20.x + - name: Checkout + uses: actions/checkout@v3 + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true + - name: Run Integration Tests + run: ./scripts/integration.sh --use-token --builder ${{ matrix.builder }} + env: + GIT_TOKEN: ${{ github.token }} + TMPDIR: "${{ runner.temp }}" + release: name: Release runs-on: ubuntu-22.04 - needs: unit + needs: integration steps: - name: Setup Go uses: actions/setup-go@v3 @@ -75,8 +97,10 @@ jobs: run: ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}" - name: Create Release Notes id: create-release-notes - run: | - echo "release_body=No release notes yet - working on it" >> "$GITHUB_OUTPUT" + uses: paketo-buildpacks/github-config/actions/release/notes@main + with: + repo: ${{ github.repository }} + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} - name: Create Release uses: paketo-buildpacks/github-config/actions/release/create@main with: @@ -104,7 +128,7 @@ jobs: failure: name: Alert on Failure runs-on: ubuntu-22.04 - needs: [ unit, release ] + needs: [ unit, integration, release ] if: ${{ always() && needs.unit.result == 'failure' || needs.integration.result == 'failure' || needs.release.result == 'failure' }} steps: - name: File Failure Alert Issue diff --git a/.github/workflows/go-get-update.yml b/.github/workflows/go-get-update.yml index d0cb0b1..cbf8bc0 100644 --- a/.github/workflows/go-get-update.yml +++ b/.github/workflows/go-get-update.yml @@ -13,7 +13,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Checkout uses: actions/checkout@v3 @@ -67,6 +67,5 @@ jobs: issue_title: "Failure: Go get update workflow" issue_body: | Go get update workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). - Please take a look to ensure CVE patches can be released. (cc @pivotal-cf/commercial-buildpacks). comment_body: | Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} diff --git a/.github/workflows/lint-yaml.yml b/.github/workflows/lint-yaml.yml index 145dfb9..e6f4a8b 100644 --- a/.github/workflows/lint-yaml.yml +++ b/.github/workflows/lint-yaml.yml @@ -19,7 +19,7 @@ jobs: path: github-config - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: 3.8 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2ceef4b..130481f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/push-buildpackage.yml b/.github/workflows/push-buildpackage.yml index 2587785..f96478e 100644 --- a/.github/workflows/push-buildpackage.yml +++ b/.github/workflows/push-buildpackage.yml @@ -66,6 +66,14 @@ jobs: echo "image=${IMAGE}" >> "$GITHUB_OUTPUT" echo "digest=$(sudo skopeo inspect "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" | jq -r .Digest)" >> "$GITHUB_OUTPUT" + - name: Register with CNB Registry + uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:main + with: + id: ${{ github.repository }} + version: ${{ steps.event.outputs.tag_full }} + address: ${{ steps.push.outputs.image }}@${{ steps.push.outputs.digest }} + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} + failure: name: Alert on Failure runs-on: ubuntu-22.04 diff --git a/.github/workflows/update-dependencies-from-metadata.yml b/.github/workflows/update-dependencies-from-metadata.yml new file mode 100644 index 0000000..f352bec --- /dev/null +++ b/.github/workflows/update-dependencies-from-metadata.yml @@ -0,0 +1,350 @@ +name: Update Dependencies From Metadata (Retrieve, Metadata, Compile, Test, Create PR) + +on: + workflow_dispatch: + # https://crontab.guru/every-12-hours + schedule: + - cron: '0 */12 * * *' + +jobs: + retrieve: + name: Retrieve New Versions and Generate Metadata + runs-on: ubuntu-latest + outputs: + metadata-filepath: ${{ steps.retrieve.outputs.metadata-filepath }} + metadata-json: ${{ steps.retrieve.outputs.metadata-json }} + # compilation-json is a subset of metadata-json entries which are missing + # a `checksum` and `uri` + compilation-json: ${{ steps.retrieve.outputs.compilation-json }} + id: ${{ steps.retrieve.outputs.id }} + length: ${{ steps.retrieve.outputs.length }} + compilation-length: ${{ steps.retrieve.outputs.compilation-length }} + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.20.x + + - name: Run Retrieve + id: retrieve + working-directory: dependency + run: | + OUTPUT="/tmp/metadata.json" + + make retrieve \ + buildpackTomlPath="${{ github.workspace }}/buildpack.toml" \ + output="${OUTPUT}" + + id=$(jq -r .[0].id < "${OUTPUT}") + content=$(jq -r < "${OUTPUT}") + + length=$(echo $content | jq -r '. | length') + + compilation=$(echo $content | jq -r 'map(select(.checksum == null and .uri == null))'?) + complength=$(echo $compilation | jq -r '. | length') + + delimiter="$(uuidgen)" + echo "metadata-filepath=${OUTPUT}" >> "$GITHUB_OUTPUT" + printf "metadata-json<<%s\n%s\n%s\n" "${delimiter}" "${content}" "${delimiter}" >> "$GITHUB_OUTPUT" # see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + echo "id=$id" >> "$GITHUB_OUTPUT" + echo "length=$length" >> "$GITHUB_OUTPUT" + printf "compilation-json<<%s\n%s\n%s\n" "${delimiter}" "${compilation}" "${delimiter}" >> "$GITHUB_OUTPUT" # see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + echo "compilation-length=$complength" >> "$GITHUB_OUTPUT" + + + - name: Upload `${{ steps.retrieve.outputs.metadata-filepath }}` + uses: actions/upload-artifact@v3 + with: + name: metadata.json + path: ${{ steps.retrieve.outputs.metadata-filepath }} + + # Check if there is buildpack-provided compilation code and testing code + # Optional compilation code expected at: /dependency/actions/compile/ + # Optional testing code expected at: /dependency/test/ + get-compile-and-test: + name: Get Compilation and Testing Code + outputs: + should-compile: ${{ steps.compile-check.outputs.should-compile }} + should-test: ${{ steps.test-check.outputs.should-test }} + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Has Compilation Action? + id: compile-check + run: | + if test -d "dependency/actions/compile"; then + echo "Compilation action provided" + echo "should-compile=true" >> "$GITHUB_OUTPUT" + fi + + - name: Has Testing Action? + id: test-check + run: | + if test -d "dependency/test"; then + echo "Testing file provided" + echo "should-test=true" >> "$GITHUB_OUTPUT" + fi + + test: + name: Test Non-Compiled Dependency + needs: + - retrieve + - get-compile-and-test + strategy: + matrix: + includes: ${{ fromJSON(needs.retrieve.outputs.metadata-json) }} + # Run job step if BOTH: + # (1) needs.get-compile-and-test.outputs.should-test = TRUE -> if there is a dependency/test directory in the buildpack + # (2) needs.get-compile-and-test.outputs.should-compile = FALSE -> if there is NOT a dependency/actions/compile directory in the buildpack + # AND: + # (3) there is at least one new version to test + if: ${{ needs.retrieve.outputs.length > 0 && needs.get-compile-and-test.outputs.should-test == 'true' && needs.get-compile-and-test.outputs.should-compile == 'false' }} + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Make Temporary Artifact Directory + id: make-outputdir + run: | + echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT" + + # Download the tarball for testing if: + # (1) dependency testing code is present in the buildpack directory + # (2) URI in metadata.json is available + - name: Download upstream tarball (if not compiled) + if: ${{ matrix.includes.uri != '' && needs.get-compile-and-test.outputs.should-test == 'true' }} + run: | + curl ${{ matrix.includes.uri }} \ + --fail-with-body \ + --show-error \ + --silent \ + --location \ + --output ${{ steps.make-outputdir.outputs.outputdir }}/dependency.tgz + + # Test the dependency tarball if: + # (1) dependency testing code is present in the buildpack directory + - name: Test Upstream Dependency + working-directory: dependency + if: ${{ needs.get-compile-and-test.outputs.should-test == 'true' }} + run: | + make test \ + version="${{ matrix.includes.version }}" \ + tarballPath="${{ steps.make-outputdir.outputs.outputdir }}/*.tgz" + + compile: + name: Compile and Test Dependency + needs: + - retrieve + - get-compile-and-test + strategy: + matrix: + includes: ${{ fromJSON(needs.retrieve.outputs.compilation-json) }} + # Run job step if: + # (1) needs.get-compile-and-test.outputs.should-compile -> if there is a dependency/actions/compile directory in the buildpack + # (2) OR needs.get-compile-and-test.outputs.should-test -> if there is a dependency/test directory in the buildpack + # AND: + # (3) there is at least one version to compile/test + if: ${{ needs.retrieve.outputs.compilation-length > 0 && (needs.get-compile-and-test.outputs.should-compile == 'true' || needs.get-compile-and-test.outputs.should-test == 'true') }} + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Make Temporary Artifact Directory + id: make-outputdir + run: | + echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT" + + # Compile if all of the following conditions are met: + # (1) compilation Github Action presetn in the buildpack directory + # (2) checksum in metadata.json is empty + # (3) URI in metadata.json is empty + - name: Compile version ${{ matrix.includes.version }} on ${{ matrix.includes.target }} Dockerfile + id: compile + if: ${{ needs.get-compile-and-test.outputs.should-compile && matrix.includes.checksum == '' && matrix.includes.uri == '' }} + uses: ./dependency/actions/compile + with: + version: "${{ matrix.includes.version }}" + outputdir: "${{ steps.make-outputdir.outputs.outputdir }}" + target: "${{ matrix.includes.target }}" + + # If compiled, upload the tarball and checksum file for usage in the Update metadata job + - name: Upload workflow asset + uses: actions/upload-artifact@v3 + if: ${{ needs.get-compile-and-test.outputs.should-compile && matrix.includes.checksum == '' && matrix.includes.uri == '' }} + with: + name: '${{ needs.retrieve.outputs.id }}-${{ matrix.includes.version }}-${{ matrix.includes.target }}' + path: '${{ steps.make-outputdir.outputs.outputdir }}/*' + + # Test the dependency tarball if: + # (1) dependency testing code is present in the buildpack directory + - name: Test Dependency + working-directory: dependency + if: ${{ needs.get-compile-and-test.outputs.should-test == 'true' }} + run: | + make test \ + version="${{ matrix.includes.version }}" \ + tarballPath="${{ steps.make-outputdir.outputs.outputdir }}/*.tgz" + + # Add in the checksum and URI fields to the metadata if the dependency was compiled + update-metadata: + name: Update Metadata (if compiled) + needs: + - retrieve + - get-compile-and-test + - compile + strategy: + matrix: + includes: ${{ fromJSON(needs.retrieve.outputs.compilation-json) }} + # Run metadata update step sequentially so that metadata.json can be + # modified for each version + max-parallel: 1 + if: ${{ needs.retrieve.outputs.compilation-length > 0 && needs.get-compile-and-test.outputs.should-compile == 'true' }} + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Download artifact files + uses: actions/download-artifact@v3 + with: + name: '${{ needs.retrieve.outputs.id }}-${{ matrix.includes.version }}-${{ matrix.includes.target }}' + + - name: Get artifact file name + id: get-file-names + run: | + echo "artifact-file=$(basename ./*.tgz)" >> "$GITHUB_OUTPUT" + echo "checksum-file=$(basename ./*.tgz.checksum)" >> "$GITHUB_OUTPUT" + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_S3_DEPENDENCIES_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_S3_DEPENDENCIES_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Upload to S3 + id: upload + uses: paketo-buildpacks/github-config/actions/dependency/upload-to-s3@main + with: + bucket-name: "paketo-buildpacks" + dependency-name: ${{ needs.retrieve.outputs.id }} + artifact-path: ${{ steps.get-file-names.outputs.artifact-file }} + + - name: Get Checksum + id: get-checksum + run: echo "checksum=$(cat ${{ steps.get-file-names.outputs.checksum-file }})" >> "$GITHUB_OUTPUT" + + - name: Download metadata.json + uses: actions/download-artifact@v3 + with: + name: metadata.json + + - name: Update `checksum` and `uri` in metadata for ${{ matrix.includes.target }} ${{ matrix.includes.version }} + if: ${{ matrix.includes.checksum == '' && matrix.includes.uri == '' }} + uses: paketo-buildpacks/github-config/actions/dependency/update-metadata-json@main + with: + version: ${{ matrix.includes.version }} + target: ${{ matrix.includes.target }} + checksum: ${{ steps.get-checksum.outputs.checksum }} + uri: ${{ steps.upload.outputs.dependency-uri }} + file: "metadata.json" + + - name: Upload modified metadata + uses: actions/upload-artifact@v3 + with: + name: "metadata.json" + path: "metadata.json" + + assemble: + name: Update buildpack.toml + needs: + - retrieve + - test + - compile + - update-metadata + # Update buildpack.toml only if ALL of the following conditions are met: + # (1) Retrieval step has succeeded and has found at least 1 new version + # (2) Testing step has succeeded OR been skipped + # (3) Compilation/Testing step has succeeded OR been skipped + # (4) Update metadata step has succeeded OR been skipped + if: always() && needs.retrieve.result == 'success' && needs.retrieve.outputs.length > 0 && (needs.test.result == 'success' || needs.test.result == 'skipped') && (needs.compile.result == 'success' || needs.compile.result == 'skipped') && (needs.update-metadata.result == 'success' || needs.update-metadata.result == 'skipped') + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Checkout Branch + uses: paketo-buildpacks/github-config/actions/pull-request/checkout-branch@main + with: + branch: automation/dependencies/update-from-metadata + + - name: Make Temporary Artifact Directory + id: make-outputdir + run: | + echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT" + + - name: Download metadata.json + uses: actions/download-artifact@v3 + with: + name: metadata.json + path: "${{ steps.make-outputdir.outputs.outputdir }}" + + - name: Update dependencies from metadata.json + id: update + uses: paketo-buildpacks/github-config/actions/dependency/update-from-metadata@main + with: + buildpack_toml_path: "${{ github.workspace }}/buildpack.toml" + metadata_file_path: "${{ steps.make-outputdir.outputs.outputdir }}/metadata.json" + + - name: Show git diff + run: | + git diff + + - name: Commit + id: commit + uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main + with: + message: "Updating buildpack.toml with new versions ${{ steps.update.outputs.new-versions }}" + pathspec: "." + keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }} + key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }} + + - name: Push Branch 'automation/dependencies/update-from-metadata' + if: ${{ steps.commit.outputs.commit_sha != '' }} + uses: paketo-buildpacks/github-config/actions/pull-request/push-branch@main + with: + branch: automation/dependencies/update-from-metadata + + - name: Open Pull Request + if: ${{ steps.commit.outputs.commit_sha != '' }} + uses: paketo-buildpacks/github-config/actions/pull-request/open@main + with: + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} + title: "Updates buildpack.toml with ${{ steps.update.outputs.new-versions }}" + branch: automation/buildpack.toml/update-from-metadata + + failure: + name: Alert on Failure + runs-on: ubuntu-22.04 + needs: [ retrieve, get-compile-and-test, test, compile, update-metadata, assemble ] + if: ${{ always() && needs.retrieve.result == 'failure' || needs.get-compile-and-test.result == 'failure' || needs.test.result == 'failure' || needs.compile.result == 'failure' || needs.update-metadata.result == 'failure' || needs.assemble.result == 'failure' }} + steps: + - name: File Failure Alert Issue + uses: paketo-buildpacks/github-config/actions/issue/file@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + repo: ${{ github.repository }} + label: "failure:update-dependencies" + comment_if_exists: true + issue_title: "Failure: Update Dependencies workflow" + issue_body: | + Update Dependencies From Metadata workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). + comment_body: | + Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} diff --git a/scripts/.util/builders.sh b/scripts/.util/builders.sh index ccfc33d..a4b3e9a 100644 --- a/scripts/.util/builders.sh +++ b/scripts/.util/builders.sh @@ -19,7 +19,7 @@ function util::builders::list() { if [[ -z "${builders}" ]]; then util::print::info "No builders specified. Falling back to default builder..." - builders="$(jq --compact-output --null-input '["index.docker.io/paketocommunity/builder-ubi-buildpackless-base:0.0.3"]')" + builders="$(jq --compact-output --null-input '["index.docker.io/paketobuildpacks/builder-jammy-buildpackless-base:latest"]')" fi echo "${builders}" diff --git a/scripts/.util/tools.json b/scripts/.util/tools.json index fe1bdde..a8834ad 100644 --- a/scripts/.util/tools.json +++ b/scripts/.util/tools.json @@ -1,5 +1,5 @@ { - "createpackage": "v1.64.0", - "jam": "v2.3.0", - "pack": "v0.30.0-pre2" + "createpackage": "v1.66.2", + "jam": "v2.5.0", + "pack": "v0.30.0" } diff --git a/scripts/.util/tools.sh b/scripts/.util/tools.sh index e4c5706..35addb0 100644 --- a/scripts/.util/tools.sh +++ b/scripts/.util/tools.sh @@ -224,4 +224,4 @@ function util::tools::tests::checkfocus() { util::print::success "** GO Test Succeeded **" 197 fi rm "${testout}" -} \ No newline at end of file +} diff --git a/scripts/build.sh b/scripts/build.sh index a419c4e..a3e1d3d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,13 +3,9 @@ set -eu set -o pipefail -readonly ROOT_DIR="$(cd "$(dirname "${0}")/.." && pwd)" readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)" -# shellcheck source=SCRIPTDIR/.util/print.sh -source "${ROOT_DIR}/scripts/.util/print.sh" - function main() { while [[ "${#}" != 0 ]]; do case "${1}" in @@ -60,7 +56,7 @@ function run::build() { echo "Success!" - for name in detect generate; do + for name in detect build; do printf "%s" "Linking ${name}... " ln -sf "run" "${name}" diff --git a/scripts/integration.sh b/scripts/integration.sh index 2e9c2fd..13a5635 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -23,57 +23,58 @@ function main() { builderArray=() while [[ "${#}" != 0 ]]; do case "${1}" in - --use-token|-t) + --use-token|-t) shift 1 token::fetch ;; - --help | -h) - shift 1 - usage - exit 0 - ;; - - --builder | -b) - builderArray+=("${2}") - shift 2 - ;; - - "") - # skip if the argument is empty - shift 1 - ;; - - *) - util::print::error "unknown argument \"${1}\"" - ;; + --help|-h) + shift 1 + usage + exit 0 + ;; + + --builder|-b) + builderArray+=("${2}") + shift 2 + ;; + + "") + # skip if the argument is empty + shift 1 + ;; + + *) + util::print::error "unknown argument \"${1}\"" esac done if [[ ! -d "${BUILDPACKDIR}/integration" ]]; then - util::print::warn "** WARNING No Integration tests **" + util::print::warn "** WARNING No Integration tests **" fi - tools::install + tools::install "${GIT_TOKEN:-}" if [ ${#builderArray[@]} -eq 0 ]; then util::print::title "No builders provided. Finding builders in integration.json..." local builders - builders="$(util::builders::list "${BUILDPACKDIR}/integration.json" | jq -r '.[]')" + builders="$(util::builders::list "${BUILDPACKDIR}/integration.json" | jq -r '.[]' )" + + util::print::info "Found the following builders:" + util::print::info "${builders}" # shellcheck disable=SC2206 IFS=$'\n' builderArray=(${builders}) unset IFS fi - # shellcheck disable=SC2068 - images::pull ${builderArray[@]} - local testout testout=$(mktemp) - for builder in "${builderArray[@]}"; do + util::print::title "Getting images for builder: '${builder}'" + builder_images::pull "${builder}" + util::print::title "Setting default pack builder image..." pack config default-builder "${builder}" @@ -92,18 +93,23 @@ Runs the integration test suite. OPTIONS --help -h prints the command usage + --use-token -t use GIT_TOKEN from lastpass --builder -b sets the name of the builder(s) that are pulled / used for testing. Defaults to "builders" array in integration.json, if present. USAGE } function tools::install() { + local token + token="${1}" util::tools::pack::install \ - --directory "${BUILDPACKDIR}/.bin" + --directory "${BUILDPACKDIR}/.bin" \ + --token "${token}" util::tools::jam::install \ - --directory "${BUILDPACKDIR}/.bin" + --directory "${BUILDPACKDIR}/.bin" \ + --token "${token}" util::tools::create-package::install \ --directory "${BUILDPACKDIR}/.bin" @@ -114,25 +120,28 @@ function tools::install() { fi } -function images::pull() { - for builder in "${@}"; do - util::print::title "Pulling builder image ${builder}..." - docker pull "${builder}" - local run_image lifecycle_image - run_image="$( - pack inspect-builder "${builder}" --output json | - jq -r '.remote_info.run_images[0].name' - )" - lifecycle_image="index.docker.io/buildpacksio/lifecycle:$( - pack inspect-builder "${builder}" --output json | - jq -r '.remote_info.lifecycle.version' - )" - util::print::title "Pulling run image..." - docker pull "${run_image}" - - util::print::title "Pulling lifecycle image..." - docker pull "${lifecycle_image}" - done +function builder_images::pull() { + local builder + builder="${1}" + + util::print::title "Pulling builder image ${builder}..." + docker pull "${builder}" + + local run_image lifecycle_image + run_image="$( + pack inspect-builder "${builder}" --output json \ + | jq -r '.remote_info.run_images[0].name' + )" + lifecycle_image="index.docker.io/buildpacksio/lifecycle:$( + pack inspect-builder "${builder}" --output json \ + | jq -r '.remote_info.lifecycle.version' + )" + + util::print::title "Pulling run image..." + docker pull "${run_image}" + + util::print::title "Pulling lifecycle image..." + docker pull "${lifecycle_image}" } function token::fetch() { @@ -144,13 +153,14 @@ function tests::run() { util::print::title "Run Buildpack Runtime Integration Tests" util::print::info "Using ${1} as builder..." - pushd "${BUILDPACKDIR}" >/dev/null - if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${2}"; then - util::print::info "** GO Test Succeeded with ${1}**" - else - util::print::error "** GO Test Failed with ${1}**" - fi - popd >/dev/null + export CGO_ENABLED=0 + pushd "${BUILDPACKDIR}" > /dev/null + if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${2}"; then + util::print::info "** GO Test Succeeded with ${1}**" + else + util::print::error "** GO Test Failed with ${1}**" + fi + popd > /dev/null } main "${@:-}" diff --git a/scripts/package.sh b/scripts/package.sh index 8e08663..d58f61c 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -14,33 +14,39 @@ source "${ROOT_DIR}/scripts/.util/tools.sh" source "${ROOT_DIR}/scripts/.util/print.sh" function main { + local version output token + token="" while [[ "${#}" != 0 ]]; do case "${1}" in - --version | -v) - version="${2}" - shift 2 - ;; - - --output | -o) - output="${2}" - shift 2 - ;; - - --help | -h) - shift 1 - usage - exit 0 - ;; - - "") - # skip if the argument is empty - shift 1 - ;; - - *) - util::print::error "unknown argument \"${1}\"" - ;; + --version|-v) + version="${2}" + shift 2 + ;; + + --output|-o) + output="${2}" + shift 2 + ;; + + --token|-t) + token="${2}" + shift 2 + ;; + + --help|-h) + shift 1 + usage + exit 0 + ;; + + "") + # skip if the argument is empty + shift 1 + ;; + + *) + util::print::error "unknown argument \"${1}\"" esac done @@ -56,7 +62,7 @@ function main { repo::prepare - tools::install + tools::install "${token}" buildpack::archive "${version}" buildpackage::create "${output}" @@ -72,6 +78,7 @@ OPTIONS --help -h prints the command usage --version -v specifies the version number to use when packaging the buildpack --output -o location to output the packaged buildpackage artifact (default: ${ROOT_DIR}/build/buildpackage.cnb) + --token Token used to download assets from GitHub (e.g. jam, pack, etc) (optional) USAGE } @@ -87,16 +94,20 @@ function repo::prepare() { } function tools::install() { + local token + token="${1}" util::tools::pack::install \ - --directory "${BIN_DIR}" + --directory "${BIN_DIR}" \ + --token "${token}" if [[ -f "${ROOT_DIR}/.libbuildpack" ]]; then util::tools::packager::install \ --directory "${BIN_DIR}" else util::tools::jam::install \ - --directory "${BIN_DIR}" + --directory "${BIN_DIR}" \ + --token "${token}" fi } @@ -114,7 +125,7 @@ function buildpack::archive() { "${BUILD_DIR}/buildpack" else jam pack \ - --extension "${ROOT_DIR}/extension.toml" \ + --buildpack "${ROOT_DIR}/buildpack.toml" \ --version "${version}" \ --output "${BUILD_DIR}/buildpack.tgz" fi @@ -124,21 +135,12 @@ function buildpackage::create() { local output output="${1}" - util::print::title "Packaging buildpack...${output}" - - cwd=$(pwd) - cd ${BUILD_DIR} - mkdir cnbdir - cd cnbdir - cp ../buildpack.tgz . - tar -xvf buildpack.tgz - rm buildpack.tgz + util::print::title "Packaging buildpack..." pack \ - extension package "${output}" \ - --format file - - cd $cwd + buildpack package "${output}" \ + --path "${BUILD_DIR}/buildpack.tgz" \ + --format file } main "${@:-}"