Skip to content

Commit

Permalink
Bootstraps with github-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran committed May 20, 2021
1 parent 0ef51a9 commit 02e6d97
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 63 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
45 changes: 45 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Auto-Merge

on:
repository_dispatch:
types:
- approve-bot-pr

jobs:
automerge:
name: Merge or Rebase
if: ${{ github.event.client_payload.login == 'cf-buildpacks-eng' || github.event.client_payload.login == 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Fetch Pull Request Details
id: pull_request
env:
NUMBER: ${{ github.event.client_payload.number }}
GITHUB_TOKEN: ${{ secrets.CF_BOT_TOKEN }}
run: |
payload="$(
curl "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${NUMBER}" \
--silent \
--location \
--header "Authorization: token ${GITHUB_TOKEN}"
)"
echo "::set-output name=mergeable_state::$(echo "${payload}" | jq -r -c .mergeable_state)"
- name: Merge
if: ${{ steps.pull_request.outputs.mergeable_state == 'clean' || steps.pull_request.outputs.mergeable_state == 'unstable' }}
uses: paketo-buildpacks/github-config/actions/pull-request/merge@main
with:
token: ${{ secrets.CF_BOT_TOKEN }}
number: ${{ github.event.client_payload.number }}

- name: Rebase
if: ${{ steps.pull_request.outputs.mergeable_state == 'behind' }}
uses: paketo-buildpacks/github-config/actions/pull-request/rebase@main
with:
token: ${{ secrets.CF_BOT_TOKEN }}
number: ${{ github.event.client_payload.number }}
66 changes: 66 additions & 0 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test Pull Request

on:
pull_request:
branches:
- main

jobs:
integration:
name: Unit Tests
runs-on: ubuntu-latest
steps:

- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.16

- name: Checkout
uses: actions/checkout@v2

- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true

- name: Run Unit Tests
run: ./scripts/unit.sh

approve:
name: Approve Bot PRs
if: ${{ github.event.pull_request.user.login == 'cf-buildpacks-eng' || github.event.pull_request.user.login == 'dependabot[bot]' }}
runs-on: ubuntu-latest
needs: integration
steps:

- name: Check Commit Verification
id: unverified-commits
uses: paketo-buildpacks/github-config/actions/pull-request/check-unverified-commits@main
with:
token: ${{ secrets.CF_BOT_TOKEN }}
repo: ${{ github.repository }}
number: ${{ github.event.number }}

- name: Check for Human Commits
id: human-commits
uses: paketo-buildpacks/github-config/actions/pull-request/check-human-commits@main
with:
token: ${{ secrets.CF_BOT_TOKEN }}
repo: ${{ github.repository }}
number: ${{ github.event.number }}
bots: 'dependabot[bot],web-flow,cf-buildpacks-eng'

- name: Checkout
if: steps.human-commits.outputs.human_commits == 'false' && steps.unverified-commits.outputs.unverified_commits == 'false'
uses: actions/checkout@v2

- name: Dispatch
if: steps.human-commits.outputs.human_commits == 'false' && steps.unverified-commits.outputs.unverified_commits == 'false'
uses: paketo-buildpacks/github-config/actions/dispatch@main
with:
repos: ${{ github.repository }}
token: ${{ secrets.CF_BOT_TOKEN }}
event: approve-bot-pr
payload: |
{
"number": "${{ github.event.pull_request.number }}",
"login": "${{ github.event.pull_request.user.login }}"
}
65 changes: 65 additions & 0 deletions .github/workflows/update-github-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Update shared github-config

on:
schedule:
- cron: '*/15 * * * *'
workflow_dispatch: {}

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

- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.CF_BOT_GITHUB_TOKEN }}
ref: develop

- name: Checkout github-config
uses: actions/checkout@v2
with:
repository: cloudfoundry/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/buildpack

- 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: "."
committer_name: "Cloud Foundry Buildpacks Team Robot"
committer_email: "cf-buildpacks-eng@pivotal.io"
keyid: ${{ secrets.CF_BOT_GPG_KEY_ID }}
key: ${{ secrets.CF_BOT_GPG_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.CF_BOT_GITHUB_TOKEN }}
title: "Updates github-config"
branch: automation/github-config/update
base: develop

34 changes: 25 additions & 9 deletions scripts/brats.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$( dirname "${BASH_SOURCE[0]}" )/.."
source .envrc
./scripts/install_tools.sh
set -e
set -u
set -o pipefail

ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

GINKGO_NODES=${GINKGO_NODES:-3}
GINKGO_ATTEMPTS=${GINKGO_ATTEMPTS:-1}
export CF_STACK=${CF_STACK:-cflinuxfs3}
source "${ROOTDIR}/.envrc"

cd src/binary/brats
ginkgo -r -mod vendor --flakeAttempts=$GINKGO_ATTEMPTS -nodes $GINKGO_NODES --slowSpecThreshold=60
function main() {
local src
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"

"${ROOTDIR}/scripts/install_tools.sh"


echo "Run Buildpack Runtime Acceptance Tests"

CF_STACK="${CF_STACK:-cflinuxfs3}" \
ginkgo \
-r \
-mod vendor \
--flakeAttempts "${GINKGO_ATTEMPTS:-2}" \
-nodes "${GINKGO_NODES:-3}" \
"${src}/brats"
}

main "${@:-}"
32 changes: 25 additions & 7 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
#!/usr/bin/env bash
set -exuo pipefail

cd "$( dirname "${BASH_SOURCE[0]}" )/.."
source .envrc
set -e
set -u
set -o pipefail

GOOS=linux go build -mod=vendor -ldflags="-s -w" -o bin/supply ./src/binary/supply/cli
GOOS=linux go build -mod=vendor -ldflags="-s -w" -o bin/finalize ./src/binary/finalize/cli
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

GOOS=windows go build -mod=vendor -ldflags="-s -w" -o bin/supply.exe ./src/binary/supply/cli
GOOS=windows go build -mod=vendor -ldflags="-s -w" -o bin/finalize.exe ./src/binary/finalize/cli
function main() {
local src
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"

IFS=" " read -r -a binaries <<< "$(find "${src}" -name cli -type d -print0 | xargs -0)"

for path in "${binaries[@]}"; do
local name
name="$(basename "$(dirname "${path}")")"

GOOS=linux \
go build \
-mod vendor \
-ldflags="-s -w" \
-o "${ROOTDIR}/bin/${name}" \
"${path}"
done
}

main "${@:-}"
66 changes: 41 additions & 25 deletions scripts/install_go.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
#!/bin/bash

set -euo pipefail
set -e
set -u
set -o pipefail

function main() {
if [[ "${CF_STACK:-}" != "cflinuxfs3" ]]; then
echo " **ERROR** Unsupported stack"
echo " See https://docs.cloudfoundry.org/devguide/deploy-apps/stacks.html for more info"
exit 1
fi

GO_VERSION="1.15.5"
local version expected_sha dir
version="1.15.5"
expected_sha="fd04494f7a2dd478b0d31cb949aae7f154749cae1242581b1574f7e590b3b7e6"
dir="/tmp/go${version}"

if [ $CF_STACK == "cflinuxfs3" ]; then
GO_SHA256="fd04494f7a2dd478b0d31cb949aae7f154749cae1242581b1574f7e590b3b7e6"
else
echo " **ERROR** Unsupported stack"
echo " See https://docs.cloudfoundry.org/devguide/deploy-apps/stacks.html for more info"
exit 1
fi
mkdir -p "${dir}"

export GoInstallDir="/tmp/go$GO_VERSION"
mkdir -p $GoInstallDir
if [[ ! -f "${dir}/go/bin/go" ]]; then
local url
url="https://buildpacks.cloudfoundry.org/dependencies/go/go_${version}_linux_x64_${CF_STACK}_${expected_sha:0:8}.tgz"

if [ ! -f $GoInstallDir/go/bin/go ]; then
URL=https://buildpacks.cloudfoundry.org/dependencies/go/go_${GO_VERSION}_linux_x64_${CF_STACK}_${GO_SHA256:0:8}.tgz
echo "-----> Download go ${version}"
curl "${url}" \
--silent \
--location \
--retry 15 \
--retry-delay 2 \
--output "/tmp/go.tgz"

echo "-----> Download go ${GO_VERSION}"
curl -s -L --retry 15 --retry-delay 2 $URL -o /tmp/go.tgz
local sha
sha="$(shasum -a 256 /tmp/go.tgz | cut -d ' ' -f 1)"

DOWNLOAD_SHA256=$(shasum -a 256 /tmp/go.tgz | cut -d ' ' -f 1)
if [[ "${sha}" != "${expected_sha}" ]]; then
echo " **ERROR** SHA256 mismatch: got ${sha}, expected ${expected_sha}"
exit 1
fi

tar xzf "/tmp/go.tgz" -C "${dir}"
rm "/tmp/go.tgz"
fi

if [[ $DOWNLOAD_SHA256 != $GO_SHA256 ]]; then
echo " **ERROR** SHA256 mismatch: got $DOWNLOAD_SHA256 expected $GO_SHA256"
if [[ ! -f "${dir}/bin/go" ]]; then
echo " **ERROR** Could not download go"
exit 1
fi

tar xzf /tmp/go.tgz -C $GoInstallDir
rm /tmp/go.tgz
fi
GoInstallDir="${dir}"
export GoInstallDir
}

if [ ! -f $GoInstallDir/bin/go ]; then
echo " **ERROR** Could not download go"
exit 1
fi
main "${@:-}"
25 changes: 18 additions & 7 deletions scripts/install_tools.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/bin/bash
set -euo pipefail

cd "$( dirname "${BASH_SOURCE[0]}" )/.."
source .envrc
set -e
set -u
set -o pipefail

go get -u github.com/onsi/ginkgo/ginkgo
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

if [ ! -f .bin/buildpack-packager ]; then
go install github.com/cloudfoundry/libbuildpack/packager/buildpack-packager
fi
source "${ROOTDIR}/.envrc"

function main() {
pushd "${ROOTDIR}" > /dev/null || return
go get -u github.com/onsi/ginkgo/ginkgo

if [[ ! -f "${ROOTDIR}/.bin/buildpack-packager" ]]; then
go install github.com/cloudfoundry/libbuildpack/packager/buildpack-packager
fi
popd > /dev/null || return
}

main "${@:-}"

0 comments on commit 02e6d97

Please sign in to comment.