Files
endoflife-date-release-data/src/common/gha.py
Marc Wrobel a0ba2d687e Improve scripts execution orchestration (#299)
Until now products could declare multiple auto-update methods, but they all had to be of the same kind.
For example if you used the git auto-update method, you could not use an additional github_releases or custom auto-update method.
This is an issue as it prevents us to extend the auto-update process, for example by having a product using the 'git' auto-update method to retrieve all the versions, and a custom script to retrieve support and EOL dates.

This improve the scripts execution orchestration to be able to support auto configurations using a mix of methods, meaning:

- multiple kind of methods, such as git and github_release,
- or multiple custom methods.

A side-effect of those changes is that now a failure in a generic script does not cancel the update of subsequent products.

Another side-effect, unwanted this time, is that now custom scripts managing multiple products, such as apple.py, are now executed multiple times instead of once.
2024-02-11 15:28:26 +01:00

59 lines
1.8 KiB
Python

import logging
import os
from base64 import b64encode
"""See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions."""
class GitHubOutput:
def __init__(self, name: str) -> None:
self.name = name
self.value = ""
def __enter__(self) -> None:
return None
def println(self, value: str) -> None:
self.value += value + "\n"
def __exit__(self, exc_type: any, exc_value: any, traceback: any) -> None:
var_exists = "GITHUB_OUTPUT" in os.environ
delimiter = b64encode(os.urandom(16)).decode()
value = f"{delimiter}\n{self.value}\n{delimiter}"
command = f"{self.name}<<{value}"
logging.info(f"GITHUB_OUTPUT (exists={var_exists}):\n{command}")
if var_exists:
with open(os.environ["GITHUB_OUTPUT"], 'a') as github_output_var: # NOQA: PTH123
print(command, file=github_output_var)
class GitHubStepSummary:
def __init__(self) -> None:
self.value = ""
def __enter__(self) -> "GitHubStepSummary":
return self
def println(self, value: str) -> None:
self.value += value + "\n"
def __exit__(self, exc_type: any, exc_value: any, traceback: any) -> None:
var_exists = "GITHUB_STEP_SUMMARY" in os.environ
logging.info(f"GITHUB_STEP_SUMMARY (exists={var_exists}):\n{self.value}")
if var_exists:
with open(os.environ["GITHUB_STEP_SUMMARY"], 'a') as github_step_summary: # NOQA: PTH123
print(self.value, file=github_step_summary)
class GitHubGroup:
def __init__(self, name: str) -> None:
self.name = name
def __enter__(self) -> None:
logging.info(f"::group::{self.name}")
def __exit__(self, exc_type: any, exc_value: any, traceback: any) -> None:
logging.info("::endgroup::")