Skip to content

Generate Checksums and Upload as Artifact #1

Generate Checksums and Upload as Artifact

Generate Checksums and Upload as Artifact #1

Workflow file for this run

name: Generate Individual File Checksums
on:
push:
branches:
- main
paths:
- 'files/**'
- '!.github/**'
workflow_dispatch:
jobs:
generate-checksums:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate Individual Checksums
id: generate_checksums
run: |
TARGET_DIR="files"
cat << 'EOF' > generate_checksums.py
import os
import hashlib
def generate_sha256(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def create_individual_checksums(root_dir):
for dirpath, _, filenames in os.walk(root_dir):
for filename in filenames:
if filename.endswith('.sha256') or '.git' in dirpath:
continue
file_path = os.path.join(dirpath, filename)
digest = generate_sha256(file_path)
checksum_file = file_path + '.sha256'
with open(checksum_file, "w", encoding="utf-8") as f:
f.write(f"{digest} *{filename}\n")
print(f"Created: {checksum_file}")
if __name__ == "__main__":
create_individual_checksums("files")
EOF
python generate_checksums.py
- name: Commit and push if changed
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "ci: Update individual file checksums"
file_pattern: files/**/*.sha256
commit_user_name: "GitHub Actions Bot"
commit_user_email: "github-actions[bot]@users.noreply.github.com"