Skip to content

Commit 7563f5f

Browse files
committed
New release workflow
1 parent c30ee87 commit 7563f5f

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

.github/workflows/release.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Release"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
branch_client_python:
7+
type: string
8+
default: 'main'
9+
required: false
10+
previous_version:
11+
type: string
12+
default: ''
13+
required: false
14+
new_version:
15+
type: string
16+
default: ''
17+
required: false
18+
19+
jobs:
20+
release:
21+
name: Release
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: checkout repo content
25+
uses: actions/checkout@v4
26+
- name: setup python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: 3.8 #install the python needed
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
if [ -f scripts/requirements.txt ]; then pip install -r scripts/requirements.txt; fi
34+
- name: execute py script # run file
35+
run: |
36+
python scripts/release.py ${{ github.event.inputs.branch_client_python }} ${{ github.event.inputs.previous_version }} ${{ github.event.inputs.new_version }}

scripts/release.py

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
import os
3+
import logging
4+
import time
5+
import requests
6+
import argparse
7+
from OBAS_utils.release_utils import closeRelease
8+
9+
logging.basicConfig(encoding="utf-8", level=logging.INFO)
10+
11+
parser = argparse.ArgumentParser("release")
12+
parser.add_argument("branch_client_python", help="The new version number of the release.", type=str)
13+
parser.add_argument("previous_version", help="The previous version number of the release.", type=str)
14+
parser.add_argument("new_version", help="The new version number of the release.", type=str)
15+
parser.add_argument("--dev", help="Flag to prevent pushing the release.", action="store_false")
16+
args = parser.parse_args()
17+
18+
previous_version = args.previous_version
19+
new_version = args.new_version
20+
branch_client_python = args.branch_client_python
21+
22+
github_token = os.environ["GREN_GITHUB_TOKEN"]
23+
24+
os.environ["DRONE_COMMIT_AUTHOR"] = "Filigran-Automation"
25+
os.environ["GIT_AUTHOR_NAME"] = "Filigran Automation"
26+
os.environ["GIT_AUTHOR_EMAIL"] = "[email protected]"
27+
os.environ["GIT_COMMITTER_NAME"] = "Filigran Automation"
28+
os.environ["GIT_COMMITTER_EMAIL"] = "[email protected]"
29+
30+
# Python library release
31+
logging.info("[client-python] Starting the release")
32+
with open("./pyobas/__init__.py", "r") as file:
33+
filedata = file.read()
34+
filedata = filedata.replace(previous_version, new_version)
35+
with open("./pyobas/__init__.py", "w") as file:
36+
file.write(filedata)
37+
with open("./pyobas/_version.py", "r") as file:
38+
filedata = file.read()
39+
filedata = filedata.replace(previous_version, new_version)
40+
with open("./pyobas/_version.py", "w") as file:
41+
file.write(filedata)
42+
43+
# Commit the change
44+
logging.info("[client-python] Pushing to " + branch_client_python)
45+
os.system(
46+
'git commit -a -m "[client] Release '
47+
+ new_version
48+
+ '" > /dev/null 2>&1')
49+
if not args.dev :
50+
os.system('git push origin '
51+
+ branch_client_python
52+
+ " > /dev/null 2>&1"
53+
)
54+
55+
logging.info("[client-python] Tagging")
56+
os.system(
57+
"git tag -f "
58+
+ new_version
59+
)
60+
if not args.dev :
61+
os.system(
62+
"git push -f --tags > /dev/null 2>&1"
63+
)
64+
65+
logging.info("[client-python] Generating release")
66+
os.system("gren release > /dev/null 2>&1")
67+
68+
# Modify the release note
69+
logging.info("[client-python] Getting the current release note")
70+
release = requests.get(
71+
"https://api.github.com/repos/OpenBAS-Platform/client-python/releases/latest",
72+
headers={
73+
"Accept": "application/vnd.github+json",
74+
"Authorization": "Bearer " + github_token,
75+
"X-GitHub-Api-Version": "2022-11-28",
76+
},
77+
)
78+
release_data = release.json()
79+
release_body = release_data["body"]
80+
81+
logging.info("[client-python] Generating the new release note")
82+
if not args.dev :
83+
github_release_note = requests.post(
84+
"https://api.github.com/repos/OpenBAS-Platform/client-python/releases/generate-notes",
85+
headers={
86+
"Accept": "application/vnd.github+json",
87+
"Authorization": "Bearer " + github_token,
88+
"X-GitHub-Api-Version": "2022-11-28",
89+
},
90+
json={"tag_name": new_version, "previous_tag_name": previous_version},
91+
)
92+
github_release_note_data = github_release_note.json()
93+
github_release_note_data_body = github_release_note_data["body"]
94+
if "Full Changelog" not in release_body:
95+
new_release_note = (
96+
release_body
97+
+ "\n"
98+
+ github_release_note_data_body.replace(
99+
"## What's Changed", "#### Pull Requests:\n"
100+
).replace("## New Contributors", "#### New Contributors:\n")
101+
)
102+
else:
103+
new_release_note = release_body
104+
105+
logging.info("[client-python] Updating the release")
106+
requests.patch(
107+
"https://api.github.com/repos/OpenBAS-Platform/client-python/releases/"
108+
+ str(release_data["id"]),
109+
headers={
110+
"Accept": "application/vnd.github+json",
111+
"Authorization": "Bearer " + github_token,
112+
"X-GitHub-Api-Version": "2022-11-28",
113+
},
114+
json={"body": new_release_note},
115+
)
116+
117+
if not args.dev :
118+
closeRelease("https://api.github.com/repos/OpenBAS-Platform/client-python", new_version, github_token)
119+
120+
logging.info(
121+
"[client-python] Release done! Waiting 10 minutes for CI/CD and publication..."
122+
)
123+
124+
if not args.dev :
125+
time.sleep(600)

scripts/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PyYAML
2+
requests
3+
git+https://github.com/OpenBAS-Platform/release.git@improvement/new_release_workflow

0 commit comments

Comments
 (0)