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 github action to increment cargo version numbers when a release is published (backport #25821) #25853

Merged
merged 1 commit into from
Jun 8, 2022
Merged
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
39 changes: 39 additions & 0 deletions .github/workflows/increment-cargo-version-on-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: increment-cargo-version

on:
release:
types: [published]

jobs:
check_compilation:
name: Increment cargo version
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

# This script confirms two assumptions:
# 1) Tag should be branch.<patch_version>
# 2) Tag should match the crate version numbers in the manifest files (which get incremented by the next step)
- name: Confirm tag, branch, and cargo version numbers
run: scripts/confirm-cargo-version-numbers-before-bump.sh ${{ github.event.release.target_commitish }} ${{ github.event.release.tag_name }}

- name: Update Patch Version Numbers
run: |
OUTPUT=$(scripts/increment-cargo-version.sh patch)
SOLANA_NEW_VERSION=$(sed -E 's/.* -> //' <<< $OUTPUT)
echo "SOLANA_NEW_VERSION=$SOLANA_NEW_VERSION"
echo "SOLANA_NEW_VERSION=$SOLANA_NEW_VERSION" >> $GITHUB_ENV

- name: Cargo Tree
run: ./scripts/cargo-for-all-lock-files.sh tree

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
commit-message: Bump Version to ${{ env.SOLANA_NEW_VERSION }}
title: Bump Version to ${{ env.SOLANA_NEW_VERSION }}
body: PR opened by Github Action
branch: update-version-${{ env.SOLANA_NEW_VERSION }}
base: ${{ github.event.release.target_commitish }}
labels: automerge
55 changes: 55 additions & 0 deletions scripts/confirm-cargo-version-numbers-before-bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -e

usage() {
cat <<EOF
usage: $0 branch tag

Checks that the tag matches the branch and the Cargo.toml versions match the tag.
EOF
exit 0
}

branch="$1"
tag="$2"

echo "branch: $branch tag: $tag"

# The tag is expected to be the branch name plus a patch number. eg:
# tag: v1.2.3
# branch: v1.2
if [[ "$tag" != "$branch"* ]]; then
>&2 echo "Tag must start with the branch name. Tag: $tag Branch: $branch"
exit 1
fi

here="$(dirname "$0")"
cd "$here"/..
source scripts/read-cargo-variable.sh

ignores=(
.cache
.cargo
target
web3.js/examples
web3.js/test
node_modules
)

not_paths=()
for ignore in "${ignores[@]}"; do
not_paths+=(-not -path "*/$ignore/*")
done

# shellcheck disable=2207
Cargo_tomls=($(find . -mindepth 2 -name Cargo.toml "${not_paths[@]}"))

for Cargo_toml in "${Cargo_tomls[@]}"; do
manifest_version="$(readCargoVariable version "${Cargo_toml}")"
if ! [[ "v$manifest_version" == "$tag" ]]; then
>&2 echo "Tag must match the crate version in the manifest files. Mismatch found in $Cargo_toml. Tag: $tag Manifest version: $manifest_version"
exit 1
else
echo "tag matches manifest: $Cargo_toml $manifest_version $tag"
fi
done