Skip to content
Snippets Groups Projects
Commit 54d4c9f8 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

ci: Split windows job into build and deploy stages

parent b7cd7dcc
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3 #!/usr/bin/env python3
from typing import Any
import json
import os import os
import requests import requests
import time import time
...@@ -7,6 +10,7 @@ ...@@ -7,6 +10,7 @@
from rich.console import Console from rich.console import Console
ACCOUNT = 'lovetox' ACCOUNT = 'lovetox'
PROJECT_SLUG = 'gajim' PROJECT_SLUG = 'gajim'
BRANCH = 'master' BRANCH = 'master'
...@@ -67,7 +71,7 @@ def is_build_finished(build: dict[str, str]) -> bool: ...@@ -67,7 +71,7 @@ def is_build_finished(build: dict[str, str]) -> bool:
return build['status'] == 'success' return build['status'] == 'success'
def get_artifacts(build_id: str) -> None: def check_for_response(build_id: str) -> None:
time.sleep(INITIAL_START_DELAY) time.sleep(INITIAL_START_DELAY)
while True: while True:
time.sleep(RETRY_TIMEOUT) time.sleep(RETRY_TIMEOUT)
...@@ -89,28 +93,26 @@ def get_artifacts(build_id: str) -> None: ...@@ -89,28 +93,26 @@ def get_artifacts(build_id: str) -> None:
build_folder.mkdir() build_folder.mkdir()
for job in build['jobs']: for job in build['jobs']:
download_job_artifacts(job['jobId'], build_folder) response = get_job_response(job['jobId'])
result = build_folder / f'{job["jobId"]}.json'
console.print('All artifacts downloaded!') result.write_text(json.dumps(response))
console.print('Write job response:', result)
def download_job_artifacts(job_id: str, target_folder: Path) -> None: def get_job_response(job_id: str) -> list[dict[str, Any]]:
artifacts_api_url = f'{BASE_URL}/buildjobs/{job_id}/artifacts' artifacts_api_url = f'{BASE_URL}/buildjobs/{job_id}/artifacts'
req = requests.get(artifacts_api_url, headers=HEADERS) req = requests.get(artifacts_api_url, headers=HEADERS)
req.raise_for_status() req.raise_for_status()
response = req.json() response = req.json()
for artifact in response: for artifact in response:
filename = artifact['fileName'] file_url = f'{artifacts_api_url}/{artifact["fileName"]}'
console.print('Download', filename, '...') artifact['fileUrl'] = file_url
file_url = f'{artifacts_api_url}/{filename}'
req = requests.get(file_url, headers=HEADERS) return response
req.raise_for_status()
with open(target_folder / filename, 'wb') as file:
file.write(req.content)
if __name__ == '__main__': if __name__ == '__main__':
push_yaml_to_project() push_yaml_to_project()
build_id = start_build() build_id = start_build()
get_artifacts(build_id) check_for_response(build_id)
#!/usr/bin/env python3
from typing import Any from typing import Any
from typing import Optional from typing import Optional
import functools import functools
import json
import os import os
import sys import sys
from datetime import date from datetime import date
from ftplib import FTP_TLS from ftplib import FTP_TLS
from pathlib import Path from pathlib import Path
import requests
from rich.console import Console from rich.console import Console
...@@ -15,6 +19,9 @@ ...@@ -15,6 +19,9 @@
FTP_USER = os.environ['FTP_USER'] FTP_USER = os.environ['FTP_USER']
FTP_PASS = os.environ['FTP_PASS'] FTP_PASS = os.environ['FTP_PASS']
API_KEY = os.environ['APPVEYOR_API_KEY']
HEADERS = {'Authorization': f'Bearer {API_KEY}'}
WINDOWS_NIGHTLY_FOLDER = 'downloads/snap/win' WINDOWS_NIGHTLY_FOLDER = 'downloads/snap/win'
LINUX_NIGHTLY_FOLDER = 'downloads/snap' LINUX_NIGHTLY_FOLDER = 'downloads/snap'
...@@ -84,6 +91,29 @@ def upload_file(ftp: FTP_TLS, ...@@ -84,6 +91,29 @@ def upload_file(ftp: FTP_TLS,
ftp.storbinary('STOR ' + name, f) ftp.storbinary('STOR ' + name, f)
def download_artifacts(path: Path) -> None:
build_results = list(path.glob('*.json'))
if not build_results:
sys.exit('No build build_results found')
responses = [json.loads(response.read_text()) for response in build_results]
for response in responses:
for artifact in response:
filename = artifact['fileName']
file_url = artifact['fileUrl']
console.print('Download', filename, '...')
req = requests.get(file_url, headers=HEADERS)
req.raise_for_status()
with open(path / filename, 'wb') as file:
file.write(req.content)
for result in build_results:
result.unlink()
def get_deploy_method() -> str: def get_deploy_method() -> str:
deploy_type = os.environ['DEPLOY_TYPE'] deploy_type = os.environ['DEPLOY_TYPE']
is_nightly = bool(os.environ.get('GAJIM_NIGHTLY_BUILD')) is_nightly = bool(os.environ.get('GAJIM_NIGHTLY_BUILD'))
...@@ -95,6 +125,7 @@ def get_deploy_method() -> str: ...@@ -95,6 +125,7 @@ def get_deploy_method() -> str:
@ftp_connection @ftp_connection
def deploy_windows_nightly(ftp: FTP_TLS, filedir: Path) -> None: def deploy_windows_nightly(ftp: FTP_TLS, filedir: Path) -> None:
ftp.cwd(WINDOWS_NIGHTLY_FOLDER) ftp.cwd(WINDOWS_NIGHTLY_FOLDER)
download_artifacts(filedir)
upload_all_from_dir(ftp, filedir) upload_all_from_dir(ftp, filedir)
...@@ -102,6 +133,7 @@ def deploy_windows_nightly(ftp: FTP_TLS, filedir: Path) -> None: ...@@ -102,6 +133,7 @@ def deploy_windows_nightly(ftp: FTP_TLS, filedir: Path) -> None:
def deploy_windows_release(ftp: FTP_TLS, filedir: Path) -> None: def deploy_windows_release(ftp: FTP_TLS, filedir: Path) -> None:
tag = get_gajim_tag() tag = get_gajim_tag()
create_release_folder(ftp, tag) create_release_folder(ftp, tag)
download_artifacts(filedir)
upload_all_from_dir(ftp, filedir) upload_all_from_dir(ftp, filedir)
......
...@@ -84,22 +84,18 @@ build-linux: ...@@ -84,22 +84,18 @@ build-linux:
paths: paths:
- dist/gajim-*.tar.gz - dist/gajim-*.tar.gz
build-and-deploy-windows: build-windows:
stage: build stage: build
dependencies: [] dependencies: []
rules: rules:
- if: '$GAJIM_NIGHTLY_BUILD' - if: '$GAJIM_NIGHTLY_BUILD'
- if: '$CI_COMMIT_TAG' - if: '$CI_COMMIT_TAG'
variables:
DEPLOY_TYPE: "windows"
script: script:
- python3 .ci/appveyor_build.py - python3 .ci/appveyor_build.py
- python3 .ci/deploy.py build artifacts:
expire_in: 1 day
# artifacts: paths:
# expire_in: 1 day - build/*.json
# paths:
# - build/Gajim-*.exe
deploy-linux: deploy-linux:
stage: deploy stage: deploy
...@@ -113,16 +109,17 @@ deploy-linux: ...@@ -113,16 +109,17 @@ deploy-linux:
script: script:
- python3 .ci/deploy.py dist - python3 .ci/deploy.py dist
# deploy-windows: deploy-windows:
# stage: deploy stage: deploy
# rules: dependencies:
# - if: '$GAJIM_NIGHTLY_BUILD' - build-windows
# - if: '$CI_COMMIT_TAG' rules:
# when: manual - if: '$GAJIM_NIGHTLY_BUILD'
# variables: - if: '$CI_COMMIT_TAG'
# DEPLOY_TYPE: "windows" variables:
# script: DEPLOY_TYPE: "windows"
# - python3 .ci/deploy.py build script:
- python3 .ci/deploy.py build
deploy-flatpak: deploy-flatpak:
image: git-deploy:latest image: git-deploy:latest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment