-
Notifications
You must be signed in to change notification settings - Fork 8
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
Create a release-commit action #97
Open
JamyGolden
wants to merge
4
commits into
main
Choose a base branch
from
jamy/feature/release-commit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−27
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Create a new commit | ||
# This action bumps the Cargo.toml version and updates related files. | ||
# Updates will affect the following files: | ||
# - ./Cargo.toml | ||
# - ./Cargo.lock | ||
# - ./THIRD-PARTY-LICENSES.md | ||
# - ./CHANGELOG.md | ||
name: "Release Commit" | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
bump_level: | ||
description: "What type of release is this?" | ||
required: true | ||
type: choice | ||
options: | ||
- minor | ||
- patch | ||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
setup-environment: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Add git tag to release | ||
run: ./scripts/create_release_changes ${{ github.event.inputs.text_input }} | ||
|
||
- name: Get new cargo version | ||
id: cargo_version | ||
run: | | ||
VERSION=$(cargo read-manifest | jq -r ".version") | ||
echo "value=v$VERSION" >> $GITHUB_OUTPUT | ||
|
||
- name: Ensure this release doesn't already exist | ||
run: | | ||
if git log --grep="Release ${{ steps.cargo_version.outputs.value }}" --quiet; then | ||
echo "Release commit already exists: \"Release ${{ steps.cargo_version.outputs.value}}\"" | ||
exit 1 | ||
fi | ||
|
||
- name: Commit the changes | ||
uses: stefanzweifel/git-auto-commit-action@ac8823709a85c7ce090849ac3e5fe24d006f6e18 # v5.0.1 | ||
with: | ||
commit_message: "Release ${{ steps.cargo_version.outputs.value }}" | ||
branch: ${{ github.head_ref }} | ||
commit_user_name: tinted-theming-bot | ||
commit_user_email: [email protected] | ||
commit_author: tinted-theming-bot <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env bash | ||
|
||
main() { | ||
local level="$1" # Supported: [major|minor|patch] | ||
local old_version=$(get_cargo_version) | ||
|
||
# Ensure things are as expected before doing anything | ||
setup | ||
|
||
bump_cargo_version "$level" | ||
|
||
local new_version="$(get_cargo_version)" | ||
version_changelog "$old_version" "$new_version" | ||
|
||
update_third_party_licenses | ||
check_for_unauthorized_changes | ||
} | ||
|
||
setup() { | ||
# Ensure there are no changes in the repository | ||
if [[ -n $(git status --porcelain) ]]; then | ||
echo "Uncommitted changes or untracked files already exist in the repository." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Extract the version from Cargo.toml | ||
get_cargo_version() { | ||
local cargo_toml="./Cargo.toml" | ||
local version=$(grep -m 1 '^version =' "$cargo_toml" | sed -E 's/version = "(.*)"/\1/') | ||
|
||
if [[ -z "$version" ]]; then | ||
echo "Version not found in Cargo.toml" | ||
exit 1 | ||
fi | ||
|
||
echo "$version" | ||
} | ||
|
||
# Bump version in Cargo.toml | ||
bump_cargo_version() { | ||
local level="$1" | ||
local version=$(get_cargo_version "$level") | ||
local cargo_toml="./Cargo.toml" | ||
|
||
# Split version into major, minor, patch | ||
IFS='.' read -r major minor patch <<< "$version" | ||
echo "Current version: $version" | ||
|
||
# Increment based on major, minor or patch | ||
if [[ "$level" == "major" ]]; then | ||
major=$((major + 1)) | ||
minor=0 | ||
patch=0 | ||
elif [[ "$level" == "minor" ]]; then | ||
minor=$((minor + 1)) | ||
patch=0 | ||
elif [[ "$level" == "patch" ]]; then | ||
patch=$((patch + 1)) | ||
else | ||
echo "Usage: $0 [major|minor|patch]" | ||
exit 1 | ||
fi | ||
|
||
local updated_version="$major.$minor.$patch" | ||
sed -i -E "s/^version = \"$version\"$/version = \"$updated_version\"/" "$cargo_toml" | ||
|
||
echo "Updated Cargo.toml to version $updated_version" | ||
} | ||
|
||
# Add version and date to "Unreleased" section in changelog | ||
version_changelog() { | ||
local old_version="$1" | ||
local new_version="$2" | ||
local changelog_file="./CHANGELOG.md" | ||
|
||
if [[ ! $(grep '^## Unreleased' "$changelog_file") ]]; then | ||
echo "Warning: CHANGELOG.md does not have an 'Unreleased' section" | ||
exit 1 | ||
fi | ||
|
||
local current_date=$(TZ=UTC date +"%Y-%m-%d") | ||
|
||
sed -i -E "s/## Unreleased/## \[$new_version\] - $current_date/" "$changelog_file" | ||
sed -i "/^\[$old_version\]: /i \[$new_version\]: https://github.com/tinted-theming/tinty/compare/v$old_version...v$new_version" "$changelog_file" | ||
|
||
echo "Updated CHANGELOG.md with $new_version" | ||
} | ||
|
||
# Update third-party licenses with `cargo about` | ||
update_third_party_licenses() { | ||
local license_file="./LICENSES-THIRD-PARTY.md" | ||
|
||
cargo deny check | ||
cargo about generate about.hbs > "$license_file" | ||
|
||
echo "Updated third-party licenses" | ||
} | ||
|
||
# Exit if disallowed files contain changes | ||
check_for_unauthorized_changes() { | ||
local allowed_files=("Cargo.toml" "Cargo.lock" "LICENSES-THIRD-PARTY.md" "CHANGELOG.md") | ||
local changed_files=$(git status --porcelain | awk '{print $2}') | ||
local unauthorized_changes=0 | ||
|
||
for file in $changed_files; do | ||
if [[ ! " ${allowed_files[*]} " =~ " ${file} " ]]; then | ||
echo "Unauthorized change detected: $file" | ||
unauthorized_changes=1 | ||
fi | ||
done | ||
|
||
if [[ $unauthorized_changes -eq 1 ]]; then | ||
echo "Error: Only allow-listed files may change: ${allowed_files[*]}." | ||
exit 1 | ||
fi | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still necessary if we're checking for an existing tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will cause a false-positive in the event the release got reverted for whatever reason.
If we're trying to determine is whether HEAD is already released, perhaps this will do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove from here because the tag is already checked in the script file. The tags are important though since they are what the changelogs are linking to. The release action tags the commit before it does a binary build. It is possible the binary build fails in some strange case, then we have to manually delete the tag, fix the issue and do a new release. Not necessarily the best way of doing it but it's how it is set up atm. Usually the build doesn't fail if the tests pass though.