Skip to content

Build, Test, Publish #206

Build, Test, Publish

Build, Test, Publish #206

name: Build, Test, Publish
on:
pull_request:
push:
branches: ["builder-18", master]
schedule:
- cron: '0 0 * * 1-5'
workflow_dispatch:
permissions:
contents: read
jobs:
create:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
builder: ["18"]
steps:
- uses: actions/checkout@v3
- uses: buildpacks/github-actions/setup-pack@v5.1.0
# We use a cache here rather than artifacts because it's 4x faster and we
# don't need the .tar.zst outside of this workflow run anyway.
- name: Setup builder cache
uses: actions/cache@v3
with:
key: ${{ github.run_id}}-buildpacks-${{ matrix.builder }}
path: buildpacks-${{ matrix.builder }}.tar.zst
- run: pack builder create buildpacks-${{ matrix.builder }} --config builder-${{ matrix.builder }}.toml --pull-policy if-not-present --verbose
- run: docker save buildpacks-${{ matrix.builder }} | zstd > buildpacks-${{ matrix.builder }}.tar.zst
test-guides:
runs-on: ubuntu-22.04
needs: create
strategy:
fail-fast: false
matrix:
builder: ["buildpacks-18"]
language: ["go", "gradle", "java", "node-js", "php", "python", "ruby", "scala", "typescript"]
steps:
- uses: actions/checkout@v3
with:
ref: main
repository: heroku/${{ matrix.language }}-getting-started.git
- name: Modify package.json (fix for Heroku-18 stack)
if: matrix.language == 'node-js' && matrix.builder == 'buildpacks-18'
run: sed -i 's/18.x || 16.x/16.x/g' package.json
- uses: buildpacks/github-actions/setup-pack@v5.1.0
- name: Modify runtime.txt (fix for Heroku-18 stack)
if: matrix.language == 'python' && matrix.builder == 'buildpacks-18'
run: echo "python-3.10.11" > runtime.txt
- uses: buildpacks/github-actions/setup-pack@v5.1.0
- name: Setup builder cache
uses: actions/cache@v3
with:
key: ${{ github.run_id}}-${{ matrix.builder }}
path: ${{ matrix.builder }}.tar.zst
- name: Load builder image into docker daemon
run: zstd -dc ${{ matrix.builder }}.tar.zst | docker load
- name: Add builder to trusted builders list
run: pack config trusted-builders add ${{ matrix.builder }}
- name: Pull the stack image
env:
BUILDER: ${{ matrix.builder }}
run: docker pull heroku/heroku:${BUILDER##*-}-cnb
- name: Build getting started guide image
run: pack build getting-started --builder ${{ matrix.builder }} --pull-policy if-not-present
- name: Start getting started guide image
run: docker run --name getting-started --detach -p 8080:8080 --env PORT=8080 getting-started
- name: Test getting started web server response
run: |
if curl -sSf --retry 10 --retry-delay 1 --retry-all-errors --connect-timeout 3 http://localhost:8080 -o response.txt; then
echo "Successful response from server"
else
echo "Server did not respond successfully"
docker logs getting-started
[[ -f response.txt ]] && cat response.txt
exit 1
fi
test-examples:
runs-on: ubuntu-22.04
needs: create
strategy:
fail-fast: false
matrix:
builder: ["buildpacks-18"]
example: ["java-function", "javascript-function", "typescript-function"]
steps:
- uses: actions/checkout@v3
- uses: buildpacks/github-actions/setup-pack@v5.1.0
- name: Setup builder cache
uses: actions/cache@v3
with:
key: ${{ github.run_id}}-${{ matrix.builder }}
path: ${{ matrix.builder }}.tar.zst
- name: Load builder image into docker daemon
run: zstd -dc ${{ matrix.builder }}.tar.zst | docker load
- name: Add builder to trusted builders list
run: pack config trusted-builders add ${{ matrix.builder }}
- name: Pull the stack image
env:
BUILDER: ${{ matrix.builder }}
run: docker pull heroku/heroku:${BUILDER##*-}-cnb
- run: pack build example-function --path examples/${{ matrix.example }} --builder ${{ matrix.builder }} --pull-policy if-not-present
- run: docker run --name example-function --detach -p 8080:8080 --env PORT=8080 example-function
- name: Test example function web server response
run: |
if curl -sSf --retry 10 --retry-delay 1 --retry-all-errors --connect-timeout 3 -X POST -H 'x-health-check: true' http://localhost:8080 -o response.txt; then
echo "Successful response from function"
else
echo "Function did not respond successfully"
docker logs example-function
[[ -f response.txt ]] && cat response.txt
exit 1
fi
publish:
runs-on: ubuntu-22.04
if: success() && github.ref == 'refs/heads/master'
needs:
- test-guides
- test-examples
strategy:
fail-fast: false
matrix:
include:
- builder: buildpacks-18
tag_public: fagiani/buildpacks:18
tag_private: heroku-18:builder
steps:
- name: Setup builder cache
uses: actions/cache@v3
with:
key: ${{ github.run_id}}-${{ matrix.builder }}
path: ${{ matrix.builder }}.tar.zst
- run: zstd -dc ${{ matrix.builder }}.tar.zst | docker load
- run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin
- name: Log into additional registry
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ secrets.REGISTRY_HOST }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin
- name: Tag builder and push to registries
run: |
if [[ -n "${{ matrix.tag_private }}" ]]; then
export TAG_PRIVATE="${{ secrets.REGISTRY_HOST }}/${{ secrets.REGISTRY_USER }}/${{ matrix.tag_private }}"
fi
export TAGS=($TAG_PRIVATE ${{ matrix.tag_public }} ${{ matrix.tag_alias }})
for tag in ${TAGS[@]}; do
echo "Pushing $tag"
docker tag ${{ matrix.builder }} $tag
docker push $tag
done