Skip to content

Commit

Permalink
Use the shared GitHub Actions workflows for buildpack releases (#156)
Browse files Browse the repository at this point in the history
* Use the shared release automation for the Procfile buildpack

This sets up the release automation scripts from [languages-github-actions](https://github.com/heroku/languages-github-actions) for the Procfile buildpack.

Also in this PR:
* adds the target Docker repository to `buildpack.toml` to align with the metadata used by other Heroku buildpacks

[W-13658758](https://gus.lightning.force.com/a07EE00001UkuZgYAJ)

* Update prepare-release.yml

* Update prepare-release.yml

* Update release.yml

* Update buildpack.toml

* Apply suggestions from code review

* Update README.md

---------

Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
  • Loading branch information
colincasey and edmorley authored Aug 3, 2023
1 parent 97aa913 commit 8dd9e1f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 121 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Prepare Buildpack Release

on:
workflow_dispatch:
inputs:
bump:
description: "Bump"
required: true
default: "patch"
type: choice
options:
- major
- minor
- patch

jobs:
prepare-release:
uses: heroku/languages-github-actions/.github/workflows/_buildpacks-prepare-release.yml@main
with:
bump: ${{ inputs.bump }}
app_id: ${{ vars.LINGUIST_GH_APP_ID }}
secrets:
app_private_key: ${{ secrets.LINGUIST_GH_PRIVATE_KEY }}
114 changes: 12 additions & 102 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,106 +1,16 @@
name: release
name: Release Buildpack

# Allow the action to be triggered manually in the "actions"
# tab of GitHub.
on:
workflow_dispatch
workflow_dispatch:

jobs:
release:
name: Package, Publish, and Register
runs-on:
- ubuntu-22.04
permissions:
contents: write
steps:
# Needed to get the buildpack code
- name: Checkout
uses: actions/checkout@v3

# Install musl gcc needed to compile rust buildpack
# to linux musl target
- name: Install musl-tools
run: sudo apt-get install musl-tools --no-install-recommends

# Get the `pack` command for packaging the buildpack
- id: setup-pack
name: Install Pack
uses: buildpacks/github-actions/setup-pack@v5.3.0

- name: Install yj
uses: buildpacks/github-actions/setup-tools@v5.3.0

# Used by `pack buildpack package --publish`. The buildpack
# will be published to this user and password
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

# Most of the time this will be a no-op, since GitHub releases new images every week
# which include the latest stable release of Rust, Rustup, Clippy and rustfmt.
- name: Update Rust toolchain
run: rustup update
- name: Rust Cache
uses: Swatinem/rust-cache@v2.5.1

# Needed to get `cargo libcnb package` command
- name: Install libcnb plugin
run: cargo install libcnb-cargo
# Configure Rust so it knows how to compile to the linux musl target
- name: Install Rust linux-musl target
run: rustup target add x86_64-unknown-linux-musl
# Compile the rust buildpack
- id: package-libcnb-rs
run: cargo libcnb package --release

# Pull out data from the buildpacks `buildpack.toml` to make
# it available to other commands. Also package and publish
# the buildpack to docker hub as well as generate a local
# file containing the buildpack.
- id: package
run: |
#!/usr/bin/env bash
set -euo pipefail
BP_ID="$(cat buildpack.toml | yj -t | jq -r .buildpack.id)"
VERSION="$(cat buildpack.toml | yj -t | jq -r .buildpack.version)"
ESCAPED_ID="$(echo "$BP_ID" | sed 's/\//_/g')"
PACKAGE="${REPO}"
# --publish pushes to the registry (logged in)
pack buildpack package --publish --path "target/buildpack/release/$ESCAPED_ID" "${PACKAGE}:${VERSION}"
pack buildpack package --format file --path "target/buildpack/release/$ESCAPED_ID" "${ESCAPED_ID}_${VERSION}.cnb"
DIGEST="$(crane digest ${PACKAGE}:${VERSION})"
echo "::set-output name=bp_id::$BP_ID"
echo "::set-output name=version::$VERSION"
echo "::set-output name=tag_name::v${VERSION}"
echo "::set-output name=address::${PACKAGE}@${DIGEST}"
echo "::set-output name=package::${ESCAPED_ID}_${VERSION}.cnb"
env:
REPO: docker.io/heroku/procfile-cnb

# Open a PR to the buildpack registry index.
# For example: https://github.com/buildpacks/registry-index/issues/2776
- id: register
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:4.2.0
with:
token: ${{ secrets.CNB_REGISTRY_RELEASE_BOT_GITHUB_TOKEN }}
id: ${{ steps.package.outputs.bp_id }}
version: ${{ steps.package.outputs.version }}
address: ${{ steps.package.outputs.address }}

# Create a release and tag on the github repo
# For example: https://github.com/heroku/procfile-cnb/releases/tag/v1.0.1
# Attaches the previously generated cloud native buildpack file (`*.cnb`)
# to the release
- id: release
name: Upload build package to release
uses: svenstaro/upload-release-action@2.7.0
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ steps.package.outputs.package }}
tag: ${{ steps.package.outputs.tag_name }}
overwrite: true
release:
name: Release
uses: heroku/languages-github-actions/.github/workflows/_buildpacks-release.yml@main
with:
app_id: ${{ vars.LINGUIST_GH_APP_ID }}
secrets:
app_private_key: ${{ secrets.LINGUIST_GH_PRIVATE_KEY }}
cnb_registry_token: ${{ secrets.CNB_REGISTRY_RELEASE_BOT_GITHUB_TOKEN }}
docker_hub_user: ${{ secrets.DOCKER_HUB_USER }}
docker_hub_token: ${{ secrets.DOCKER_HUB_TOKEN }}
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ This is a [Cloud Native Buildpack](https://buildpacks.io/) that replicates the b

It is written in Rust using the Cloud Native Buildpack framework [libcnb.rs](https://github.com/heroku/libcnb.rs).

## Deployment

### 0) Prerelease

- Ensure that the version in `buildpack.toml` is correct. The following deployment steps will create a release with the that version number.
- Ensure there's an entry for the same version in `CHANGELOG.md`.

### 1) Generate a release

- Visit the actions page https://github.com/heroku/procfile-cnb/actions,
- Click on "release" and then "Run workflow".

When the action is successful a release will be added to https://github.com/heroku/procfile-cnb/releases and docker hub https://hub.docker.com/r/heroku/procfile-cnb/tags.

### 2) Update builders

Heroku builders (github.com/heroku/builders) must be updated to the latest
version of the buildpack. A detailed procedure is available [here](github.com/heroku/languages-team/blob/main/languages/cnb/deploy.md#update-builder-images).

## Development

### Prerequisites
Expand Down Expand Up @@ -67,3 +48,7 @@ Processes:
web (default) bash echo 'this is the web process!' /workspace
worker bash echo 'this is the worker process!' /workspace
```

## Releasing

[Deploy Cloud Native Buildpacks](https://github.com/heroku/languages-team/blob/main/languages/cnb/deploy.md)
3 changes: 3 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ id = "*"

[[buildpack.licenses]]
type = "BSD-3-Clause"

[metadata.release]
image = { repository = "docker.io/heroku/procfile-cnb" }

0 comments on commit 8dd9e1f

Please sign in to comment.