Merge pull request #6033 from jepler/better-describe

Improve use of `git describe`
This commit is contained in:
Scott Shawcroft 2022-02-15 10:48:55 -08:00 committed by GitHub
commit 947a53c8d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 20 deletions

View File

@ -42,8 +42,8 @@ jobs:
run: python tools/ci_fetch_deps.py test ${{ github.sha }}
- name: CircuitPython version
run: |
git describe --dirty --tags || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
tools/describe || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
- name: Install dependencies
run: |
sudo apt-get update
@ -148,8 +148,8 @@ jobs:
run: python tools/ci_fetch_deps.py mpy-cross-mac ${{ github.sha }}
- name: CircuitPython version
run: |
git describe --dirty --tags
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
tools/describe || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
- name: Install dependencies
run: |
brew install gettext
@ -204,8 +204,8 @@ jobs:
run: python tools/ci_fetch_deps.py docs ${{ github.sha }}
- name: CircuitPython version
run: |
git describe --dirty --tags
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
tools/describe || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
- name: Set up Python 3
uses: actions/setup-python@v2
with:
@ -379,7 +379,9 @@ jobs:
- name: Get CP deps
run: python tools/ci_fetch_deps.py ${{ matrix.board }} ${{ github.sha }}
- name: CircuitPython version
run: git describe --dirty --tags
run: |
tools/describe || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
- uses: actions/cache@v2
name: Fetch IDF tool cache
id: idf-cache

View File

@ -34,7 +34,9 @@ jobs:
gcc --version
python3 --version
- name: CircuitPython version
run: git describe --dirty --tags
run: |
tools/describe || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
- name: Website
run: python3 build_board_info.py
working-directory: tools

View File

@ -77,8 +77,8 @@ jobs:
run: python tools/ci_fetch_deps.py windows ${{ github.sha }}
- name: CircuitPython version
run: |
git describe --dirty --tags
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
tools/describe || git log --parents HEAD~4..
echo >>$GITHUB_ENV CP_VERSION=$(tools/describe)
- name: build mpy-cross
run: make -j2 -C mpy-cross

View File

@ -24,12 +24,15 @@ import subprocess
import sys
import urllib.parse
import time
import pathlib
from collections import defaultdict
from sphinx.transforms import SphinxTransform
from docutils import nodes
from sphinx import addnodes
tools_describe = str(pathlib.Path(__file__).parent / "tools/describe")
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
@ -129,7 +132,7 @@ copyright = f'2014-{current_date.tm_year}, MicroPython & CircuitPython contribut
final_version = ""
git_describe = subprocess.run(
["git", "describe", "--dirty", "--tags"],
[tools_describe],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8"

View File

@ -1,29 +1,25 @@
"""
Generate header file with macros defining MicroPython version info.
This script works with Python 2.6, 2.7, 3.3 and 3.4.
This script works with Python 3.7 and newer
"""
from __future__ import print_function
import sys
import os
import pathlib
import datetime
import subprocess
tools_describe = str(pathlib.Path(__file__).parent.parent / "tools/describe")
def get_version_info_from_git():
# Python 2.6 doesn't have check_output, so check for that
try:
subprocess.check_output
subprocess.check_call
except AttributeError:
return None
# Note: git describe doesn't work if no tag is available
try:
git_tag = subprocess.check_output(
["git", "describe", "--tags", "--dirty", "--always", "--match", "[1-9].*"],
[tools_describe],
stderr=subprocess.STDOUT,
universal_newlines=True,
).strip()

View File

@ -43,6 +43,7 @@ setup(
"root": "..",
"relative_to": __file__,
"local_scheme": local_scheme,
"git_describe_command": "tools/describe",
},
zip_safe=False,
)

2
tools/describe Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git describe --first-parent --dirty --tags --always --match "[1-9].*"