Skip to content

changes the means to compute the version for packages #499

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 2 commits into from
Oct 16, 2024
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
13 changes: 11 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
pdo_ci:
if: "!contains(github.event.commits[0].message, '[skip ci]')"
name: PDO CI Job
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, according to our docs, 20.04 is still the default. If we change it here maybe we should change it also there? And if change, why not change straight away to the latest LTS, 24.04?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember that this is the version only used for building the docker images. nothing else runs here. so its not actually related to our documented default version. i could go for a jump to 24.04 if that actually makes a difference. only wanted this for improved docker commands.


strategy:
matrix:
Expand All @@ -17,7 +17,16 @@ jobs:

steps:
- name: Check out repo
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
fetch-tags: true

- name: Display branch name
run: |
echo "Building branch $GITHUB_HEAD_REF"
echo PDO VERSION is $(bin/get_version)

- name: Build and run tests
if: "!contains(github.event.commits[0].message, '[debug]')"
Expand Down
3 changes: 3 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0.3.0 5fa37a13fac2749b1a6a43039ed2bee16d6cc70e
0.2.0 90884c67bf6c1445f96e068c5c06904a89de2411
0.1.0 cd993a69cd5955ebfe5a9e74b37e26c1b479ddce
69 changes: 38 additions & 31 deletions bin/get_version
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,42 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import pathlib
import subprocess
import sys
import warnings

count = 0
commit = ''
dirty = ''

try :
output = subprocess.check_output(['git', 'describe', '--dirty'])
(version, *rest) = output.decode('utf-8').strip().split('-')
(major, minor, patch) = version.strip('v').split('.')

# first case: this is a dirty tagged release, only dirty flag
if len(rest) == 1 :
assert rest[0] == 'dirty'
dirty = 'dirty'
# second case: this is a committed post tag release
elif len(rest) == 2 :
count = rest[0]
commit = rest[1]
# third case: this is a dirty, committed post tag release
elif len(rest) == 3 :
assert rest[2] == 'dirty'
count = rest[0]
commit = rest[1]
dirty = rest[2]

print('{}.{}.{}'.format(major, minor, count))
except Exception as e :
warnings.warn('failed to compute version, using default')
print('0.0.0')

pdo_source_root=pathlib.Path(__file__).parent.parent
version_file = pdo_source_root / 'VERSION'

parser = argparse.ArgumentParser()

parser.add_argument(
'--version-file', '-f',
help=f'File where version information is stored (default: {version_file})',
type=str)

options = parser.parse_args()

if options.version_file :
version_file = pathlib.Path(options.version_file)
pdo_source_root = version_file.parent

# the version file is a tab separated list of version numbers and git commit hashes in reverse
# order (newest is at the top of the file)
with open(version_file, 'r') as vf :
(version, commit, *rest) = vf.readline().strip().split('\t')

# the version is of the form x.y.z, there may be an optional 'v' at the beginning of the version
# string
(major, minor, patch) = version.strip('v').split('.')

# compute the number of commits since the tagged version was
# committed to the repository
command = ['git', 'rev-list', commit + '...HEAD', '--count']
output = subprocess.run(command, cwd=pdo_source_root, capture_output=True, text=True)
count = output.stdout.strip()

# the actual patch version number is the recorded patch number added to the number of commits
# since the version was committed
print('{}.{}.{}'.format(major, minor, int(patch) + int(count)))
100 changes: 100 additions & 0 deletions bin/set_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python3

# Copyright 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Add a new version to the version file. The version file is a tab separated list of version numbers
# and git commit hashes in reverse order (newest is at the top of the file). The version may contain
# a short description as well.

import argparse
import datetime
import os
import pathlib
import subprocess

pdo_source_root=pathlib.Path(__file__).parent.parent
version_file = pdo_source_root / 'VERSION'

parser = argparse.ArgumentParser()

parser.add_argument(
'--version-file', '-f',
help=f'File where version information is stored (default: {version_file})',
type=str)

parser.add_argument(
'--version', '-v',
help='Version to commit, form <major>.<minor>.<patch> (default: increment minor version by one and reset patch level)',
type=str)

parser.add_argument(
'--description', '-d',
help='Optional description to add to the version',
type=str)

parser.add_argument(
'--commit', '-c',
help='Hash of the git commit to associate with the version (default: commit at HEAD)',
type=str)

options = parser.parse_args()

# Get the VERSION file and current source path
if options.version_file :
version_file = pathlib.Path(options.version_file)
pdo_source_root = version_file.parent

# Compute the new version, by default the version will increment the minor version of the most
# recent version and reset the patch level. the version is of the form x.y.z, there may be an
# optional 'v' at the beginning of the version string
if options.version :
version = options.version
(major, minor, patch) = version.strip('v').split('.')

major = int(major)
minor = int(minor)
patch = int(patch)

else :
# get the current version information from the version file
with open(version_file, 'r') as vf :
(version, commit, *rest) = vf.readline().strip().split('\t')

(major, minor, patch) = version.strip('v').split('.')

major = int(major)
minor = int(minor) + 1
patch = 0

# Compute the commit to associate with the new version
if options.commit :
command = ['git', 'rev-parse', options.commit]
else :
command = ['git', 'rev-parse', 'HEAD']

output = subprocess.run(command, cwd=pdo_source_root, capture_output=True, text=True)
output.check_returncode()
commit = output.stdout.strip()

description = str(datetime.date.today())
if options.description :
description += f' {options.description}'

# Finally write the new version out to the VERSION file
version_entry = f'{major}.{minor}.{patch}\t{commit}\t{description}'
with open(version_file, 'r+') as vf :
content = vf.read()
vf.seek(0,0)
vf.write(version_entry + '\n' + content)
8 changes: 6 additions & 2 deletions build/cmake/ProjectVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ ENDIF()
# the version if something goes wrong (like running
# without any annotated version tags)
EXECUTE_PROCESS(
COMMAND ./get_version
WORKING_DIRECTORY ${PDO_SOURCE_ROOT}/bin
COMMAND ${PDO_SOURCE_ROOT}/bin/get_version
WORKING_DIRECTORY ${PDO_SOURCE_ROOT}
OUTPUT_VARIABLE PDO_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

IF (NOT PDO_VERSION)
MESSAGE(FATAL_ERROR "Unable to compute PDO_VERSION")
ENDIF()
2 changes: 1 addition & 1 deletion docker/pdo_base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ARG ADD_APT_PKGS=

ENV DEBIAN_FRONTEND "noninteractive"
RUN apt-get update \
&& apt-get install -y -q \
&& apt-get install -y -q --no-install-recommends \
autoconf \
automake \
build-essential \
Expand Down
5 changes: 3 additions & 2 deletions docker/pdo_ccf_base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ARG ADD_APT_PKGS=

ENV DEBIAN_FRONTEND "noninteractive"
RUN apt-get update \
&& apt-get install -y -q \
&& apt-get install -y -q --no-install-recommends \
libsecp256k1-dev \
lsof \
python \
Expand All @@ -46,8 +46,9 @@ RUN apt-get update \
RUN echo "deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu ${UBUNTU_NAME} main" >> /etc/apt/sources.list
RUN curl https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -


RUN apt-get update \
&& apt-get install -y \
&& apt-get install -y --no-install-recommends \
sgx-aesm-service \
libsgx-dcap-ql \
libsgx-urts \
Expand Down