Skip to content

Commit b43993d

Browse files
author
k9ert
authored
Bugfix: release helper (#2449)
* fix release_helper lazy gl property * fix yet another property * add dependency of jobs
1 parent c2cd77f commit b43993d

File tree

2 files changed

+66
-70
lines changed

2 files changed

+66
-70
lines changed

.gitlab-ci.yml

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ variables:
88

99
cache:
1010
# enable per-job and per-branch caching
11-
- key:
12-
files:
11+
- key:
12+
files:
1313
- ./requirements.txt
1414
prefix: "$CI_JOB_NAME"
1515
paths:
@@ -25,14 +25,14 @@ before_script:
2525
- docker info || echo "no docker-command found" # Print out docker version for debugging
2626
- echo CI_PROJECT_NAMESPACE = $CI_PROJECT_NAMESPACE
2727
- echo CI_PROJECT_ROOT_NAMESPACE = $CI_PROJECT_ROOT_NAMESPACE
28-
- python -V # Print out python version for debugging
28+
- python -V # Print out python version for debugging
2929
- apt update
3030
- apt install -y libusb-1.0-0-dev libudev-dev # usb-support in hidapi
3131
# https://github.com/python-babel/babel/issues/990#issuecomment-1760326334
3232
- rm -f /etc/localtime
3333
- ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime
34-
# This doesn't get cached in gitlab but we don't need it anyway for now:
35-
# - ./tests/install_noded.sh --debug --elements compile
34+
# This doesn't get cached in gitlab but we don't need it anyway for now:
35+
# - ./tests/install_noded.sh --debug --elements compile
3636
- pip3 install --upgrade virtualenv
3737
- virtualenv --python=python3 .env
3838
- source .env/bin/activate
@@ -48,20 +48,20 @@ check:
4848
# So effectively, gitlab is currently only used for releasing.
4949

5050
.test:
51-
stage: testing
52-
# We assume here that people who want to get code into the master-branch are
53-
# relying on PRs and people who are working on gitlab-forks are working
54-
# on CI which probably want fast feedback on the releasing-jobs
55-
# and therefore skip the test-job
56-
# tem deactivated as it did not work as expected
57-
#only:
58-
# - $CI_PROJECT_ROOT_NAMESPACE =~ "cryptoadvance"
59-
script:
60-
- pip3 install -r requirements.txt
61-
- pip3 install -e .
62-
- pip3 install -e ".[test]"
63-
- python3 setup.py install # compiles babel stuff as well (might make pip install obsolete)
64-
- py.test --cov-report term --cov cryptoadvance
51+
stage: testing
52+
# We assume here that people who want to get code into the master-branch are
53+
# relying on PRs and people who are working on gitlab-forks are working
54+
# on CI which probably want fast feedback on the releasing-jobs
55+
# and therefore skip the test-job
56+
# tem deactivated as it did not work as expected
57+
#only:
58+
# - $CI_PROJECT_ROOT_NAMESPACE =~ "cryptoadvance"
59+
script:
60+
- pip3 install -r requirements.txt
61+
- pip3 install -e .
62+
- pip3 install -e ".[test]"
63+
- python3 setup.py install # compiles babel stuff as well (might make pip install obsolete)
64+
- py.test --cov-report term --cov cryptoadvance
6565

6666
.test-cypress:
6767
image: registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python-jammy:v9.7.0
@@ -83,7 +83,7 @@ check:
8383

8484
release_pip:
8585
stage: releasing
86-
only:
86+
only:
8787
- tags
8888
script:
8989
- pip3 install -e .
@@ -112,10 +112,10 @@ release_pip:
112112

113113
release_binary_windows:
114114
stage: releasing
115-
only:
115+
only:
116116
- tags
117117
variables:
118-
GIT_DEPTH: 0 # Disable shallow clone to get all Git history
118+
GIT_DEPTH: 0 # Disable shallow clone to get all Git history
119119
tags:
120120
- windows
121121
before_script:
@@ -125,13 +125,13 @@ release_binary_windows:
125125
- pip install virtualenv
126126
- virtualenv --python=python3 .env
127127
- .\.env\Scripts\activate
128-
- pip3 install -e ".[test]"
129-
128+
- pip3 install -e ".[test]"
129+
130130
script:
131131
# This script won't execute if the script before that fails
132132
# No need to check the version-scheme again
133133

134-
- echo "Releasing for ${CI_PROJECT_ROOT_NAMESPACE}"
134+
- echo "Releasing for ${CI_PROJECT_ROOT_NAMESPACE}"
135135
- .\pyinstaller\build-win-ci.bat $CI_COMMIT_TAG
136136
- python ./utils/github.py upload ./pyinstaller/release/specterd-$CI_COMMIT_TAG-win64.zip
137137
- cd ./pyinstaller/release
@@ -145,21 +145,21 @@ release_binary_windows:
145145
expire_in: 1 day
146146
cache:
147147
key:
148-
files:
149-
- ./pyinstaller/electron/package-lock.json
150-
prefix: $CI_JOB_NAME
148+
files:
149+
- ./pyinstaller/electron/package-lock.json
150+
prefix: $CI_JOB_NAME
151151
paths:
152152
- ./pyinstaller/electron/node_modules
153153

154154
release_electron_linux_windows:
155155
image: registry.gitlab.com/cryptoadvance/specter-desktop/electron-builder:latest
156156
stage: releasing
157-
only:
157+
only:
158158
- tags
159159
needs:
160160
- release_binary_windows
161161
before_script:
162-
- python3 -V # Print out python version for debugging
162+
- python3 -V # Print out python version for debugging
163163
- apt update
164164
- apt install -y unzip libusb-1.0-0-dev libudev-dev # usb-support in hidapi
165165
- pip3 install virtualenv
@@ -184,17 +184,17 @@ release_electron_linux_windows:
184184
- ./utils/artifact_signer.sh sign --artifact ./release/SHA256SUMS-win
185185
- ./utils/artifact_signer.sh sign --artifact ./release/SHA256SUMS-linux
186186
- python3 ./utils/github.py upload ./release/Specter-Setup-${CI_COMMIT_TAG}.exe
187-
- python3 ./utils/github.py upload ./release/specterd-${CI_COMMIT_TAG}-x86_64-linux-gnu.zip
188-
- python3 ./utils/github.py upload ./release/specter_desktop-${CI_COMMIT_TAG}-x86_64-linux-gnu.tar.gz
187+
- python3 ./utils/github.py upload ./release/specterd-${CI_COMMIT_TAG}-x86_64-linux-gnu.zip
188+
- python3 ./utils/github.py upload ./release/specter_desktop-${CI_COMMIT_TAG}-x86_64-linux-gnu.tar.gz
189189
#- python3 ../utils/github.py upload ./release/SHA256SUMS-linux
190190
#- python3 ../utils/github.py upload ./release/SHA256SUMS-linux.asc
191191
#- python3 ../utils/github.py upload ./release/SHA256SUMS-win
192192
#- python3 ../utils/github.py upload ./release/SHA256SUMS-win.asc
193193
cache:
194194
key:
195-
files:
196-
- ./pyinstaller/electron/package-lock.json
197-
prefix: $CI_JOB_NAME
195+
files:
196+
- ./pyinstaller/electron/package-lock.json
197+
prefix: $CI_JOB_NAME
198198
paths:
199199
- ./pyinstaller/electron/node_modules
200200

@@ -212,28 +212,28 @@ release_electron_linux_windows:
212212

213213
release_signatures:
214214
stage: post_releasing
215-
only:
215+
only:
216216
- tags
217217
before_script:
218-
- python -V # Print out python version for debugging
218+
- python -V # Print out python version for debugging
219219
- pip3 install --upgrade virtualenv
220220
- virtualenv --python=python3 .env
221221
- source .env/bin/activate
222222
- pip3 install -e ".[test]"
223223
- ./utils/artifact_signer.sh init # prepare .gnupg
224224
script:
225-
- python3 -m utils.release_helper download # downloads the job-artifacts from gitlab
226-
- python3 -m utils.release_helper downloadgithub # downloads additional artifacts from github (if not there and is they have SHA256SUMS-something)
227-
- python3 -m utils.release_helper checksigs # checks the signatures of all SHA256SUMM*.asc files
228-
- python3 -m utils.release_helper checkhashes # checks all SHA256SUM* files (might modify files on the fly due to windows line endings)
229-
- python3 -m utils.release_helper create # creates a SHA256SUM
225+
- python3 -m utils.release_helper download # downloads the job-artifacts from gitlab
226+
- python3 -m utils.release_helper downloadgithub # downloads additional artifacts from github (if not there and is they have SHA256SUMS-something)
227+
- python3 -m utils.release_helper checksigs # checks the signatures of all SHA256SUMM*.asc files
228+
- python3 -m utils.release_helper checkhashes # checks all SHA256SUM* files (might modify files on the fly due to windows line endings)
229+
- python3 -m utils.release_helper create # creates a SHA256SUM
230230
- ./utils/artifact_signer.sh sign --artifact ./signing_dir/SHA256SUMS # Signs the SHA256SUM
231-
- python3 -m utils.release_helper upload_shasums # uploads SHA256SUMS to github
231+
- python3 -m utils.release_helper upload_shasums # uploads SHA256SUMS to github
232232
- python3 -m utils.release_helper upload_shasumssig # uploads SHA256SUMS.asc to github
233233

234234
release_docker:
235235
stage: post_releasing
236-
only:
236+
only:
237237
- tags
238238
before_script:
239239
- echo "Triggering Docker Release"
@@ -257,6 +257,8 @@ update_github:
257257
stage: post_releasing
258258
only:
259259
- tags
260+
needs:
261+
- release_signatures
260262
before_script:
261263
# write access to [email protected]:swan-bitcoin/specter-static.git
262264
- source ./utils/prepare_for_git_write.sh "$SSH_SPECTERSTATIC_DEPLOY_KEY"
@@ -268,6 +270,8 @@ update_webpage:
268270
stage: post_releasing
269271
only:
270272
- tags
273+
needs:
274+
- release_signatures
271275
before_script:
272276
# write access to [email protected]:swan-bitcoin/specter-static.git
273277
- source ./utils/prepare_for_git_write.sh "$SSH_SPECTERSTATIC_DEPLOY_KEY"

utils/release_helper.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ class ReleaseHelper:
185185
(format: export CI_PIPELINE_ID=<pipeline_id>).
186186
CI_PROJECT_ROOT_NAMESPACE: The root namespace of the CI project
187187
(required for uploading to GitHub).
188-
GH_BIN_UPLOAD_PW: Password or token for GitHub to authenticate uploads.
188+
GH_BIN_UPLOAD_PW: gh_token or token for GitHub to authenticate uploads.
189189
190190
Attributes:
191191
target_dir (str): The directory path where artifacts are to be managed.
192192
tag (str): The git tag associated with the artifacts being managed.
193193
pipeline_id (str): The CI pipeline ID for artifact management operations.
194194
pipeline (Pipeline): A pipeline object fetched from the CI server.
195195
github_project (str): The GitHub repository in which the release should be created or updated.
196-
password (str): The password or token used to authenticate with GitHub.
196+
gh_token (str): The password or token used to authenticate with GitHub.
197197
198198
Methods:
199199
download_and_unpack_all_artifacts(): Downloads and unpacks artifacts from a CI pipeline.
@@ -269,7 +269,7 @@ def ci_project_id(self):
269269
return self._ci_project_id
270270
if os.environ.get("CI_PROJECT_ID"):
271271
self._ci_project_id = os.environ.get("CI_PROJECT_ID")
272-
logger.info(f"Using ci_project_id: {self.ci_project_id} ")
272+
logger.info(f"Using ci_project_id: {self._ci_project_id} ")
273273
else:
274274
logger.error("No Project given. choose one:")
275275
for project in self.gl.projects.list(search="specter-desktop"):
@@ -291,6 +291,19 @@ def github_project(self):
291291
logger.info(f"Using github_project: {self._github_project}")
292292
return self._github_project
293293

294+
@property
295+
def gh_token(self):
296+
if hasattr(self, "_gh_token"):
297+
return self._gh_token
298+
if os.environ.get("GH_BIN_UPLOAD_PW"):
299+
self._gh_token = os.environ.get("GH_BIN_UPLOAD_PW")
300+
logger.info(f"Using gh_token: REDACTED")
301+
else:
302+
raise Exception(
303+
"no Github token given ( export GH_BIN_UPLOAD_PW=v0.0.0.0-pre13 )"
304+
)
305+
return self._gh_token
306+
294307
@property
295308
def ci_commit_tag(self):
296309
if hasattr(self, "_ci_commit_tag"):
@@ -454,28 +467,8 @@ def check_all_sigs(self):
454467
)
455468
logger.info("All files *.asc has valid signatures")
456469

457-
def calculate_publish_params(self):
458-
if not "CI_PROJECT_ROOT_NAMESPACE" in os.environ:
459-
logger.error("CI_PROJECT_ROOT_NAMESPACE not found")
460-
exit(2)
461-
else:
462-
self.github_project = (
463-
f"{os.environ['CI_PROJECT_ROOT_NAMESPACE']}/specter-desktop"
464-
)
465-
if not "CI_COMMIT_TAG" in os.environ:
466-
logger.error("CI_COMMIT_TAG not found")
467-
exit(2)
468-
else:
469-
tag = os.environ["CI_COMMIT_TAG"]
470-
if not "GH_BIN_UPLOAD_PW" in os.environ:
471-
logger.error("GH_BIN_UPLOAD_PW not found.")
472-
exit(2)
473-
else:
474-
self.password = os.environ["GH_BIN_UPLOAD_PW"]
475-
476470
def upload_sha256sum_file(self):
477471
artifact = os.path.join("signing_dir", "SHA256SUMS")
478-
self.calculate_publish_params()
479472

480473
if github.artifact_exists(
481474
self.github_project, self.ci_commit_tag, Path(artifact).name
@@ -489,12 +482,11 @@ def upload_sha256sum_file(self):
489482
self.ci_commit_tag,
490483
[artifact],
491484
"gitlab_upload_release_binaries",
492-
self.password,
485+
self.gh_token,
493486
)
494487

495488
def upload_sha256sumsig_file(self):
496489
artifact = os.path.join("signing_dir", "SHA256SUMS.asc")
497-
self.calculate_publish_params()
498490

499491
if github.artifact_exists(
500492
self.github_project, self.ci_commit_tag, Path(artifact).name
@@ -508,7 +500,7 @@ def upload_sha256sumsig_file(self):
508500
self.ci_commit_tag,
509501
[artifact],
510502
"gitlab_upload_release_binaries",
511-
self.password,
503+
self.gh_token,
512504
)
513505

514506

0 commit comments

Comments
 (0)