Skip to content

Generate Checksums and Upload as Artifact #9

Generate Checksums and Upload as Artifact

Generate Checksums and Upload as Artifact #9

Workflow file for this run

name: Generate and Manage File Checksums
on:
push:
branches:
- main
paths:
- 'files/**'
- '!.github/**'
- '!files/**/*.sha256'
workflow_dispatch:
jobs:
generate-checksums:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate/Update and Clean Checksums using Shell
run: |
echo "--- Starting Checksum Generation ---"
# 1. Generate/Update checksums for existing files
find files -type f -not -name "*.sha256" | while read -r file; do
echo "Processing file: $file"
# Calculate checksum
checksum=$(sha256sum "$file" | awk '{print $1}')
# Get just the filename, not the whole path
base_filename=$(basename "$file")
# Write to the .sha256 file in the desired format
echo "$checksum *$base_filename" > "$file.sha256"
echo "--> Created/Updated $file.sha256"
done
echo ""
echo "--- Starting Stale Checksum Cleanup ---"
# 2. Remove stale checksums (where the source file was deleted)
find files -type f -name "*.sha256" | while read -r checksum_file; do
# Construct the expected source file name by removing the .sha256 extension
source_file="${checksum_file%.sha256}"
# Check if the source file no longer exists
if [ ! -f "$source_file" ]; then
echo "Stale checksum found: $checksum_file. Source file '$source_file' is missing."
rm "$checksum_file"
echo "--> Removed $checksum_file"
fi
done
echo "--- Process Complete ---"
- name: Check Git status for changes
run: |
echo "--- Checking for uncommitted changes ---"
git status --porcelain
echo "----------------------------------------"
- name: Commit and push if changed
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "ci: Update individual file checksums"
# The pattern remains the same, as we are still committing .sha256 files
file_pattern: "files/**/*.sha256"
commit_user_name: "GitHub Actions Bot"
commit_user_email: "github-actions[bot]@users.noreply.github.com"