Skip to content

Commit

Permalink
Add update-github-config workflow to sync from github-config/library
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatcasey authored and ryanmoran committed Sep 9, 2022
1 parent 9c33469 commit 54dcc85
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/.patch_files
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.github/workflows/approve-bot-pr.yml
.github/workflows/codeql-analysis.yml
.github/workflows/lint.yml
.github/workflows/update-github-config.yml
.github/workflows/create-draft-release.yml
.github/workflows/test-pull-request.yml
.github/workflows/lint-yaml.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Run Unit Tests
run: go test -v -count=1 ./...
run: ./scripts/unit.sh

release:
name: Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v3

- name: Run Unit Tests
run: go test -v -count=1 ./...
run: ./scripts/unit.sh

upload:
name: Upload Workflow Event Payload
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/update-github-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Update shared github-config

on:
schedule:
- cron: '30 1 * * *'
workflow_dispatch: {}

concurrency: github_config_update

jobs:
build:
name: Create PR to update shared files
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}

- name: Checkout github-config
uses: actions/checkout@v3
with:
repository: paketo-buildpacks/github-config
path: github-config

- name: Checkout Branch
uses: paketo-buildpacks/github-config/actions/pull-request/checkout-branch@main
with:
branch: automation/github-config/update

- name: Run the sync action
uses: paketo-buildpacks/github-config/actions/sync@main
with:
workspace: /github/workspace
config: /github/workspace/github-config/library

- name: Cleanup
run: rm -rf github-config

- name: Commit
id: commit
uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main
with:
message: "Updating github-config"
pathspec: "."
keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }}
key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }}

- name: Push Branch
if: ${{ steps.commit.outputs.commit_sha != '' }}
uses: paketo-buildpacks/github-config/actions/pull-request/push-branch@main
with:
branch: automation/github-config/update

- 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 github-config"
branch: automation/github-config/update
21 changes: 21 additions & 0 deletions scripts/.util/git.sh
Original file line number Diff line number Diff line change
@@ -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}"
}
51 changes: 51 additions & 0 deletions scripts/.util/print.sh
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions scripts/.util/tools.sh
Original file line number Diff line number Diff line change
@@ -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}"
}
80 changes: 80 additions & 0 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/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"

# shellcheck source=SCRIPTDIR/.util/git.sh
source "${PROGDIR}/.util/git.sh"

function main() {
while [[ "${#}" != 0 ]]; do
case "${1}" in
--use-token|-t)
shift 1
token::fetch
;;

--help|-h)
shift 1
usage
exit 0
;;

"")
# 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 **"
fi

tests::run
}

function usage() {
cat <<-USAGE
integration.sh [OPTIONS]
Runs the integration test suite.
OPTIONS
--help -h prints the command usage
--use-token -t use GIT_TOKEN from lastpass
USAGE
}

function token::fetch() {
GIT_TOKEN="$(util::git::token::fetch)"
export GIT_TOKEN
}

function tests::run() {
util::print::title "Run Library Integration Tests"

testout=$(mktemp)
pushd "${BUILDPACKDIR}" > /dev/null
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | 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 "${@:-}"
62 changes: 62 additions & 0 deletions scripts/unit.sh
Original file line number Diff line number Diff line change
@@ -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 -run "Unit|Example" | 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 "${@:-}"

0 comments on commit 54dcc85

Please sign in to comment.