Skip to content

Commit

Permalink
Add cargo publish step to release pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Mar 6, 2023
1 parent 9ef3314 commit f7db5f9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
37 changes: 34 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,35 @@ jobs:
crate: ${{ steps.parse-ref.outputs.crate }}
version: ${{ steps.parse-ref.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- id: parse-ref
name: Parse ref
run: |
echo "CRATE=$(cut -d/ -f1 <<<"${GITHUB_REF#refs/*/}")" >> $GITHUB_OUTPUT
echo "VERSION=$(cut -d/ -f2 <<<"${GITHUB_REF#refs/*/}")" >> $GITHUB_OUTPUT
set -e
CRATE="$(cut -d/ -f1 <<<"${GITHUB_REF#refs/*/}")"
VERSION="$(cut -d/ -f2 <<<"${GITHUB_REF#refs/*/}")"
if [ -z "${CRATE}" ]; then
echo "::error::Could not determine crate name from ref '${GITHUB_REF}'"
exit 1
fi
if [ -z "${VERSION}" ]; then
echo "::error::Could not determine version from ref '${GITHUB_REF}'"
exit 1
fi
echo "CRATE=${CRATE}" >> $GITHUB_OUTPUT
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
setVersion="$(./scripts/version.sh "${CRATE}")"
if [ ! "${VERSION#v}" = "${setVersion}" ]; then
echo "::error::Version mismatch: tag version ${VERSION#v} != crate version ${setVersion}"
exit 1
fi
build:
needs:
Expand All @@ -34,6 +59,8 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ needs.generate.outputs.crate }}
- name: "check cgroup version"
run: "mount | grep cgroup"
- uses: actions/checkout@v3
Expand Down Expand Up @@ -64,7 +91,7 @@ jobs:
- name: Setup buildx
run: docker buildx create --use
- name: build binaries
run: docker buildx bake --set *.cache-from=type=gha --set *.cache-to=type=gha release-tars
run: docker buildx bake --set *.cache-from=type=gha,scope=buildkit-release-${CRATE} --set *.cache-to=type=gha,scope=buildkit-release-${CRATE} release-tars
env:
CRATE: ${{ needs.generate.outputs.crate }}
- name: upload binary as GitHub artifact
Expand All @@ -81,3 +108,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NAME: ${{ needs.generate.outputs.crate }}/${{ needs.generate.outputs.version }}
- name: Cargo publish
run: cargo publish --package ${{ needs.generate.outputs.crate }} --verbose --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_PUBLISH_TOKEN }}
3 changes: 0 additions & 3 deletions scripts/bins.jq

This file was deleted.

9 changes: 8 additions & 1 deletion scripts/bins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
# Get the list of binaries from the Cargo.toml file.
# If targeting a specific crate, pass the crate name as the first argument.

cargo metadata --format-version=1 | jq --arg CRATE "${1}" -f ./scripts/bins.jq
read -r -d '' Q <<-'EOF'
include "crates";
.packages | filter_by_package($CRATE) | get_bins
EOF

set -u -e -o pipefail

cargo metadata --format-version=1 --no-deps | jq -L "${BASH_SOURCE[0]%/*}" --arg CRATE "${1}" "${Q}"
3 changes: 3 additions & 0 deletions scripts/crates.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def filter_by_package(package): if package != "" then map(select(.name == package)) else . end;

def get_bins: map(.targets | map(select(.kind[] | contains("bin")).name))[] | select(length > 0);
13 changes: 13 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Get the list of binaries from the Cargo.toml file.
# If targeting a specific crate, pass the crate name as the first argument.

read -r -d '' Q <<-'EOF'
include "crates";
.packages | filter_by_package($CRATE)[0].version
EOF

set -u -e -o pipefail

cargo metadata --format-version=1 --no-deps | jq -r -L "${BASH_SOURCE[0]%/*}" --arg CRATE "${1}" "${Q}"

0 comments on commit f7db5f9

Please sign in to comment.