Skip to content

chore: Add crate release helper scripts #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/reviewdog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: reviewdog/action-shellcheck@52f34f737a16c65b8caa8c51ae1b23036afe5685 # v1.23.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

yamllint:
runs-on: ubuntu-latest
steps:
Expand Down
63 changes: 40 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: detect-aws-credentials
args: ["--allow-missing-credentials"]
- id: detect-private-key
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
args: ["--all", "--", "--check"]
- id: clippy
args: ["--all-targets", "--", "-D", "warnings"]
- repo: https://github.com/adrienverge/yamllint
rev: v1.26.3
hooks:
- id: yamllint
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.31.1
hooks:
- id: markdownlint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: detect-aws-credentials
args: ["--allow-missing-credentials"]
- id: detect-private-key

- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
args: ["--all", "--", "--check"]
- id: clippy
args: ["--all-targets", "--", "-D", "warnings"]
- repo: https://github.com/adrienverge/yamllint
rev: v1.26.3
hooks:
- id: yamllint

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.31.1
hooks:
- id: markdownlint

- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
args: ["--severity=info"]

- repo: local
hooks:
- id: .scripts/verify-crate-versions
name: .scripts/verify-crate-versions
language: system
entry: .scripts/verify_crate_versions.sh
stages: [commit, merge-commit, manual]
pass_filenames: false
42 changes: 42 additions & 0 deletions .scripts/tag_and_push_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# Tag the latest release based on the versions in the Cargo.toml files.
# Do this after merging a release PR to main.
#
# This script will skip local tags (eg: if a crate release has already been
# done). You will be prompted at the end whether to push the tags or not.
#
# To ensure crate versions match the latest version in the changelogs,
# see verify_crate_versions.sh

set -euo pipefail

# You need fzf to run this
type fzf &> /dev/null || (echo "This script requires fzf" >&2 && exit 1)

# Update from remote
git fetch origin

# Select a commit (usually the first is the right one)
SHORT_COMMIT_HASH=$(git log --color=always --oneline | fzf --ansi --layout=reverse --prompt="Select the commit to tag" | cut -d' ' -f1)

# Get the latest versions
LATEST_TAGS=$(find . -mindepth 2 -name CHANGELOG.md -exec sh -c 'grep -HoE "\[[0-9]+\.[0-9]+\.[0-9]+\]" "$1" | head -1 | sed -e "s|^./crates/\([a-z0-9_\-]\+\).*:\[\(.*\)\]$|\1-\2|"' shell {} \; | sort)
LATEST_TAGS=$(find . -mindepth 2 -name CHANGELOG.md -exec sh -c 'grep -HoE "\[[0-9]+\.[0-9]+\.[0-9]+\]" "$1" | head -1 | sed -e "s|^./crates/\([a-z0-9_\-]\+\).*:\[\(.*\)\]$|\1-\2|"' shell {} \; | sort)
ALL_TAGS=$(git tag | sort)

# Only show tags that don't exist (if you need to overwrite tags, do it manually)
AVAILABLE_TAGS=$(comm -23 <(echo -e "$LATEST_TAGS") <(echo -e "$ALL_TAGS"))

# Select tags
SELECTED_TAGS=$(echo -e "$AVAILABLE_TAGS" | fzf --reverse --multi --bind "ctrl-a:toggle-all" --bind "space:toggle" --prompt "Select multiple to release (use SPACE to select, CTRL+A to invert selection)")

# Tag each selected to the selected commit
echo -e "$SELECTED_TAGS" | xargs -I {} git tag -s -m "release/{}" {} "$SHORT_COMMIT_HASH"
echo
read -r -p "push the tags [y/N]? " PUSH
if [ "${PUSH,,}" == "y" ]; then
echo -e "$SELECTED_TAGS" | xargs -I {} git push origin {}
fi

git log -1 --oneline
63 changes: 63 additions & 0 deletions .scripts/verify_crate_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -euo pipefail

# Eg: makes a list like this based on the latest release in the CHANGELOG.md files:
# k8s-version-0.1.1
# stackable-certs-0.3.1
# stackable-operator-0.70.0
# stackable-operator-derive-0.3.1
# stackable-telemetry-0.2.0
# stackable-versioned-0.1.1
# stackable-webhook-0.3.1

for CRATE in $(find . -mindepth 2 -name Cargo.toml | sed -e 's|^./crates/\([a-z0-9_\-]\+\).*|\1|' | sort); do
# Get the version in Cargo.toml
CRATE_VERSION=$(grep 'version' "./crates/$CRATE/Cargo.toml" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
[ -n "$CRATE_VERSION" ] || (
echo "CRATE_VERSION for $CRATE is empty." >&2
echo "Please check ./crates/$CRATE/Cargo.toml" >&2
exit 21
)

# Special treatment of stackable-versioned-macros:
# - It has no changelog
# - The version should be the same as stackable-versioned
if [ "$CRATE" = "stackable-versioned-macros" ]; then
ASSOCIATED_CRATE="stackable-versioned"

# Get the version in Cargo.toml
ASSOCIATED_CRATE_VERSION=$(grep 'version' "./crates/$ASSOCIATED_CRATE/Cargo.toml" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
[ -n "$ASSOCIATED_CRATE_VERSION" ] || (
echo "ASSOCIATED_CRATE_VERSION for $ASSOCIATED_CRATE_VERSION is empty" >&2
echo "Please check ./crates/$ASSOCIATED_CRATE_VERSION/Cargo.toml" >&2
exit 22
)

# Ensure the versions match
[ "$CRATE_VERSION" == "$ASSOCIATED_CRATE_VERSION" ] || (
echo "Versions for $CRATE and $ASSOCIATED_CRATE do not match. $CHANGELOG_VERSION != $ASSOCIATED_CRATE_VERSION" >&2
echo "Ensure the version in ./crates/$CRATE/Cargo.toml matches the version in ./crates/$ASSOCIATED_CRATE/Cargo.toml" >&2
exit 23
)

else
# Get the latest documented version from the CHANGELOG.md
CHANGELOG_VERSION=$(grep -oE '\[[0-9]+\.[0-9]+\.[0-9]+\]' "./crates/$CRATE/CHANGELOG.md" | head -1 | tr -d '[]')
[ -n "$CHANGELOG_VERSION" ] || (
echo "CHANGELOG_VERSION for $CRATE is empty" >&2
echo "Please check the latest release version in ./crates/$CRATE/CHANGELOG.md" >&2
exit 24
)

# Ensure the versions match
[ "$CRATE_VERSION" == "$CHANGELOG_VERSION" ] || (
echo "Versions for $CRATE do not match. $CHANGELOG_VERSION != $CRATE_VERSION." >&2
echo "Ensure the version in ./crates/$CRATE/CHANGELOG.md matches the latest release version in ./crates/$CRATE/Cargo.toml" >&2
exit 25
)
fi

echo "${CRATE}-${CRATE_VERSION}"

done
Loading