Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding svn validations basic flow #1

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
10d2269
adding svn validations basic flow
gopidesupavan Dec 1, 2024
f77a114
update names
gopidesupavan Dec 1, 2024
164a1d1
remove echo
gopidesupavan Dec 1, 2024
ca41ee7
update tests
gopidesupavan Dec 1, 2024
add8003
adding signature check
gopidesupavan Dec 1, 2024
9c8703a
fix workspace name
gopidesupavan Dec 1, 2024
bb946f5
adding subsection actions
gopidesupavan Dec 7, 2024
0779890
add unit tests for svn check
gopidesupavan Dec 7, 2024
94b2215
add unit tests to check-sum
gopidesupavan Dec 7, 2024
7eea894
add pypi publish and tests
gopidesupavan Dec 8, 2024
bf17e47
update variables
gopidesupavan Dec 8, 2024
9db2dc5
update paths
gopidesupavan Dec 8, 2024
c43752f
update repo path
gopidesupavan Dec 8, 2024
b9d3465
add initial readme file
gopidesupavan Dec 8, 2024
cce1d2f
add tests to signature check
gopidesupavan Dec 9, 2024
d180e37
add python-gnupg module to tests
gopidesupavan Dec 9, 2024
45e96b9
add requests module to tests
gopidesupavan Dec 9, 2024
03e48d6
use pytest-unordered
gopidesupavan Dec 9, 2024
8025fa5
use pytest-unordered
gopidesupavan Dec 9, 2024
6e1ec93
log updates
gopidesupavan Dec 9, 2024
481a1b6
adding doc string and fixing lints
gopidesupavan Dec 9, 2024
1edb0d4
remove fromjson for non json outputs
gopidesupavan Dec 10, 2024
6883637
update sample workflow usage as per best practice suggestion
gopidesupavan Dec 10, 2024
0259bcf
update sample workflow usage as per best practice suggestion
gopidesupavan Dec 10, 2024
5af7723
rename action
gopidesupavan Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding subsection actions
  • Loading branch information
gopidesupavan committed Dec 7, 2024
commit bb946f58d53458811376b7f05d07a4376ec3cfef
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: "Run tests"
run: |
python3 -m pip install pytest
pytest ./tests
pytest
69 changes: 69 additions & 0 deletions .github/workflows/test-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: GH pypi publish
description: 'Publish to PyPI'

on:
workflow_dispatch:
inputs:
publish-config:
description: 'Path to the publish config file'
required: true
default: 'publish-config.yml'
temp-dir:
description: 'Temporary directory to checkout svn repo'
required: false
default: 'temp-svn-repo'
mode:
description: 'Mode to run the action'
required: false
default: 'verify'

jobs:
gh-action-pypi-publish:
runs-on: ubuntu-latest
environment: test
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: "Config parser"
id: config-parser
uses: ./read-config
with:
publish-config: ${{ inputs.publish-config }}

- name: "Checkout svn ${{ fromJSON(steps.config-parser.outputs.publisher-url) }}"
id: "svn-checkout"
uses: ./init
with:
temp-dir: ${{ inputs.temp-dir }}
repo-url: ${{ fromJSON(steps.config-parser.outputs.publisher-url) }}
repo-path: ${{ fromJSON(steps.config-parser.outputs.publisher-path) }}

- name: "Svn check"
id: "svn-check"
uses: ./svn
with:
svn-config: ${{ steps.config-parser.outputs.checks-svn }}
repo-url: ${{ fromJSON(steps.config-parser.outputs.publisher-url) }}
repo-path: ${{ fromJSON(steps.config-parser.outputs.publisher-path) }}

- name: "Checksum check"
id: "checksum-check"
uses: ./checksum
with:
checksum-config: ${{ steps.config-parser.outputs.checks-checksum }}
repo-url: ${{ fromJSON(steps.config-parser.outputs.publisher-url) }}
repo-path: ${{ fromJSON(steps.config-parser.outputs.publisher-path) }}

- name: "Signature check"
id: "signature-check"
uses: ./signature
with:
signature-config: ${{ steps.config-parser.outputs.checks-signature }}
repo-url: ${{ fromJSON(steps.config-parser.outputs.publisher-url) }}
repo-path: ${{ fromJSON(steps.config-parser.outputs.publisher-path) }}
71 changes: 0 additions & 71 deletions README.md

This file was deleted.

93 changes: 0 additions & 93 deletions action.yml

This file was deleted.

File renamed without changes.
35 changes: 35 additions & 0 deletions checksum/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Checksum Validator'
description: 'Validate checksum of packages'
inputs:
checksum-config:
description: 'Json config for checksum'
required: true
temp-dir:
description: 'Checkout directory of svn repo'
required: false
default: 'temp-svn-repo'
repo-path:
description: 'Path to the svn repo ex: airflow/providers/'
required: true
repo-url:
description: 'URL of the svn repo ex: https://dist.apache.org/repos/dist/release/airflow/'
required: true


runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: "Check sum validation"
shell: bash
id: check-sum
env:
CHECK_SUM_CONFIG: ${{ inputs.checksum-config }}
run: |
python3 -m pip install uv
uv run $GITHUB_ACTION_PATH/checksum_check.py
working-directory: "./${{ inputs.temp-dir }}/${{ inputs.repo-path }}"
71 changes: 71 additions & 0 deletions checksum/checksum_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "rich",
# ]
# ///
import hashlib
import json
import os
from rich.console import Console

console = Console(width=400, color_system="standard")
svn_files = os.listdir()

invalid_checksums = []


def validate_checksum(check_sum_files: list[dict[str, str]], algorithm: str):
for file_dict in check_sum_files:
sha_file, check_file = file_dict.values()

with open(check_file, "rb") as chk:
digest = hashlib.file_digest(chk, algorithm)

actual_sha = digest.hexdigest()

with open(sha_file, "rb") as shf:
content = shf.read().decode("utf-8").strip()

expected_sha = content.split()[0]

if actual_sha != expected_sha:
invalid_checksums.append(
{
"file": sha_file,
"expected_sha": expected_sha,
"actual_sha": actual_sha,
}
)


def get_valid_files(algorithm, files) -> list[dict[str, str]]:
eligible_files = []
for file in files:
if file.endswith(algorithm):
eligible_files.append(
{
"sha_file": file,
"check_file": file.replace(algorithm, "").rstrip("."),
}
)
return eligible_files


if __name__ == "__main__":
check_sum_config = json.loads(os.environ.get("CHECK_SUM_CONFIG"))

for check in check_sum_config:
console.print(f"[blue]Checking {check.get('description')} checksum[/]")
valid_files = get_valid_files(check.get("algorithm"), svn_files)
validate_checksum(valid_files, check.get("algorithm"))

if invalid_checksums:
console.print("[red]Checksum validation failed[/]")
for invalid in invalid_checksums:
console.print(f"[red]File: {invalid.get('file')}[/]")
console.print(f"[red]Expected SHA: {invalid.get('expected_sha')}[/]")
console.print(f"[red]Actual SHA: {invalid.get('actual_sha')}[/]")
exit(1)

console.print("[blue]Checksum validation passed[/]")
17 changes: 17 additions & 0 deletions checksum/test_checksum_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from unittest.mock import patch, mock_open
from checksum.checksum_check import get_valid_files, validate_checksum, invalid_checksums

class TestChecksumCheck:

def test_get_valid_files(self):
files = [
'apache-airflow-2.10.3-source.tar.gz.sha512',
'apache_airflow-2.10.3-py3-none-any.whl.asc',
'apache_airflow-2.10.3-py3-none-any.whl.sha512',
'apache_airflow-2.10.3.tar.gz'
]
valida_files = get_valid_files('sha512', files)
assert valida_files == [{'sha_file': 'apache-airflow-2.10.3-source.tar.gz.sha512', 'check_file': 'apache-airflow-2.10.3-source.tar.gz'}, {'sha_file': 'apache_airflow-2.10.3-py3-none-any.whl.sha512', 'check_file': 'apache_airflow-2.10.3-py3-none-any.whl'}]



Loading
Loading