diff --git a/.github/workflows/approve-bot-pr.yml b/.github/workflows/approve-bot-pr.yml index 9388116..3f45a3d 100644 --- a/.github/workflows/approve-bot-pr.yml +++ b/.github/workflows/approve-bot-pr.yml @@ -10,7 +10,7 @@ jobs: download: name: Download PR Artifact if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: pr-author: ${{ steps.pr-data.outputs.author }} pr-number: ${{ steps.pr-data.outputs.number }} @@ -25,14 +25,14 @@ jobs: token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} - id: pr-data run: | - echo "::set-output name=author::$(cat event.json | jq -r '.pull_request.user.login')" - echo "::set-output name=number::$(cat event.json | jq -r '.pull_request.number')" + echo "author=$(cat event.json | jq -r '.pull_request.user.login')" >> "$GITHUB_OUTPUT" + echo "number=$(cat event.json | jq -r '.pull_request.number')" >> "$GITHUB_OUTPUT" approve: name: Approve Bot PRs needs: download if: ${{ needs.download.outputs.pr-author == 'paketo-bot' || needs.download.outputs.pr-author == 'dependabot[bot]' }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Check Commit Verification id: unverified-commits @@ -67,3 +67,22 @@ jobs: gh pr merge ${{ needs.download.outputs.pr-number }} --auto --rebase env: GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} + + failure: + name: Alert on Failure + runs-on: ubuntu-22.04 + needs: [download, approve] + if: ${{ always() && needs.download.result == 'failure' || needs.approve.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:approve-bot-pr" + comment_if_exists: true + issue_title: "Failure: Approve bot PR workflow" + issue_body: | + Approve bot PR 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/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 13d5249..ac16d68 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -15,7 +15,7 @@ on: jobs: analyze: name: Analyze - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: fail-fast: false diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml index cfc9f3a..a6a5c5c 100644 --- a/.github/workflows/label-pr.yml +++ b/.github/workflows/label-pr.yml @@ -16,7 +16,7 @@ concurrency: pr_labels_${{ github.event.number }} jobs: autolabel: name: Ensure Minimal Semver Labels - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Check Minimal Semver Labels uses: mheap/github-action-required-labels@v1 diff --git a/.github/workflows/lint-yaml.yml b/.github/workflows/lint-yaml.yml index f0ef713..145dfb9 100644 --- a/.github/workflows/lint-yaml.yml +++ b/.github/workflows/lint-yaml.yml @@ -8,7 +8,7 @@ on: jobs: lintYaml: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2735f4f..c8d836c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,12 +13,12 @@ on: jobs: golangci: name: lint - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: 1.18.x + go-version: 1.19.x - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/synchronize-labels.yml b/.github/workflows/synchronize-labels.yml index e7b87c4..0f8c59b 100644 --- a/.github/workflows/synchronize-labels.yml +++ b/.github/workflows/synchronize-labels.yml @@ -7,12 +7,13 @@ on: - v* paths: - .github/labels.yml + workflow_dispatch: {} jobs: synchronize: name: Synchronize Labels runs-on: - - ubuntu-latest + - ubuntu-22.04 steps: - uses: actions/checkout@v3 - uses: micnncim/action-label-syncer@v1 diff --git a/.github/workflows/update-github-config.yml b/.github/workflows/update-github-config.yml index e413e28..90d512f 100644 --- a/.github/workflows/update-github-config.yml +++ b/.github/workflows/update-github-config.yml @@ -10,7 +10,7 @@ concurrency: github_config_update jobs: build: name: Create PR to update shared files - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout @@ -60,3 +60,23 @@ jobs: token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} title: "Updates github-config" branch: automation/github-config/update + base: ${{ github.event.repository.default_branch }} + + failure: + name: Alert on Failure + runs-on: ubuntu-22.04 + needs: [build] + if: ${{ always() && needs.build.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-github-config" + comment_if_exists: true + issue_title: "Failure: Update GitHub config workflow" + issue_body: | + Update GitHub config 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/git.sh b/scripts/.util/git.sh new file mode 100644 index 0000000..71965bc --- /dev/null +++ b/scripts/.util/git.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +# shellcheck source=SCRIPTDIR/print.sh +source "$(dirname "${BASH_SOURCE[0]}")/print.sh" + +function util::git::token::fetch() { + if [[ -z "${GIT_TOKEN:-""}" ]]; then + util::print::title "Fetching GIT_TOKEN" + + GIT_TOKEN="$( + lpass show Shared-CF\ Buildpacks/concourse-private.yml \ + | grep buildpacks-github-token \ + | cut -d ' ' -f 2 + )" + fi + + printf "%s" "${GIT_TOKEN}" +} diff --git a/scripts/.util/print.sh b/scripts/.util/print.sh new file mode 100644 index 0000000..0c5a49e --- /dev/null +++ b/scripts/.util/print.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +function util::print::title() { + local blue reset message + blue="\033[0;34m" + reset="\033[0;39m" + message="${1}" + + echo -e "\n${blue}${message}${reset}" >&2 +} + +function util::print::info() { + local message + message="${1}" + + echo -e "${message}" >&2 +} + +function util::print::error() { + local message red reset + message="${1}" + red="\033[0;31m" + reset="\033[0;39m" + + echo -e "${red}${message}${reset}" >&2 + exit 1 +} + +function util::print::success() { + local message green reset + message="${1}" + green="\033[0;32m" + reset="\033[0;39m" + + echo -e "${green}${message}${reset}" >&2 + exitcode="${2:-0}" + exit "${exitcode}" +} + +function util::print::warn() { + local message yellow reset + message="${1}" + yellow="\033[0;33m" + reset="\033[0;39m" + + echo -e "${yellow}${message}${reset}" >&2 + exit 0 +} diff --git a/scripts/.util/tools.sh b/scripts/.util/tools.sh new file mode 100644 index 0000000..53abd49 --- /dev/null +++ b/scripts/.util/tools.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +# shellcheck source=SCRIPTDIR/print.sh +source "$(dirname "${BASH_SOURCE[0]}")/print.sh" + +function util::tools::tests::checkfocus() { + testout="${1}" + if grep -q 'Focused: [1-9]' "${testout}"; then + echo "Detected Focused Test(s) - setting exit code to 197" + rm "${testout}" + util::print::success "** GO Test Succeeded **" 197 + fi + rm "${testout}" +} diff --git a/scripts/unit.sh b/scripts/unit.sh new file mode 100755 index 0000000..f8c40ca --- /dev/null +++ b/scripts/unit.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)" + +# shellcheck source=SCRIPTDIR/.util/tools.sh +source "${PROGDIR}/.util/tools.sh" + +# shellcheck source=SCRIPTDIR/.util/print.sh +source "${PROGDIR}/.util/print.sh" + +function main() { + while [[ "${#}" != 0 ]]; do + case "${1}" in + --help|-h) + shift 1 + usage + exit 0 + ;; + + "") + # skip if the argument is empty + shift 1 + ;; + + *) + util::print::error "unknown argument \"${1}\"" + esac + done + + unit::run +} + +function usage() { + cat <<-USAGE +unit.sh [OPTIONS] + +Runs the unit test suite. + +OPTIONS + --help -h prints the command usage +USAGE +} + +function unit::run() { + util::print::title "Run Library pack Unit and Example Tests" + + testout=$(mktemp) + pushd "${BUILDPACKDIR}" > /dev/null + if go test ./... -v | tee "${testout}"; then + util::tools::tests::checkfocus "${testout}" + util::print::success "** GO Test Succeeded **" + else + util::print::error "** GO Test Failed **" + fi + popd > /dev/null +} + +main "${@:-}"