diff --git a/.githooks/pre-commit.py b/.githooks/pre-commit.py new file mode 100644 index 0000000000..b51f139263 --- /dev/null +++ b/.githooks/pre-commit.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +# This script appends the current commit hash to the version information in +# `layouts/partials/version.txt` +# +# Call this script from your ".git/hooks/pre-commit" file like this (supporting +# Linux, Windows and MacOS) + +# #!/bin/sh +# echo 'execute .githooks/pre-commit.py' >> .githooks/hooks.log +# python3 .githooks/pre-commit.py + +from datetime import datetime +import re +import subprocess + +def main(): + time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + file_path = 'layouts/partials/version.txt' + with open(file_path, 'r+') as f: + version = f.read().strip() + new_version = '' + match = re.match(r'(\d+\.\d+\.\d+)(\+[^+]+)?', version) + if match: + semver = match.group(1) + commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD~1']).decode('utf-8').strip() + new_version = f'{semver}+{commit_hash}' + f.seek(0) + f.write(new_version) + f.truncate() + subprocess.check_call(['git', 'add', file_path]) + else: + print(f'{time}: PRE-COMMIT - Invalid version format in {file_path}', file=open(".githooks/hooks.log", "a")) + print(f'PRE-COMMIT - Invalid version format in {file_path}') + exit(1) + print(f'{time}: PRE-COMMIT - New version {new_version} was written to {file_path}', file=open(".githooks/hooks.log", "a")) + exit(0) + +if __name__ == '__main__': + main() diff --git a/.githooks/pre-push.py b/.githooks/pre-push.py index a63b46f124..c5d3726017 100644 --- a/.githooks/pre-push.py +++ b/.githooks/pre-push.py @@ -33,10 +33,10 @@ def main(): local_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], universal_newlines=True).strip() wip_prefix = '^#\\d+(?:\\b.*)$' if re.match(wip_prefix, local_branch): - print(f'{time}: Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress', file=open(".githooks/hooks.log", "a")) - print(f'Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress') + print(f'{time}: PRE-PUSH - Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress', file=open(".githooks/hooks.log", "a")) + print(f'PRE-PUSH - Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress') exit(1) - print(f'{time}: Branch "{local_branch}" was pushed', file=open(".githooks/hooks.log", "a")) + print(f'{time}: PRE-PUSH - Branch "{local_branch}" was pushed', file=open(".githooks/hooks.log", "a")) exit(0) if __name__ == "__main__": diff --git a/.github/actions/release_milestone/action.yaml b/.github/actions/release_milestone/action.yaml index 6b5a90efdb..8ff7cc4f89 100644 --- a/.github/actions/release_milestone/action.yaml +++ b/.github/actions/release_milestone/action.yaml @@ -213,17 +213,6 @@ runs: ${{ steps.changelog_github.outputs.value }} tag: ${{ env.MILESTONE }} - - name: Update version number to mark non-release version - shell: bash - env: - MILESTONE: ${{ inputs.milestone }} - GITHUB_TOKEN: ${{ inputs.github_token }} - run: | - echo -n "$MILESTONE+tip" > layouts/partials/version.txt - git add * - git commit --message "Mark non-release version" - git push origin main - - name: Create next patch milestone uses: WyriHaximus/github-action-create-milestone@v1 continue-on-error: true diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index 29775e728a..7639b434b3 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -6.4.1+tip \ No newline at end of file +6.4.0+c484ba60edc0cc42cb36c0f8c7f34c1b10b44f89 \ No newline at end of file