Skip to content

Commit 6db1b5f

Browse files
paketo-botryanmoran
authored andcommitted
Update github-config to e6896a0
1 parent 1000cac commit 6db1b5f

4 files changed

Lines changed: 114 additions & 110 deletions

File tree

.github/workflows/create-release.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
id: tag
4949
uses: paketo-buildpacks/github-config/actions/tag@master
5050
- name: Package
51-
run: PACKAGE_DIR=artifact ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}" --archive
51+
run: ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}"
5252
- name: Create Release Notes
5353
id: create-release-notes
5454
run: |
@@ -59,7 +59,7 @@ jobs:
5959
--location \
6060
--output "${HOME}/bin/jam"
6161
chmod +x "${HOME}/bin/jam"
62-
RELEASE_BODY=$(jam summarize --buildpack "${PWD}/artifact.tgz" --format markdown)
62+
RELEASE_BODY=$(jam summarize --buildpack "${PWD}/build/buildpack.tgz" --format markdown)
6363
# Coz of this messed up issue
6464
# https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/m-p/38372#M3322
6565
RELEASE_BODY="${RELEASE_BODY//'%'/'%25'}"
@@ -79,8 +79,13 @@ jobs:
7979
assets: |
8080
[
8181
{
82-
"path": "artifact.tgz",
82+
"path": "build/buildpack.tgz",
8383
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz",
8484
"content_type": "application/gzip"
85+
},
86+
{
87+
"path": "build/buildpackage.cnb",
88+
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.cnb",
89+
"content_type": "application/gzip"
8590
}
8691
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Push Buildpackage
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
push:
9+
name: Push
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Download
13+
id: download
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
16+
uses: paketo-buildpacks/github-config/actions/buildpackage/download@master
17+
- name: Push
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
20+
GCR_PUSH_BOT_JSON_KEY: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
21+
run: |
22+
echo "${GCR_PUSH_BOT_JSON_KEY}" | docker login --username _json_key --password-stdin gcr.io
23+
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/${{ steps.download.outputs.buildpackage }}" "docker://gcr.io/${{ github.repository }}:${{ steps.download.outputs.tag }}"
24+
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/${{ steps.download.outputs.buildpackage }}" "docker://gcr.io/${{ github.repository }}:latest"

scripts/.util/tools.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ set -o pipefail
66
# shellcheck source=./print.sh
77
source "$(dirname "${BASH_SOURCE[0]}")/print.sh"
88

9-
# shellcheck source=./git.sh
10-
source "$(dirname "${BASH_SOURCE[0]}")/git.sh"
11-
129
function util::tools::path::export() {
1310
local dir
1411
dir="${1}"
@@ -101,7 +98,7 @@ function util::tools::pack::install() {
10198
version="v0.10.0"
10299

103100
util::print::title "Installing pack ${version}"
104-
curl "https://github.com/buildpacks/pack/releases/download/${version}/pack-v0.10.0-${os}.tgz" \
101+
curl "https://github.com/buildpacks/pack/releases/download/${version}/pack-${version}-${os}.tgz" \
105102
--silent \
106103
--location \
107104
--output /tmp/pack.tgz
@@ -130,6 +127,6 @@ function util::tools::packager::install () {
130127

131128
if [[ ! -f "${dir}/packager" ]]; then
132129
util::print::title "Installing packager"
133-
GOBIN="${dir}" go get github.com/cloudfoundry/libcfbuildpack/packager
130+
GOBIN="${dir}" go get -u github.com/cloudfoundry/libcfbuildpack/packager
134131
fi
135132
}

scripts/package.sh

Lines changed: 80 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,92 @@
1-
#!/usr/bin/env bash
2-
set -eu
1+
#!/bin/bash
2+
3+
set -e
4+
set -u
35
set -o pipefail
46

5-
readonly PROGDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6-
readonly BUILDPACKDIR="$(cd "${PROGDIR}/.." && pwd)"
7+
readonly ROOT_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
8+
readonly BIN_DIR="${ROOT_DIR}/.bin"
9+
readonly BUILD_DIR="${ROOT_DIR}/build"
710

811
# shellcheck source=.util/tools.sh
9-
source "${PWD}/scripts/.util/tools.sh"
12+
source "${ROOT_DIR}/scripts/.util/tools.sh"
1013

1114
# shellcheck source=.util/print.sh
12-
source "${PWD}/scripts/.util/print.sh"
13-
14-
if ! command -v realpath > /dev/null; then
15-
function realpath() {
16-
[[ "${1}" = /* ]] && echo "${1}" || echo "${PWD}/${1#./}"
17-
}
18-
fi
19-
20-
function main() {
21-
local full_path args version cached archive offline
22-
PACKAGE_DIR=${PACKAGE_DIR:-"${BUILDPACKDIR}/$(basename ${BUILDPACKDIR})_$(openssl rand -hex 4)"}
23-
24-
full_path="$(realpath "${PACKAGE_DIR}")"
25-
26-
while [[ "${#}" != 0 ]]; do
27-
case "${1}" in
28-
--archive|-a)
29-
archive="true"
30-
shift 1
31-
;;
32-
33-
--cached|-c)
34-
cached="true"
35-
offline="true"
36-
shift 1
37-
;;
38-
39-
--version|-v)
40-
version="${2}"
41-
shift 2
42-
;;
43-
44-
"")
45-
# skip if the argument is empty
46-
shift 1
47-
;;
48-
49-
*)
50-
util::print::error "unknown argument \"${1}\""
51-
esac
52-
done
53-
54-
if [[ -f "${BUILDPACKDIR}/.packit" ]]; then
55-
#use jam
56-
util::tools::jam::install --directory "${BUILDPACKDIR}/.bin"
57-
if [[ -z "${version:-}" ]]; then #version not provided, use latest git tag
58-
git_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)" || echo "v0.0.0")
59-
version=${git_tag:1}
60-
fi
61-
62-
extra_args=""
63-
64-
if [[ -n "${offline:-}" ]]; then
65-
PACKAGE_DIR="${PACKAGE_DIR}-cached"
66-
extra_args+="--offline"
67-
fi
68-
69-
if [[ "${PACKAGE_DIR}" != "*.tgz" ]]; then
70-
PACKAGE_DIR="${PACKAGE_DIR}.tgz"
71-
fi
72-
73-
74-
.bin/jam pack \
75-
--buildpack "$(pwd)/buildpack.toml" \
76-
--version "${version}" \
77-
--output "${PACKAGE_DIR}" \
78-
${extra_args}
79-
80-
else
81-
# use old packager
82-
util::tools::packager::install --directory "${BUILDPACKDIR}/.bin"
83-
84-
args="${BUILDPACKDIR}/.bin/packager"
85-
if [[ -n "${cached:-}" ]]; then
86-
full_path="${full_path}-cached"
87-
else
88-
args="${args} --uncached"
89-
fi
90-
91-
if [[ -n "${archive:-}" ]]; then
92-
args="${args} -archive"
93-
fi
94-
95-
if [[ -z "${version:-}" ]]; then
96-
version="$(cd "${BUILDPACKDIR}" && git describe --tags "$(git rev-list --tags --max-count=1)" || echo "v0.0.0")"
97-
fi
98-
99-
args="${args} -version ${version}"
100-
101-
pushd "${BUILDPACKDIR}" > /dev/null
102-
eval "${args}" "${full_path}"
103-
popd > /dev/null
104-
105-
if [[ -n "${BP_REWRITE_HOST:-}" ]]; then
106-
sed -i '' -e "s|^uri = \"https:\/\/buildpacks\.cloudfoundry\.org\(.*\)\"$|uri = \"http://${BP_REWRITE_HOST}\1\"|g" "${full_path}/buildpack.toml"
107-
fi
108-
fi
15+
source "${ROOT_DIR}/scripts/.util/print.sh"
16+
17+
function main {
18+
local version
19+
20+
while [[ "${#}" != 0 ]]; do
21+
case "${1}" in
22+
--version|-v)
23+
version="${2}"
24+
shift 2
25+
;;
26+
27+
"")
28+
# skip if the argument is empty
29+
shift 1
30+
;;
31+
32+
*)
33+
util::print::error "unknown argument \"${1}\""
34+
esac
35+
done
36+
37+
if [[ "${version:-}" == "" ]]; then
38+
util::print::error "--version is required"
39+
fi
40+
41+
repo::prepare
42+
buildpack::archive "${version}"
43+
buildpackage::create
44+
}
45+
46+
function repo::prepare() {
47+
util::print::title "Preparing repo..."
48+
49+
rm -rf "${BUILD_DIR}"
50+
51+
mkdir -p "${BIN_DIR}"
52+
mkdir -p "${BUILD_DIR}"
53+
54+
export PATH="${BIN_DIR}:${PATH}"
55+
}
56+
57+
function buildpack::archive() {
58+
local version
59+
version="${1}"
60+
61+
util::print::title "Packaging buildpack into ${BUILD_DIR}/buildpack.tgz..."
62+
63+
if [[ -f "${ROOT_DIR}/.packit" ]]; then
64+
util::tools::jam::install --directory "${BIN_DIR}"
65+
66+
jam pack \
67+
--buildpack "${ROOT_DIR}/buildpack.toml" \
68+
--version "${version}" \
69+
--output "${BUILD_DIR}/buildpack.tgz"
70+
else
71+
util::tools::packager::install --directory "${BIN_DIR}"
72+
73+
packager \
74+
--uncached \
75+
--archive \
76+
--version "${version}" \
77+
"${BUILD_DIR}/buildpack"
78+
fi
79+
}
10980

81+
function buildpackage::create() {
82+
util::print::title "Packaging buildpack..."
11083

84+
util::tools::pack::install --directory "${BIN_DIR}"
11185

86+
pack \
87+
package-buildpack "${BUILD_DIR}/buildpackage.cnb" \
88+
--package-config "${ROOT_DIR}/package.toml" \
89+
--format file
11290
}
11391

11492
main "${@:-}"

0 commit comments

Comments
 (0)