Merge pull request #1215 from zabbix/workflow_64

Workflow 64
This commit is contained in:
Alexey Pustovalov 2024-02-20 01:01:21 +09:00 committed by GitHub
commit b8f6c15e13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 64 additions and 20 deletions

48
.github/scripts/rhel_description.py vendored Normal file
View File

@ -0,0 +1,48 @@
import sys
import requests
import json
import markdown
import os
repository_description = None
if ("DESCRIPTION_FILE" not in os.environ or len(os.environ["DESCRIPTION_FILE"]) == 0):
print("Description file environment variable is not specified")
sys.exit(1)
if ("PYXIS_API_TOKEN" not in os.environ or len(os.environ["PYXIS_API_TOKEN"]) == 0):
print("API token environment variable is not specified")
sys.exit(1)
if ("API_URL" not in os.environ or len(os.environ["API_URL"]) == 0):
print("API URL environment variable is not specified")
sys.exit(1)
if ("PROJECT_ID" not in os.environ or len(os.environ["PROJECT_ID"]) == 0):
print("RedHat project ID environment variable is not specified")
sys.exit(1)
if (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.md')):
file = open(os.environ["DESCRIPTION_FILE"] + '.md', mode='r')
markdown_data = file.read()
file.close()
repository_description=markdown.markdown(markdown_data)
elif (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.html')):
file = open(os.environ["DESCRIPTION_FILE"] + '.html', mode='r')
repository_description = file.read()
file.close()
if (repository_description is None or len(repository_description) == 0):
print("No description")
sys.exit(1)
data = dict()
data['container'] = dict()
data['container']['repository_description'] = repository_description[:32768]
headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'}
result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"],
headers = headers,
data = json.dumps(data))
print("::group::Result")
print("Response code: " + result)
print("Last update date: " + json.loads(result.content)['last_update_date'])
print("::endgroup::")

View File

@ -3,9 +3,10 @@ name: Red Hat Catalog Description
on:
push:
branches:
- 'trunk'
- '[0-9]+.[0-9]+'
paths:
- 'Dockerfiles/*/*/README.html'
- 'Dockerfiles/*/*/README.md'
- '.github/workflows/rhel_registry_description.yml'
workflow_dispatch:
@ -70,6 +71,7 @@ jobs:
echo "secret_prefix=RHEL_${github_ref//.}"
echo "::endgroup::"
echo "zabbix_release=${github_ref//.}" >> $GITHUB_OUTPUT
echo "secret_prefix=RHEL_${github_ref//.}" >> $GITHUB_OUTPUT
- name: Check ${{ env.MATRIX_FILE }} file
@ -98,7 +100,7 @@ jobs:
- name: Variables formating
id: var_format
env:
MATRIX_BUILD: ${{ matrix.build }}
MATRIX_BUILD: ${{ matrix.component }}
run: |
MATRIX_BUILD=${MATRIX_BUILD^^}
MATRIX_BUILD=${MATRIX_BUILD//-/_}
@ -108,26 +110,20 @@ jobs:
echo "::endgroup::"
echo "matrix_build=${MATRIX_BUILD}" >> $GITHUB_OUTPUT
- name: Update Red Hat project description (zabbix-${{ matrix.component }})
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: install python packages
run: |
python -m pip install --upgrade pip
pip install markdown requests
- name: Update Red Hat project description (${{ matrix.component }}-${{ steps.branch_info.outputs.zabbix_release }})
env:
DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README.html', env.DOCKERFILES_DIRECTORY, matrix.build) }}
DESCRIPTION_FILE: ${{ format('{0}/{1}/rhel/README', env.DOCKERFILES_DIRECTORY, matrix.component) }}
PROJECT_ID: ${{ secrets[format('{0}_{1}_PROJECT', steps.branch_info.outputs.secret_prefix, steps.var_format.outputs.matrix_build)] }}
PYXIS_API_TOKEN: ${{ secrets.REDHAT_API_TOKEN }}
API_URL: ${{ env.API_URL }}
run: |
import requests
import json
import os
run: python ./.github/scripts/rhel_description.py
file = open(os.environ["DESCRIPTION_FILE"],mode='r')
repository_description = file.read()
file.close()
data = dict()
data['container'] = dict()
data['container']['repository_description'] = repository_description[:32768]
headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'}
result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data))
print(result)
print(json.loads(r.content)['last_update_date'])