Skip to content

Commit

Permalink
Merge branch 'eclipse-sw360:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fgreinacher authored May 7, 2024
2 parents 4afe6b8 + fe044d0 commit 0c73096
Show file tree
Hide file tree
Showing 499 changed files with 58,143 additions and 2,304 deletions.
28 changes: 8 additions & 20 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ name: Bug report
about: Create a report to help us improve
labels: bug
---
[//]: # (Copyright Siemens AG, 2021. Part of the SW360 Portal Project)
[//]: # (This program and the accompanying materials are made)
[//]: # (available under the terms of the Eclipse Public License 2.0)
[//]: # (which is available at https://www.eclipse.org/legal/epl-2.0/)
[//]: # (SPDX-License-Identifier: EPL-2.0)

<!-- Before filling this issue, please read the wiki (https://github.com/eclipse/sw360/wiki)
and search if the bug do not already exists in the issues (https://github.com//eclipse/sw360/issues). -->
<!-- Before filling this issue, please read the wiki (https://eclipse.org/sw360)
and search if the bug do not already exists in the issues (https://github.com//eclipse-sw360/sw360/issues). -->

### Description

Expand All @@ -20,23 +15,16 @@ Please describe your issue in few words here.

Describe the bug and list the steps you used when the issue occurred.

#### Screenshots
#### Screenshots ( if applicable )

If applicable, add screenshots to help explain your problem.
Add screenshots to help explain your problem.

### Versions

* Last commit id on master:
* Operating System (lsb_release -a):

### Logs

Any logs (if any) generated in
* Docker version OR
* Last commit id on main

#### SW360 logs

Logs generated under /var/log/sw360/sw360.log

#### Tomcat logs

Logs generated under /var/log/tomcat/error.log
* With docker through `docker logs sw360`
* From bare metal / vm install system under /var/log/sw360/sw360.log and /var/log/tomcat/error.log
13 changes: 4 additions & 9 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ name: Feature request
about: Request a new feature in sw360
labels: enhancement
---
[//]: # (Copyright Siemens AG, 2021. Part of the SW360 Portal Project)
[//]: # (This program and the accompanying materials are made)
[//]: # (available under the terms of the Eclipse Public License 2.0)
[//]: # (which is available at https://www.eclipse.org/legal/epl-2.0/)
[//]: # (SPDX-License-Identifier: EPL-2.0)

<!-- Before filling this issue, please read the Wiki (https://github.com/sw360/wiki)
and search if the bug do not already exists in the issues (https://github.com/eclipse/sw360/issues). -->
<!-- Before filling this issue, please read the wiki (https://eclipse.org/sw360)
and search if the bug do not already exists in the issues (https://github.com//eclipse-sw360/sw360/issues). -->

### Description

Expand All @@ -20,6 +15,6 @@ Please describe your situation in few words here.

Describe the steps followed by you and your expected results after following the steps.

#### Screenshots
#### Screenshots ( if applicable )

If applicable, add screenshots to help explain your problem.
Add screenshots to help explain your problem.
50 changes: 50 additions & 0 deletions .github/actions/clean_up_package_registry/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright Helio Chissini de Castro, 2023
# SPDX-FileCopyrightText: 2024 Helio Chissini de Castro <[email protected]>
#
# SPDX-License-Identifier: EPL-2.0
# SPDX-License-Identifier: MIT

name: 'Delete old non-release packages from Github package registry'
description: 'Delete older packages set by a minimal level input'
author: 'The ORT Project Authors'

inputs:
registry:
description: 'Github container registry'
default: 'ghcr.io'
token:
description: 'Github token'
required: true
keep:
description: 'Number of non-release packages to keep'
required: false
default: '3'
packages:
description: 'Name of the packages to be cleaned up'
required: true
dry-run:
description: 'Execute a dry run operation to check the execution is correct'
default: 'false'

runs:
using: 'composite'

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'

- name: Execute the operation
id: check_image
shell: bash
env:
INPUT_REGISTRY: ${{ inputs.registry }}
INPUT_TOKEN: ${{ inputs.token }}
INPUT_KEEP: ${{ inputs.keep }}
INPUT_PACKAGES: ${{ inputs.packages }}
INPUT_DRY_RUN: ${{ inputs.dry-run}}
run: |
pip install -r ./.github/actions/clean_up_package_registry/requirements.txt
python ./.github/actions/clean_up_package_registry/clean_up_package_registry.py
137 changes: 137 additions & 0 deletions .github/actions/clean_up_package_registry/clean_up_package_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Copyright Helio Chissini de Castro, 2023
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0


import os
import sys
from typing import Any
from urllib.parse import parse_qs, urlparse

import requests
from rich import print

""" Use current Github API to list packages
in registry and remove all but last 3 or custom
set number of packages.
Reference: https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#about-github-packages
"""

dry_run: bool = True if os.getenv("INPUT_DRY_RUN") == "true" else False
keep = int(os.getenv("INPUT_KEEP")) if os.getenv("INPUT_KEEP") else 5
org = os.getenv("GITHUB_REPOSITORY_OWNER")
packages = os.getenv("INPUT_PACKAGES").split("\n")
token = os.getenv("INPUT_TOKEN")

headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
}

# Assembly organization packages url string
pkg_url: str = f"https://api.github.com/orgs/{org}/packages"


def get_last_page(headers: dict[str, Any]) -> int:
if "link" not in headers:
return 1

links = headers["link"].split(", ")

last_page = None
for link in links:
if 'rel="last"' in link:
last_page = link
break

if last_page:
parsed_url = urlparse(
last_page[last_page.index("<") + 1 : last_page.index(">")]
)
return int(parse_qs(parsed_url.query)["page"][0])

return 1


def delete_packages():
for package in packages:
print(f":package: {package}")

# Start page is 1 as stated by documentation
url = f"{pkg_url}/container/{package.replace('/', '%2F')}/versions?page=1&per_page=50"

# Get the header
response = requests.head(url, headers=headers)
pages: int | None = get_last_page(response.headers)

for page in range(pages, 0, -1):
print(f"Page: {page}")
url = f"{pkg_url}/container/{package.replace('/', '%2F')}/versions?page={page}&per_page=50"
response = requests.get(url, headers=headers)
if response.status_code == 404:
print(f":cross_mark: Not found - {url}")
continue
elif response.status_code == 401:
print(f":cross_mark: Requires authentication - {url}")
sys.exit(1)
elif response.status_code == 403:
print(f":cross_mark: Forbidden - {url}")
sys.exit(1)

# Sort all images on id.
images = sorted(response.json(), key=lambda x: x["id"], reverse=True)

# Slice and remove all
if len(images) > keep:
for image in images if page != 1 else images[keep + 1 :]:
url = f"{pkg_url}/container/{package.replace('/', '%2F')}/versions/{image['id']}"

# Never remove latest or non snapshot tagged images
if restrict_delete_tags(image["metadata"]["container"]["tags"]):
print(
f":package: Skip tagged {package} id {image['id']} tags {image['metadata']['container']['tags']}"
)
continue

if not dry_run:
response = requests.delete(url, headers=headers)
if response.status_code == 404:
print(f":cross_mark: Failed to delete package {package} version id {image['id']}.")
continue
elif response.status_code == 401:
print(f":cross_mark: Requires authentication - {url}")
sys.exit(1)
elif response.status_code == 403:
print(f":cross_mark: Forbidden - {url}")
sys.exit(1)

tags = image["metadata"]["container"]["tags"]
if tags:
print(
f":white_heavy_check_mark: Deleted tagged package {package} version id {image['id']}"
f"with tags {tags}."
)
else:
print(
f":white_heavy_check_mark: Deleted untagged package {package} version id {image['id']}"
)


def restrict_delete_tags(tags: list) -> bool:
if not tags:
return False
for tag in tags:
if tag == "latest":
return True
elif "nightly" in tag:
return True
return False


if __name__ == "__main__":
delete_packages()
9 changes: 9 additions & 0 deletions .github/actions/clean_up_package_registry/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
certifi==2023.7.22
charset-normalizer==3.3.2
idna==3.7
markdown-it-py==3.0.0
mdurl==0.1.2
Pygments==2.16.1
requests==2.31.0
rich==13.6.0
urllib3==2.1.0
43 changes: 26 additions & 17 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
[//]: # (Copyright Bosch.IO GmbH 2020)
[//]: # (This program and the accompanying materials are made)
[//]: # (available under the terms of the Eclipse Public License 2.0)
[//]: # (which is available at https://www.eclipse.org/legal/epl-2.0/)
[//]: # (SPDX-License-Identifier: EPL-2.0)

> Please provide a summary of your changes here.
> * Which issue is this pull request belonging to and how is it solving it? (*Refer to issue here*)
> * Did you add or update any new dependencies that are required for your change?
---
name: Bug report
about: Create a report to help us improve
labels: bug
---

Issue:
<!-- Before filling this issue, please read the wiki (https://eclipse.org/sw360)
and search if the bug do not already exists in the issues (https://github.com//eclipse-sw360/sw360/issues). -->

### Suggest Reviewer
> You can suggest reviewers here with an @mention.
### Description

### How To Test?
> How should these changes be tested by the reviewer?
> Have you implemented any additional tests?
Please describe your issue in few words here.

### Checklist
Must:
- [ ] All related issues are referenced in commit messages and in PR
#### How to reproduce

Describe the bug and list the steps you used when the issue occurred.

#### Screenshots ( if applicable )

Add screenshots to help explain your problem.

### Versions

* Docker version OR
* Last commit id on main

#### SW360 logs

* With docker through `docker logs sw360`
* From bare metal / vm install system under /var/log/sw360/sw360.log and /var/log/tomcat/error.log
7 changes: 7 additions & 0 deletions .github/testForLicenseHeaders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ done <<< "$(git ls-files \
| grep -v .pre-commit-config.yaml \
| grep -v 'id_rsa' \
| grep -v '.versions' \
| grep -v '.github/actions/docker_control/action.yml' \
| grep -v '.github/actions/docker_control/check_image.py' \
| grep -v '.github/ISSUE_TEMPLATE/*' \
| grep -v '.github/pull_request_template.md' \
| grep -v 'sw360.code-workspace' \
| grep -v 'default_secrets' \
| grep -v 'requirements.txt' \
| grep -Ev 'third-party/couchdb-lucene/*' \
| grep -Ev '*/asciidoc/*')"

if [ "$failure" = true ]; then
Expand Down
Loading

0 comments on commit 0c73096

Please sign in to comment.