Skip to content

Commit

Permalink
feat: Release workflow
Browse files Browse the repository at this point in the history
Creates packages for a variety of OS's in appropriate package format, such as
dpkg. Creates a gitflow release of that package, and then bumps crate versions
to indicate a release, creating a tag for that release.
  • Loading branch information
dbcfd committed Sep 7, 2023
1 parent 4f7fe5d commit a47cd1b
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 9 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# CI that:
#
# * checks for a Git Tag that looks like a release ("v1.2.0")
# * creates a Github Release™️
# * builds binaries/packages with cargo-dist
# * uploads those packages to the Github Release™️
#
# Note that the Github Release™️ will be created before the packages,
# so there will be a few minutes where the release has no packages
# and then they will slowly trickle in, possibly failing. To make
# this more pleasant we mark the release as a "draft" until all
# artifacts have been successfully uploaded. This allows you to
# choose what to do with partial successes and avoids spamming
# anyone with notifications before the release is actually ready.
name: Release

permissions:
contents: write

on:
workflow_dispatch:
inputs:
level:
description: 'Release level'
required: true
default: 'minor'
type: choice
options:
- patch
- minor
- major

jobs:
# Build and packages all the things
build-binaries:
strategy:
matrix:
# For these target platforms
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
arch: x86_64
ext: deb
- target: x86_64-apple-darwin
os: macos-latest
arch: x86_64
ext: pkg
- target: aarch64-apple-darwin
os: macos-latest
config-file: fpm/osx.fpm
arch: aarch64
ext: pkg
#- target: x86_64-pc-windows-msvc
# os: windows-latest
runs-on: ${{ matrix.os }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Install Rust
run: |
rustup update stable
rustup default stable
- name: Setup target
run: rustup target add ${{ matrix.target }}
- name: Install ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2' # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Install fpm
run: |
gem install fpm
- name: Run package script
run: |
./ci-scripts/packages.sh --arch ${{ matrix.arch }} --ext ${{ matrix.ext }}
- name: Archive artifact
uses: actions/upload-artifact@v3
with:
name: ceramic-one_${{ matrix.target }}
path: ceramic-one.${{ matrix.ext }}

release:
needs: [build-binaries]
runs-on: ubuntu-latest
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: check artifacts
run: |
ls artifacts/**/*
- id: install-cargo-release
uses: taiki-e/install-action@v1
with:
tool: cargo-release
- id: release
run: |
./ci-scripts/release.sh --level ${{ inputs.level }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/target
*/target
/artifacts

.DS_Store
.idea
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ For example, to enable debug logging for code from this repo but error logging f

$ RUST_LOG=ERROR,ceramic_kubo_rpc=DEBUG,ceramic_one=DEBUG cargo run -p ceramic-one -- daemon

## Packaging
To package rust-ceramic, you will need the following dependencies

* [jq](https://jqlang.github.io/jq/)
* [FPM](https://fpm.readthedocs.io/en/v1.15.1/) - `gem install fpm`
* Dependent on your system, you might also need [ruby](https://www.ruby-lang.org/en/)

You can then run the [package script](./ci-scripts/package.sh) to generate a package for your operating system.

## Releasing
To release rust-ceramic, you will need the following dependencies

* [git cliff](https://git-cliff.org/docs/installation/crates-io)
* [cargo-release](https://github.com/crate-ci/cargo-release)
* [gh client](https://cli.github.com/)

When releasing, please release at the appropriate level

* `patch` -> binary compatible, no new functionality
* `minor` (default) -> binary incompatible or binary compatible with new functionality
* `major` -> breaking functionality

You will also need to login with the `gh` client to your github account, and that account needs permission to perform
a release of the rust-ceramic repository.

You can then run the [release script](./ci-scripts/release.sh) to create a release of rust-ceramic.

## Contributing

We are happy to accept small and large contributions, feel free to make a suggestion or submit a pull request.
Expand Down
2 changes: 1 addition & 1 deletion api-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To see how to make this your own, look here:
[README]((https://openapi-generator.tech))

- API version: 0.1.0
- Build date: 2023-08-30T15:31:27.893-06:00[America/Denver]
- Build date: 2023-09-07T12:35:13.405-06:00[America/Denver]



Expand Down
1 change: 1 addition & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
publish = false

[dependencies]
anyhow.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion ci-scripts/check_api_server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Script to generate api-server crate from OpenAPI definition.

DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down
2 changes: 1 addition & 1 deletion ci-scripts/check_kubo_rpc_server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Script to generate kubo-rpc-server crate from OpenAPI definition.

DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down
2 changes: 1 addition & 1 deletion ci-scripts/gen_api_server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Script to generate api-server crate from OpenAPI definition.

DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down
2 changes: 1 addition & 1 deletion ci-scripts/gen_kubo_rpc_server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Script to generate kubo-server crate from OpenAPI definition.

set -e
Expand Down
76 changes: 76 additions & 0 deletions ci-scripts/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# Script to package our application for distribution.
VALID_ARGS=$(getopt -o fedia: --long config-file,extension,binary-dir,install-dir,architecture: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi

EXT="deb"
PKG_TYPE="dpkg"
CONFIG_FILE="fpm/linux.fpm"
INSTALL_DIR="/usr/local/bin"
TARGET="x86_64-unknown-linux-gnu"

ARCH=""
case $(uname -m) in
x86_64) ARCH="x86_64" ;;
arm64) ARCH="aarch64" ;;
--)
echo "Unknown architecture $(uname -m)"
exit 1
;;
esac

if [[ "$OSTYPE" == "darwin"* ]]; then
CONFIG_FILE="fpm/osx.fpm"
EXT="pkg"
PKG_TYPE="osxpkg"
INSTALL_DIR="/Applications"
TARGET=$ARCH"-apple-darwin"
fi

eval set -- "$VALID_ARGS"
while [ : ]; do
case "$1" in
-f | --config-file)
CONFIG_FILE=$2
shift 2
;;
-e | --extension)
EXT=$2
shift 2
;;
-d | --binary-dir)
BIN_DIR=$2
shift 2
;;
-i | --install-dir)
INSTALL_DIR=$2
shift 2
;;
-a | --architecture)
ARCH=$2
shift 2
;;
--) shift;
break
;;
esac
done

ARTIFACTS_DIR=artifacts
OUT_FILE=$ARTIFACTS_DIR/ceramic-one.$EXT
PKG_VERSION=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"')
BIN_DIR=target/$TARGET/release

if [ -f $OUT_FILE ]; then
rm $OUT_FILE
fi

echo "Building package for "$TARGET

cargo build --release --target $TARGET

mkdir $ARTIFACTS_DIR || true

fpm --fpm-options-file $CONFIG_FILE -C $BIN_DIR -v $PKG_VERSION -p $OUT_FILE ceramic-one=$INSTALL_DIR/ceramic-one
2 changes: 1 addition & 1 deletion ci-scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# Build and publish a docker image run running ceramic-one
#
Expand Down
47 changes: 47 additions & 0 deletions ci-scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Check specified release level based on commit messages, then if appropriate, release package
VALID_ARGS=$(getopt -o l: --long level: -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi

LEVEL=minor

eval set -- "$VALID_ARGS"
while [ : ]; do
case "$1" in
-l | --level)
LEVEL=echo "$2" | tr '[:upper:]' '[:lower:]'
case "$LEVEL" in
major|minor|patch) ;;
*)
echo "Invalid release level: $LEVEL"
exit 1
;;
esac
shift 2
;;
--) shift;
break
;;
esac
done

cd $(git rev-parse --show-toplevel)

# Using git cliff determine if there are any feat commits that do not belong to a tag.
git cliff --unreleased --strip all --body "{% for group, commits in commits | group_by(attribute=\"group\") %}
{{ group }} {{ commits | length }}
{% endfor %}" | grep Features
ret=$?
if [[ $ret = 0 ]] && [[ $LEVEL = patch ]]; then
echo "Cannot release patch version when there are unreleased features."
exit 1
fi

git config user.email "github@3box.io"
git config user.name "Github Automation"
TAG=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"')
cargo release -vv $LEVEL --exclude ceramic-api-server --exclude ceramic-kubo-rpc-server --no-confirm

#gh release create v$TAG --title "v"$TAG --latest artifacts/**/*
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
8 changes: 8 additions & 0 deletions fpm/linux.fpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-t deb
-s dir
--name ceramic-one
--license mit
--architecture all
--description "Ceramic API Server"
--url "https://ceramic.network"
--maintainer "3Box Labs <support@3box.com>"
8 changes: 8 additions & 0 deletions fpm/osx.fpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-t osxpkg
-s dir
--name ceramic-one
--license mit
--architecture all
--description "Ceramic API Server"
--url "https://ceramic.network"
--maintainer "3Box Labs <support@3box.com>"
2 changes: 1 addition & 1 deletion kubo-rpc-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To see how to make this your own, look here:
[README]((https://openapi-generator.tech))

- API version: 0.1.0
- Build date: 2023-08-30T16:59:47.807386943-06:00[America/Denver]
- Build date: 2023-09-07T12:35:24.290-06:00[America/Denver]



Expand Down
1 change: 1 addition & 0 deletions kubo-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
publish = false

[features]
http = [
Expand Down
1 change: 1 addition & 0 deletions metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors.workspace = true
license.workspace = true
repository.workspace = true
build = "build.rs"
publish = false

[dependencies]
serde.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion one/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true

publish = false

[dependencies]
anyhow.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true

publish = false

[dependencies]
ahash.workspace = true
Expand Down
Loading

0 comments on commit a47cd1b

Please sign in to comment.