Skip to content

Improve use of git describe #6033

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

Merged
merged 4 commits into from
Feb 15, 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
16 changes: 9 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,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
Expand Down Expand Up @@ -144,8 +144,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
Expand Down Expand Up @@ -200,8 +200,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:
Expand Down Expand Up @@ -375,7 +375,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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/create_website_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ports_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,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
Expand Down
5 changes: 4 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
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.
Expand Down Expand Up @@ -129,7 +132,7 @@ def autoapi_prepare_jinja_env(jinja_env):

final_version = ""
git_describe = subprocess.run(
["git", "describe", "--dirty", "--tags"],
[tools_describe],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8"
Expand Down
14 changes: 5 additions & 9 deletions py/makeversionhdr.py
Original file line number Diff line number Diff line change
@@ -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

def get_version_info_from_git():
# 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()
Expand Down
1 change: 1 addition & 0 deletions setup.py-stubs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ setup(
"root": "..",
"relative_to": __file__,
"local_scheme": local_scheme,
"git_describe_command": "tools/describe",
},
zip_safe=False,
)
2 changes: 2 additions & 0 deletions tools/describe
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
git describe --first-parent --dirty --tags --always --match "[1-9].*"