Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
49 changes: 39 additions & 10 deletions .github/workflows/release-proposal-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:

- name: Merge the main branch into the release branch
run: |
git fetch origin "${{ env.RELEASE_BRANCH }}" --tags
git fetch origin "${{ env.MAIN_BRANCH }}" "${{ env.RELEASE_BRANCH }}" --tags
git checkout "${{ env.RELEASE_BRANCH }}"

if ! git merge origin/"${{ env.MAIN_BRANCH }}"; then
Expand Down Expand Up @@ -182,6 +182,12 @@ jobs:
# Get commits since release for each crate and save to file
./scripts/commits-since-release.sh "$(cat /tmp/crates.json)" > /tmp/commits-by-crate.json

# Capture release branch tip now (while HEAD=release). Use this in Release version bumps
# so tag/merge-base resolution uses the same ref the script used; avoids failures after
# we switch to the new proposal branch.
git rev-parse HEAD > /tmp/release_head_sha
echo "Release branch HEAD (saved for later): $(cat /tmp/release_head_sha)"

# Display json output
jq . /tmp/commits-by-crate.json

Expand All @@ -190,30 +196,41 @@ jobs:
run: |
git status

IS_SHALLOW=$(git rev-parse --is-shallow-repository)
if [ "$IS_SHALLOW" = "true" ]; then
echo "Repository is shallow"
git pull --unshallow
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
echo "Repository is shallow, fetching full history..."
git fetch --unshallow
fi

git checkout "${{ env.RELEASE_BRANCH }}"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BRANCH_NAME="${{ env.PROPOSAL_BRANCH_PREFIX }}/${{ inputs.crate }}/$TIMESTAMP"
git checkout -b "$BRANCH_NAME"
git push origin "$BRANCH_NAME"
git push origin "$BRANCH_NAME" --tags
echo "Branch created: $BRANCH_NAME from ${{ env.RELEASE_BRANCH }} branch"
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"

- name: Release version bumps
id: release-version-bumps
env:
ORIGINAL_HEAD: ${{ github.sha }}
run: |
echo "Release version bumps..."

# After creating and pushing the proposal branch, tag/merge-base resolution can fail
# (tags no longer seen as ancestors of release_head_sha). Re-fetch release and tags,
# and unshallow if needed, so we have full history and tag refs for the rest of the step.
git fetch origin "${{ env.RELEASE_BRANCH }}" --tags
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
echo "Repository is shallow, fetching full history..."
git fetch --unshallow
fi

# Initialize results array
echo "[]" > /tmp/api-changes.json

# Use release branch tip from when we ran commits-since-release (same ref the script used).
# Avoids tag/merge-base resolution failures after switching to the new proposal branch.
ORIGINAL_HEAD=$(cat /tmp/release_head_sha)
echo "ORIGINAL_HEAD: $ORIGINAL_HEAD"

BRANCH_NAME="${{ steps.proposal-branch.outputs.branch_name }}"

# iterate over the commits and execute cargo release for each crate
Expand All @@ -236,6 +253,18 @@ jobs:
RANGE="$TAG..$ORIGINAL_HEAD"
echo "Using $RANGE as range"

if git merge-base --is-ancestor "$TAG" "$ORIGINAL_HEAD" 2>/dev/null; then
echo " Tag $TAGis ancestor of HEAD, using $RANGE"
else
MERGE_BASE=$(git merge-base "$TAG" "$ORIGINAL_HEAD" 2>/dev/null || echo "")
if [ -n "$MERGE_BASE" ]; then
RANGE="$MERGE_BASE..$ORIGINAL_HEAD"
echo " Tag $TAG is NOT ancestor of HEAD, using merge-base: $RANGE"
else
echo " WARNING: Could not find merge-base for tag $TAG, using $RANGE"
fi
fi

echo "Is the tag $TAG in the branch:"
git branch --contains "$TAG" || {
echo "Error: Tag $TAG is not in the branch" >&2
Expand All @@ -255,7 +284,7 @@ jobs:
echo "Semver level: $SEMVER_LEVEL"

LEVEL=$(echo "$SEMVER_LEVEL" | jq -r '.level')

# TODO: cargo release warns if there are no changes to the public API
# warning: updating crate to 4.0.1 despite no changes made since tag crate-v4.0.0
# Should we skip the release if there are no changes to the public API?
Expand Down Expand Up @@ -292,7 +321,7 @@ jobs:
NEXT_TAG="$TAG_PREFIX$NEXT_VERSION"

# Check what commits git sees in the range
echo "Commits in the range $RANGE:"
echo "Commits in the range $RANGE filtered by $CRATE_PATH:"
git log --oneline "$RANGE" -- "$CRATE_PATH/"

echo "Executing git cliff for $NAME since $RANGE, next tag: $NEXT_TAG..."
Expand Down
3 changes: 2 additions & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ commit_parsers = [
{ message = "^fix", group = "<!-- C -->Fixed" },
{ message = "^refactor\\(clippy\\)", skip = true },
{ message = "^chore\\(release\\)", skip = true },
{ message = "^chore: Release", skip = true },
{ message = "^chore: [R|r]elease", skip = true },
{ message = "^chore\\(deps.*\\)", skip = true },
{ message = "^chore\\(pr\\)", skip = true },
{ message = "^chore\\(pull\\)", skip = true },
{ message = "^chore\\(npm\\).*yarn\\.lock", skip = true },
{ message = "^Merge branch", skip = true },
{ message = "^Merge remote-tracking branch", skip = true },
{ message = ".*", group = "<!-- B -->Changed" },
]
# Prevent commits that are breaking from being excluded by commit parsers.
Expand Down
10 changes: 7 additions & 3 deletions scripts/commits-since-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ while read -r crate; do

# Check if tag exists
TAG_EXISTS=false
TAG_ANCESTOR="unknown"
COMMITS_JSON="[]"

if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
Expand All @@ -165,15 +166,18 @@ while read -r crate; do
# If not, use merge-base to find the common ancestor
if git merge-base --is-ancestor "$TAG" HEAD 2>/dev/null; then
COMMIT_RANGE="$TAG..HEAD"
TAG_ANCESTOR="true"
log_verbose " Tag is ancestor of HEAD, using $COMMIT_RANGE"
else
MERGE_BASE=$(git merge-base "$TAG" HEAD 2>/dev/null || echo "")
if [ -n "$MERGE_BASE" ]; then
COMMIT_RANGE="$MERGE_BASE..HEAD"
TAG_ANCESTOR="$MERGE_BASE"
log_verbose " Tag is NOT ancestor of HEAD, using merge-base: $COMMIT_RANGE"
else
log_verbose " WARNING: Could not find merge-base, using $TAG..HEAD"
COMMIT_RANGE="$TAG..HEAD"
TAG_ANCESTOR="no merge-base"
log_verbose " WARNING: Could not find merge-base, using $TAG..HEAD"
fi
fi

Expand Down Expand Up @@ -219,7 +223,7 @@ while read -r crate; do
OUTPUT_JSON+=","
fi

OUTPUT_JSON+="{\"name\":\"$NAME\",\"version\":\"$VERSION\",\"path\":\"$CRATE_PATH\",\"tag\":\"$TAG\",\"tag_exists\":$TAG_EXISTS,\"commits\":$COMMITS_JSON}"
OUTPUT_JSON+="{\"name\":\"$NAME\",\"version\":\"$VERSION\",\"path\":\"$CRATE_PATH\",\"tag\":\"$TAG\",\"tag_exists\":$TAG_EXISTS,\"tag_ancestor\":\"$TAG_ANCESTOR\",\"commits\":$COMMITS_JSON}"

done < <(echo "$INPUT_JSON" | jq -c '.[]')

Expand All @@ -240,7 +244,7 @@ case "$FORMAT" in
echo "$OUTPUT_JSON" | jq -r '.[] |
"\(.name) v\(.version)" +
(if .tag_exists then
" (tag: \(.tag))\n Commits: \(.commits | length)" +
" (tag: \(.tag) ancestor: \(.tag_ancestor))\n Commits: \(.commits | length)" +
(if (.commits | length) > 0 then
"\n" + (.commits | map(" - \(.hash[0:8]) \(.subject)") | join("\n"))
else "" end)
Expand Down
2 changes: 1 addition & 1 deletion scripts/semver-level.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ compute_semver_results() {
fi

# Fetch base commit
git fetch origin "$baseline" --depth=50 --quiet
git fetch origin "$baseline" --quiet

# Ensure baseline has origin/ prefix if it doesn't already (skip for tags: refs/tags/...)
if [[ ! "$baseline" =~ ^origin/ ]] && [[ "$baseline" != *"refs/tags"* ]]; then
Expand Down
Loading