Skip to content

Commit

Permalink
Release Buildpack action (#111)
Browse files Browse the repository at this point in the history
* Release Buildpack action

* Rev version

* Remove extra newline

* Guard against docker double push
  • Loading branch information
schneems authored Jan 31, 2023
1 parent 04136e7 commit 7104c62
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Release Buildpack

on:
workflow_dispatch:

permissions:
contents: write

jobs:
release:
name: Release heroku/ruby
runs-on: ubuntu-20.04 # ubuntu-latest currently resolves to 18.04 which does not have aws-cli 2.x yet
steps:

- id: checkout
name: "Checkout code"
uses: actions/checkout@v3

- id: setup-pack
name: "Setup pack"
uses: buildpacks/github-actions/[email protected]

- name: Install yj
uses: buildpacks/github-actions/[email protected]

- id: install-musl-tools
run: sudo apt-get install musl-tools

- id: install-rust-toolchain
name: "Install Rust toolchain"
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: "x86_64-unknown-linux-musl"

- id: install-libcnb-cargo
name: "Install libcnb-cargo"
uses: actions-rs/[email protected]
with:
crate: libcnb-cargo
version: latest

- id: compile
name: "Compile buildpack"
run: cargo libcnb package --release
working-directory: ./buildpacks/ruby

- id: metadata
name: "Read buildpack metadata"
run: |
export BUILDPACK_PATH="target/buildpack/release/heroku_ruby"
echo "buildpack_path=$BUILDPACK_PATH" >> $GITHUB_ENV
echo "buildpack_id=$(yj -t < $BUILDPACK_PATH/buildpack.toml | jq -r .buildpack.id)" >> $GITHUB_ENV
echo "buildpack_version=$(yj -t < $BUILDPACK_PATH/buildpack.toml | jq -r .buildpack.version)" >> $GITHUB_ENV
echo "buildpack_repo=$(yj -t < $BUILDPACK_PATH/buildpack.toml | jq -r .metadata.release.image.repository)" >> $GITHUB_ENV
echo "buildpack_file=heroku_ruby.cnb" >> $GITHUB_ENV
- id: package-buildpack
name: "Package buildpack"
run: pack buildpack package --path "${{ env.buildpack_path }}" --format file "${{ env.buildpack_file}}"

- id: dockerhub-login
name: "Login to Docker Hub"
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- id: guard-double-publish
name: "Check version is unique on Docker Hub"
run: |
if docker manifest inspect "${{ env.buildpack_repo }}:${{ env.buildpack_version }}" > /dev/null; then
echo "Duplicate version found on dockerhub ${{ env.buildpack_repo }}:${{ env.buildpack_version }}"
exit 1
fi
- id: publish-image
name: "Publish buildpack to image registry"
run: pack buildpack package --path "${{ env.buildpack_path }}" --publish "${{ env.buildpack_repo }}:${{ env.buildpack_version }}"

- id: image-digest
name: "Calculate buildpack image digest"
run: |
echo "buildpack_digest=$(crane digest ${{ env.buildpack_repo }}:${{ env.buildpack_version }})" >> $GITHUB_ENV
- id: add-registry-entry
name: "Request Buildpack Registry Entry"
uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:5.0.1
with:
token: ${{ secrets.CNB_REGISTRY_RELEASE_BOT_GITHUB_TOKEN }}
id: ${{ env.buildpack_id }}
version: ${{ env.buildpack_version }}
address: ${{ env.buildpack_repo }}@${{ env.buildpack_digest }}

- id: create_release
name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.buildpack_id }}_${{ env.buildpack_version }}
release_name: ${{ env.buildpack_id }} ${{ env.buildpack_version }}
body: |
See the [CHANGELOG](./CHANGELOG.md) for details.
draft: false
prerelease: false

- id: upload_package
name: Upload buildpackage to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.buildpack_file }}
tag: ${{ env.buildpack_id }}_${{ env.buildpack_version }}
overwrite: true
7 changes: 7 additions & 0 deletions buildpacks/ruby/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ id = "heroku-22"

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

[metadata]

[metadata.release]

[metadata.release.image]
repository = "docker.io/heroku/buildpack-ruby"

0 comments on commit 7104c62

Please sign in to comment.