Skip to content

Commit

Permalink
Bugfix: release helper (#2449)
Browse files Browse the repository at this point in the history
* fix release_helper lazy gl property

* fix yet another property

* add dependency of jobs
  • Loading branch information
k9ert authored May 29, 2024
1 parent c2cd77f commit b43993d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 70 deletions.
92 changes: 48 additions & 44 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ variables:

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

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

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

release_pip:
stage: releasing
only:
only:
- tags
script:
- pip3 install -e .
Expand Down Expand Up @@ -112,10 +112,10 @@ release_pip:

release_binary_windows:
stage: releasing
only:
only:
- tags
variables:
GIT_DEPTH: 0 # Disable shallow clone to get all Git history
GIT_DEPTH: 0 # Disable shallow clone to get all Git history
tags:
- windows
before_script:
Expand All @@ -125,13 +125,13 @@ release_binary_windows:
- pip install virtualenv
- virtualenv --python=python3 .env
- .\.env\Scripts\activate
- pip3 install -e ".[test]"
- pip3 install -e ".[test]"

script:
# This script won't execute if the script before that fails
# No need to check the version-scheme again

- echo "Releasing for ${CI_PROJECT_ROOT_NAMESPACE}"
- echo "Releasing for ${CI_PROJECT_ROOT_NAMESPACE}"
- .\pyinstaller\build-win-ci.bat $CI_COMMIT_TAG
- python ./utils/github.py upload ./pyinstaller/release/specterd-$CI_COMMIT_TAG-win64.zip
- cd ./pyinstaller/release
Expand All @@ -145,21 +145,21 @@ release_binary_windows:
expire_in: 1 day
cache:
key:
files:
- ./pyinstaller/electron/package-lock.json
prefix: $CI_JOB_NAME
files:
- ./pyinstaller/electron/package-lock.json
prefix: $CI_JOB_NAME
paths:
- ./pyinstaller/electron/node_modules

release_electron_linux_windows:
image: registry.gitlab.com/cryptoadvance/specter-desktop/electron-builder:latest
stage: releasing
only:
only:
- tags
needs:
- release_binary_windows
before_script:
- python3 -V # Print out python version for debugging
- python3 -V # Print out python version for debugging
- apt update
- apt install -y unzip libusb-1.0-0-dev libudev-dev # usb-support in hidapi
- pip3 install virtualenv
Expand All @@ -184,17 +184,17 @@ release_electron_linux_windows:
- ./utils/artifact_signer.sh sign --artifact ./release/SHA256SUMS-win
- ./utils/artifact_signer.sh sign --artifact ./release/SHA256SUMS-linux
- python3 ./utils/github.py upload ./release/Specter-Setup-${CI_COMMIT_TAG}.exe
- python3 ./utils/github.py upload ./release/specterd-${CI_COMMIT_TAG}-x86_64-linux-gnu.zip
- python3 ./utils/github.py upload ./release/specter_desktop-${CI_COMMIT_TAG}-x86_64-linux-gnu.tar.gz
- python3 ./utils/github.py upload ./release/specterd-${CI_COMMIT_TAG}-x86_64-linux-gnu.zip
- python3 ./utils/github.py upload ./release/specter_desktop-${CI_COMMIT_TAG}-x86_64-linux-gnu.tar.gz
#- python3 ../utils/github.py upload ./release/SHA256SUMS-linux
#- python3 ../utils/github.py upload ./release/SHA256SUMS-linux.asc
#- python3 ../utils/github.py upload ./release/SHA256SUMS-win
#- python3 ../utils/github.py upload ./release/SHA256SUMS-win.asc
cache:
key:
files:
- ./pyinstaller/electron/package-lock.json
prefix: $CI_JOB_NAME
files:
- ./pyinstaller/electron/package-lock.json
prefix: $CI_JOB_NAME
paths:
- ./pyinstaller/electron/node_modules

Expand All @@ -212,28 +212,28 @@ release_electron_linux_windows:

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

release_docker:
stage: post_releasing
only:
only:
- tags
before_script:
- echo "Triggering Docker Release"
Expand All @@ -257,6 +257,8 @@ update_github:
stage: post_releasing
only:
- tags
needs:
- release_signatures
before_script:
# write access to [email protected]:swan-bitcoin/specter-static.git
- source ./utils/prepare_for_git_write.sh "$SSH_SPECTERSTATIC_DEPLOY_KEY"
Expand All @@ -268,6 +270,8 @@ update_webpage:
stage: post_releasing
only:
- tags
needs:
- release_signatures
before_script:
# write access to [email protected]:swan-bitcoin/specter-static.git
- source ./utils/prepare_for_git_write.sh "$SSH_SPECTERSTATIC_DEPLOY_KEY"
Expand Down
44 changes: 18 additions & 26 deletions utils/release_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ class ReleaseHelper:
(format: export CI_PIPELINE_ID=<pipeline_id>).
CI_PROJECT_ROOT_NAMESPACE: The root namespace of the CI project
(required for uploading to GitHub).
GH_BIN_UPLOAD_PW: Password or token for GitHub to authenticate uploads.
GH_BIN_UPLOAD_PW: gh_token or token for GitHub to authenticate uploads.
Attributes:
target_dir (str): The directory path where artifacts are to be managed.
tag (str): The git tag associated with the artifacts being managed.
pipeline_id (str): The CI pipeline ID for artifact management operations.
pipeline (Pipeline): A pipeline object fetched from the CI server.
github_project (str): The GitHub repository in which the release should be created or updated.
password (str): The password or token used to authenticate with GitHub.
gh_token (str): The password or token used to authenticate with GitHub.
Methods:
download_and_unpack_all_artifacts(): Downloads and unpacks artifacts from a CI pipeline.
Expand Down Expand Up @@ -269,7 +269,7 @@ def ci_project_id(self):
return self._ci_project_id
if os.environ.get("CI_PROJECT_ID"):
self._ci_project_id = os.environ.get("CI_PROJECT_ID")
logger.info(f"Using ci_project_id: {self.ci_project_id} ")
logger.info(f"Using ci_project_id: {self._ci_project_id} ")
else:
logger.error("No Project given. choose one:")
for project in self.gl.projects.list(search="specter-desktop"):
Expand All @@ -291,6 +291,19 @@ def github_project(self):
logger.info(f"Using github_project: {self._github_project}")
return self._github_project

@property
def gh_token(self):
if hasattr(self, "_gh_token"):
return self._gh_token
if os.environ.get("GH_BIN_UPLOAD_PW"):
self._gh_token = os.environ.get("GH_BIN_UPLOAD_PW")
logger.info(f"Using gh_token: REDACTED")
else:
raise Exception(
"no Github token given ( export GH_BIN_UPLOAD_PW=v0.0.0.0-pre13 )"
)
return self._gh_token

@property
def ci_commit_tag(self):
if hasattr(self, "_ci_commit_tag"):
Expand Down Expand Up @@ -454,28 +467,8 @@ def check_all_sigs(self):
)
logger.info("All files *.asc has valid signatures")

def calculate_publish_params(self):
if not "CI_PROJECT_ROOT_NAMESPACE" in os.environ:
logger.error("CI_PROJECT_ROOT_NAMESPACE not found")
exit(2)
else:
self.github_project = (
f"{os.environ['CI_PROJECT_ROOT_NAMESPACE']}/specter-desktop"
)
if not "CI_COMMIT_TAG" in os.environ:
logger.error("CI_COMMIT_TAG not found")
exit(2)
else:
tag = os.environ["CI_COMMIT_TAG"]
if not "GH_BIN_UPLOAD_PW" in os.environ:
logger.error("GH_BIN_UPLOAD_PW not found.")
exit(2)
else:
self.password = os.environ["GH_BIN_UPLOAD_PW"]

def upload_sha256sum_file(self):
artifact = os.path.join("signing_dir", "SHA256SUMS")
self.calculate_publish_params()

if github.artifact_exists(
self.github_project, self.ci_commit_tag, Path(artifact).name
Expand All @@ -489,12 +482,11 @@ def upload_sha256sum_file(self):
self.ci_commit_tag,
[artifact],
"gitlab_upload_release_binaries",
self.password,
self.gh_token,
)

def upload_sha256sumsig_file(self):
artifact = os.path.join("signing_dir", "SHA256SUMS.asc")
self.calculate_publish_params()

if github.artifact_exists(
self.github_project, self.ci_commit_tag, Path(artifact).name
Expand All @@ -508,7 +500,7 @@ def upload_sha256sumsig_file(self):
self.ci_commit_tag,
[artifact],
"gitlab_upload_release_binaries",
self.password,
self.gh_token,
)


Expand Down

0 comments on commit b43993d

Please sign in to comment.