mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
build: write commit hash into version.txt
This commit is contained in:
parent
d6186c0b6d
commit
1bf4613d26
4 changed files with 44 additions and 15 deletions
40
.githooks/pre-commit.py
Normal file
40
.githooks/pre-commit.py
Normal file
|
@ -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()
|
|
@ -33,10 +33,10 @@ def main():
|
||||||
local_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], universal_newlines=True).strip()
|
local_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], universal_newlines=True).strip()
|
||||||
wip_prefix = '^#\\d+(?:\\b.*)$'
|
wip_prefix = '^#\\d+(?:\\b.*)$'
|
||||||
if re.match(wip_prefix, local_branch):
|
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'{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'Branch "{local_branch}" was not pushed because its name starts with a "#" which marks it as work in progress')
|
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)
|
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)
|
exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
11
.github/actions/release_milestone/action.yaml
vendored
11
.github/actions/release_milestone/action.yaml
vendored
|
@ -213,17 +213,6 @@ runs:
|
||||||
${{ steps.changelog_github.outputs.value }}
|
${{ steps.changelog_github.outputs.value }}
|
||||||
tag: ${{ env.MILESTONE }}
|
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
|
- name: Create next patch milestone
|
||||||
uses: WyriHaximus/github-action-create-milestone@v1
|
uses: WyriHaximus/github-action-create-milestone@v1
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
6.4.1+tip
|
6.4.0+c484ba60edc0cc42cb36c0f8c7f34c1b10b44f89
|
Loading…
Reference in a new issue