From 1172c3bd725b67bde3aeafab9d9fa08f5abb76ca Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 5 Dec 2023 11:43:25 +0100 Subject: [PATCH 1/2] Replace release label validator script --- .github/workflows/create-release.yaml | 14 +++++- scripts/python/release_label_validator.py | 52 +++++++++++++++++++++++ scripts/python/requirements.txt | 3 +- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100755 scripts/python/release_label_validator.py diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index 0b8dc8390..2077c3fbc 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -59,10 +59,20 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: "./scripts/check_artifacts_existence.sh ${{ inputs.name }} ${{ inputs.name }}" - - name: Validate Labels + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + + - name: Install requirements + run: pip install -r scripts/python/requirements.txt + + - name: Validate labels env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./scripts/label_validator.sh "RELEASE" + REPOSITORY: ${{ env.KYMA_BTP_MANAGER_REPO }} + run: python3 scripts/python/release_label_validator.py bump-sec-scanners-config: name: Bump sec-scanners-config diff --git a/scripts/python/release_label_validator.py b/scripts/python/release_label_validator.py new file mode 100755 index 000000000..f0a7bf3bd --- /dev/null +++ b/scripts/python/release_label_validator.py @@ -0,0 +1,52 @@ +import requests +import os +import yaml +import sys + +with open('.github/release.yml', 'r') as file: + try: + release_yaml = yaml.safe_load(file) + label_pool = [] + for category in release_yaml['changelog']['categories']: + label_pool.extend(category['labels']) + except yaml.YAMLError as exc: + print(exc) + +print(f"One of these labels is required on PR: {label_pool}") +token = os.getenv('GITHUB_TOKEN') +repo = os.getenv('REPOSITORY') + +response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest', headers={'Authorization': f'token {token}'}) +response.raise_for_status() +latest_release = response.json() +latest_release_date = latest_release['created_at'] + +response = requests.get(f'https://api.github.com/repos/{repo}/pulls?state=closed&sort=updated&direction=desc', headers={'Authorization': f'token {token}'}) +response.raise_for_status() +all_closed_prs = response.json() + +prs_since_last_release = [ + pr for pr in all_closed_prs + if pr['merged_at'] is not None and pr['merged_at'] > latest_release_date +] + +valid_prs = [] +invalid_prs = [] +for pr in prs_since_last_release: + labels = [label['name'] for label in pr['labels']] + common_labels = set(labels).intersection(label_pool) + if len(common_labels) != 1: + invalid_prs.append(pr['html_url']) + else: + valid_prs.append(pr['html_url']) + +print("\nThese PRs have exactly one required label:") +print('\n'.join([f"PR: {pr}" for pr in valid_prs])) + + +if invalid_prs: + print("\nThese PRs don't have exactly one required label:") + print('\n'.join([f"PR: {pr}" for pr in invalid_prs])) + sys.exit(1) + +print("\nAll PRs have exactly one required label") diff --git a/scripts/python/requirements.txt b/scripts/python/requirements.txt index bb2737880..1b1f52e89 100644 --- a/scripts/python/requirements.txt +++ b/scripts/python/requirements.txt @@ -1,2 +1,3 @@ pyyaml -jwt \ No newline at end of file +jwt +requests \ No newline at end of file From 9613528d32cfee78455d3201d23adc368908ec18 Mon Sep 17 00:00:00 2001 From: Marek Michali Date: Tue, 5 Dec 2023 11:54:46 +0100 Subject: [PATCH 2/2] Remove v from upgrade test --- scripts/testing/run_e2e_module_upgrade_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/testing/run_e2e_module_upgrade_tests.sh b/scripts/testing/run_e2e_module_upgrade_tests.sh index 7f0ba6f5d..2c30e52a0 100755 --- a/scripts/testing/run_e2e_module_upgrade_tests.sh +++ b/scripts/testing/run_e2e_module_upgrade_tests.sh @@ -34,7 +34,7 @@ elif [[ $# -eq 2 ]]; then GITHUB_URL=https://api.github.com/repos/${REPOSITORY} LATEST_RELEASE=$(curl -sS "${GITHUB_URL}/releases/latest" | jq -r '.tag_name') NEW_MODULE_IMAGE_NAME=$1 - OLD_MODULE_IMAGE_NAME=${NEW_MODULE_IMAGE_NAME/:*/:v$LATEST_RELEASE} + OLD_MODULE_IMAGE_NAME=${NEW_MODULE_IMAGE_NAME/:*/:$LATEST_RELEASE} CI=${2-manual} # if called from any workflow "ci" is expected here else echo "wrong number of arguments" && exit 1