Skip to content
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

Add tagging automation for crates #7144

Closed
wants to merge 3 commits into from
Closed
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
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release

on push:
branches:
- master
paths-ignore:
- 'docs/**'

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Create tags
id: create_tags
run: |
ci/tag-new-crates.sh
git push --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions ci/detect-changed-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Source this file.
#
# Detects any manifests whose versions have changed.
# Does so by comparing the current version in the Cargo.toml with the previous
# version in the last commit. Intended for squash-merged PRs.

detect_changed_manifests() {
local changed_manifests=()
local cargo_toml_files=$(find . -name "Cargo.toml")

for file in $cargo_toml_files; do
# Get the current version from the manifest.
local current_version=$(grep -E '^version\s*=' "$file" | sed -E 's/version\s*=\s*"(.*)"/\1/')

# Get the previous version from the last commit.
local previous_version=$(git show HEAD~1:"$file" | grep -E '^version\s*=' | sed -E 's/version\s*=\s*"(.*)"/\1/' 2>/dev/null)

# Compare the versions and add the path to the list if they are different.
if [ "$current_version" != "$previous_version" ]; then
changed_manifests+=("$file")
fi
done

echo "${changed_manifests[@]}"
}
24 changes: 24 additions & 0 deletions ci/tag-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# Creates a new git tag for each package that has a new version.

set -e

source ci/detect-changed-manifests.sh

changed_manifests=$(detect_changed_manifests)

if [ -n "$changed_manifests" ]; then
for manifest_path in $changed_manifests; do
# Read the package name and version from its manifest.
package_name=$(grep '^name\s*=' "$manifest_path" | awk -F'\"' '{print $2}')
new_version=$(grep '^version\s*=' "$manifest_path" | awk -F'\"' '{print $2}')

# Create a new git tag.
tag_name="${package_name}-v${new_version}"
git tag "$tag_name"
echo "Created tag: $tag_name"
done
else
echo "No versions changed."
fi