Generate Checksums and Upload as Artifact #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate Checksums and Upload as Artifact | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'files/**' | |
| - '!.github/**' | |
| - '!files/**/*.sha256' | |
| workflow_dispatch: | |
| jobs: | |
| generate-and-upload: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Generate Checksum Files | |
| run: | | |
| echo "--- Starting Checksum Generation ---" | |
| # 1. یک پوشه تمیز برای نگهداری فایلهای خروجی میسازیم | |
| mkdir -p generated_checksums | |
| # 2. تمام فایلهای داخل پوشه 'files' را پیدا میکنیم | |
| find files -type f -not -name "*.sha256" | while read -r file; do | |
| echo "Processing file: $file" | |
| checksum=$(sha256sum "$file" | awk '{print $1}') | |
| base_filename=$(basename "$file") | |
| # 3. ساختار پوشه اصلی را در پوشه خروجی بازسازی میکنیم | |
| # برای مثال، اگر فایل در 'files/sub/a.txt' باشد، | |
| # مسیر نسبی 'sub' خواهد بود. | |
| relative_dir=$(dirname "${file#files/}") | |
| # اگر فایل در ریشه 'files' باشد، مسیر نسبی '.' میشود که مشکلی ندارد | |
| if [ "$relative_dir" != "." ]; then | |
| mkdir -p "generated_checksums/$relative_dir" | |
| output_path="generated_checksums/$relative_dir/$base_filename.sha256" | |
| else | |
| output_path="generated_checksums/$base_filename.sha256" | |
| fi | |
| # 4. فایل checksum را در پوشه خروجی مینویسیم | |
| echo "$checksum *$base_filename" > "$output_path" | |
| echo "--> Created: $output_path" | |
| done | |
| echo "--- Generation Complete ---" | |
| echo "--- Listing generated files for artifact ---" | |
| ls -R generated_checksums | |
| - name: Upload Checksum Files as Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| # نام فایل زیپی که دانلود خواهید کرد | |
| name: checksum-files | |
| # مسیری که فایلهای ساخته شده در آن قرار دارند | |
| path: generated_checksums/ | |
| # فایلها تا ۵ روز برای دانلود باقی میمانند | |
| retention-days: 5 |