Skip to content

Commit

Permalink
ci: Add git tag / commit message with cargo release (solana-labs#7235)
Browse files Browse the repository at this point in the history
#### Problem

The publish workflow is great, but it does some work by hand, namely
creating the git commit and tag. `cargo release` can do this, but we
currently don't use it because we aren't customizing it.

#### Summary of changes

Add configuration options to the top-level Cargo.toml and let cargo
release do everything for us.
  • Loading branch information
joncinque authored Sep 3, 2024
1 parent dab04d4 commit ba05751
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/publish-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ jobs:
./ci/publish-rust.sh "${{ inputs.package_path }}" $LEVEL $OPTIONS
- name: Push Commit and Tag
if: github.event.inputs.dry_run != 'true'
run: git push origin --follow-tags

- name: Generate a changelog
if: github.event.inputs.create_release == 'true'
uses: orhun/git-cliff-action@v3
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ exclude = [
]

resolver = "2"

[workspace.metadata.release]
pre-release-commit-message = "Publish {{crate_name}} v{{version}}"
tag-message = "Publish {{crate_name}} v{{version}}"
consolidate-commits = false
17 changes: 4 additions & 13 deletions ci/publish-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ cd "${PACKAGE_PATH}"

# Get the old version, used with git-cliff
old_version=$(readCargoVariable version "Cargo.toml")
package_name=$(readCargoVariable name "Cargo.toml")
tag_name="$(echo $package_name | sed 's/spl-//')"

# Publish the new version.
# Publish the new version, commit the repo change, tag it, and push it all.
if [[ -n ${DRY_RUN} ]]; then
cargo release ${LEVEL}
else
cargo release ${LEVEL} --no-push --no-tag --no-confirm --execute
cargo release ${LEVEL} --tag-name "${tag_name}-v{{version}}" --no-confirm --execute
fi

# Stop here if this is a dry run.
Expand All @@ -37,8 +39,6 @@ fi

# Get the new version.
new_version=$(readCargoVariable version "Cargo.toml")
package_name=$(readCargoVariable name "Cargo.toml")
tag_name="$(echo $package_name | sed 's/spl-//')"
new_git_tag="${tag_name}-v${new_version}"
old_git_tag="${tag_name}-v${old_version}"
release_title="SPL ${tag_name} - v${new_version}"
Expand All @@ -49,12 +49,3 @@ if [[ -n $CI ]]; then
echo "old_git_tag=${old_git_tag}" >> $GITHUB_OUTPUT
echo "release_title=${release_title}" >> $GITHUB_OUTPUT
fi

# Soft reset the last commit so we can create our own commit and tag.
git reset --soft HEAD~1

# Commit the new version.
git commit -am "Publish ${tag_name} v${new_version}"

# Tag the new version.
git tag -a ${new_git_tag} -m "${tag_name} v${new_version}"

0 comments on commit ba05751

Please sign in to comment.