Skip to content

Commit 61cc7b1

Browse files
authored
feat: add release action to release .whl (#177)
https://tier4.atlassian.net/browse/T4PB-22573
1 parent 410d5c6 commit 61cc7b1

File tree

11 files changed

+137
-40
lines changed

11 files changed

+137
-40
lines changed

.github/workflows/merged.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: push main
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types: [closed]
8+
9+
jobs:
10+
update_version:
11+
runs-on: ubuntu-20.04
12+
if: github.event.pull_request.merged == true
13+
timeout-minutes: 10
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v2
17+
18+
- name: setup python
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: 3.8
22+
23+
- name: install packages
24+
run: >-
25+
python -m pip install -r proto/requirements.txt
26+
27+
- name: protobuf build
28+
run: |
29+
cd proto
30+
make
31+
32+
- name: update .proto_hash
33+
run: |
34+
cd proto
35+
proto_hash=$(python3 proto_hash.py)
36+
if [ ${proto_hash} != $(cat .proto_hash) ]; then
37+
echo ${proto_hash} > .proto_hash
38+
python3 increment_minor.py $(cat .version) > .version
39+
fi
40+
make clean
41+
42+
- uses: stefanzweifel/git-auto-commit-action@v4
43+
with:
44+
commit_message: update otaclient_pb2 hash and version
45+
file_pattern: ':/proto/.version :/proto/.proto_hash'
46+
branch: main

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-20.04
11+
timeout-minutes: 10
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v2
15+
16+
- name: setup python
17+
uses: actions/setup-python@v1
18+
with:
19+
python-version: 3.8
20+
21+
- name: install packages
22+
run: >-
23+
python -m pip install -r proto/requirements.txt
24+
25+
- name: build a binary
26+
run: >-
27+
python -m
28+
build
29+
--wheel
30+
--outdir dist/
31+
.
32+
33+
- name: build a proto binary
34+
run: |
35+
cd proto
36+
make
37+
38+
- name: release
39+
uses: softprops/action-gh-release@v1
40+
with:
41+
files: |
42+
dist/*.whl
43+
proto/pb2/dist/*.whl

proto/.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
build
2-
*egg-info
3-
pb2/otaclient_pb2
1+
pb2/*
2+
!pb2/setup.py

proto/.proto_hash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f4e5081b9efdbf1aa095cecff4781b1ddc4be603fefe542a7cea60739ab7a83f
File renamed without changes.

proto/Makefile

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
PB2_OUT_BASE_DIR := pb2
22
PB2_OUT_DIR := $(PB2_OUT_BASE_DIR)/otaclient_pb2
33

4+
DEPS = $(PB2_OUT_DIR)/v2/otaclient.proto \
5+
$(PB2_OUT_DIR)/v2/otaclient_pb2_grpc.py \
6+
$(PB2_OUT_DIR)/v2/otaclient_pb2.py \
7+
$(PB2_OUT_DIR)/v2/__init__.py \
8+
$(PB2_OUT_DIR)/__init__.py
9+
410
.PHONY: all
5-
all: whl
11+
all: setup whl
612

7-
.PHONY: clean
8-
clean:
9-
rm -rf build *.egg-info dist $(PB2_OUT_DIR)
10-
rm -rf pb2/build pb2/*.egg-info pb2/dist
13+
$(PB2_OUT_DIR)/v2/otaclient.proto: otaclient_v2.proto
14+
mkdir -p $(dir $@)
15+
cp -a $< $@
16+
17+
$(PB2_OUT_DIR)/v2/otaclient_pb2_grpc.py $(PB2_OUT_DIR)/v2/otaclient_pb2.py: $(PB2_OUT_DIR)/v2/otaclient.proto
18+
python3 -m grpc_tools.protoc \
19+
-I$(PB2_OUT_BASE_DIR) \
20+
--python_out=$(PB2_OUT_BASE_DIR) \
21+
--grpc_python_out=$(PB2_OUT_BASE_DIR) \
22+
./$(PB2_OUT_DIR)/v2/otaclient.proto
1123

12-
.PHONY: build
13-
build:
14-
rm -rf build $(PB2_OUT_DIR)
15-
mkdir -p $(PB2_OUT_DIR)/v2
16-
cp -a ./otaclient_v2.proto $(PB2_OUT_DIR)/v2/otaclient.proto
17-
python3 -m grpc_tools.protoc -I$(PB2_OUT_BASE_DIR) --python_out=$(PB2_OUT_BASE_DIR) --grpc_python_out=$(PB2_OUT_BASE_DIR) ./$(PB2_OUT_DIR)/v2/otaclient.proto
18-
for dir in $$(find $(PB2_OUT_DIR) -type d); do touch $${dir}/__init__.py; done
24+
$(PB2_OUT_DIR)/__init__.py $(PB2_OUT_DIR)/v2/__init__.py:
25+
touch $@
1926

20-
.PHONY: install
21-
install:
22-
python3 -m pip install --force-reinstall $$(ls -rv ./whl/otaclient_pb2-*-py3-none-any.whl | head -n 1)
27+
.PHONY: setup
28+
setup:
29+
python3 -m pip install --upgrade pip
30+
python3 -m pip install --upgrade setuptools wheel
31+
python3 -m pip install -r ../tests/requirements.txt
2332

2433
.PHONY: whl
25-
whl: build
26-
python3 -m pip install --upgrade pip setuptools wheel
27-
cd pb2; rm -rf build *.egg-info dist *.whl; mkdir -p ../whl
28-
cd pb2; python3 setup.py bdist_wheel; mv dist/*.whl ../whl/
34+
whl: $(DEPS)
35+
cd pb2; \
36+
python3 setup.py bdist_wheel;
37+
38+
.PHONY: clean
39+
clean:
40+
rm -rf pb2/dist pb2/build/ pb2/otaclient_pb2*

proto/increment_minor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
import semantic_version
3+
4+
v = semantic_version.Version(sys.argv[1])
5+
print(f"{v.major}.{v.minor + 1}.{v.patch}")

proto/pb2/setup.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,18 @@
1313
# limitations under the License.
1414

1515

16-
import os
1716
from setuptools import setup, find_packages
18-
import subprocess
1917

2018

2119
def get_version():
22-
current_dir = os.path.dirname(os.path.abspath(__file__))
23-
with open(os.path.join(current_dir, "..", "VERSION"), mode="r") as f:
24-
return f.read().strip()
25-
26-
27-
def get_git_hash():
28-
result = subprocess.run(
29-
["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE, text=True
30-
)
31-
return result.stdout.strip()
20+
return open("../.version").read().strip()
3221

3322

3423
pkg_name = "otaclient_pb2"
3524

36-
version = get_version()
37-
git_hash = get_git_hash()
38-
whl_version = f"{version}.{git_hash}"
39-
4025
setup(
4126
name=pkg_name,
42-
version=whl_version,
27+
version=get_version(),
4328
packages=find_packages(),
4429
description="ota client protobuf package",
4530
url="https://github.com/tier4/ota-client",

proto/proto_hash.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pb2.otaclient_pb2.v2.otaclient_pb2 as v2
2+
from hashlib import sha256
3+
4+
print(sha256(v2.DESCRIPTOR.serialized_pb).hexdigest())

proto/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
grpcio-tools==1.48.2
2+
semantic-version==2.10.0
3+
build==0.8.0

0 commit comments

Comments
 (0)