|
name: Deploy to GitHub Pages |
|
|
|
on: |
|
push: |
|
branches: |
|
- main |
|
workflow_dispatch: |
|
|
|
permissions: |
|
contents: write |
|
pages: write |
|
id-token: write |
|
|
|
concurrency: |
|
group: "pages" |
|
cancel-in-progress: false |
|
|
|
jobs: |
|
build-and-deploy: |
|
runs-on: ubuntu-latest |
|
environment: |
|
name: github-pages |
|
url: ${{ steps.deployment.outputs.page_url }} |
|
steps: |
|
- name: Checkout |
|
uses: actions/checkout@v4 |
|
with: |
|
fetch-depth: 0 |
|
|
|
- name: Build site and update README |
|
run: | |
|
set -e |
|
|
|
DOMAIN="your.domain.name" |
|
OUTPUT_DIR="_site" |
|
|
|
mkdir -p "$OUTPUT_DIR" |
|
|
|
# Create CNAME file for custom domain |
|
echo "$DOMAIN" > "$OUTPUT_DIR/CNAME" |
|
|
|
# Create robots.txt that disallows all crawling |
|
cat > "$OUTPUT_DIR/robots.txt" << 'EOF' |
|
User-agent: * |
|
Disallow: / |
|
EOF |
|
sed -i 's/^ //' "$OUTPUT_DIR/robots.txt" |
|
|
|
# Create index.html that redirects to GitHub repo (with noindex) |
|
cat > "$OUTPUT_DIR/index.html" << 'EOF' |
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<meta name="robots" content="noindex, nofollow, noarchive, nosnippet, noimageindex"> |
|
<meta name="googlebot" content="noindex, nofollow, noarchive, nosnippet, noimageindex"> |
|
<script>location.href='https://github.com/your-github-username/your-github-fileshare-repo'</script> |
|
</head> |
|
<body></body> |
|
</html> |
|
EOF |
|
sed -i 's/^ //' "$OUTPUT_DIR/index.html" |
|
|
|
# Process each file in filez/ |
|
if [ -d "filez" ] && [ "$(ls -A filez 2>/dev/null)" ]; then |
|
find filez -type f | while read -r filepath; do |
|
# Get relative path within filez/ |
|
relpath="${filepath#filez/}" |
|
|
|
# Get the last commit hash and datetime that modified this file |
|
commit_hash=$(git log -1 --format="%H" -- "$filepath" | cut -c1-12) |
|
commit_datetime=$(git log -1 --date=format:'%Y-%m-%d %H:%M' --format="%cd" -- "$filepath") |
|
commit_timestamp=$(git log -1 --format="%ct" -- "$filepath") |
|
|
|
# Compute SHA256 checksum (first 12 chars) |
|
checksum=$(sha256sum "$filepath" | cut -c1-12) |
|
|
|
# Create prefix |
|
prefix="${commit_hash}-${checksum}" |
|
|
|
# Create output directory structure |
|
output_path="$OUTPUT_DIR/$prefix/$relpath" |
|
mkdir -p "$(dirname "$output_path")" |
|
|
|
# Copy file |
|
cp "$filepath" "$output_path" |
|
|
|
# Store entry for README: timestamp|datetime|name|url (timestamp for sorting) |
|
echo "${commit_timestamp}|${commit_datetime}|${relpath}|https://$DOMAIN/$prefix/$relpath" >> /tmp/readme_entries.txt |
|
|
|
echo "Processed: $relpath -> $prefix/$relpath" |
|
done |
|
fi |
|
|
|
# Generate README.md as table sorted by datetime (latest first) |
|
echo "| π | π |" > README.md |
|
echo "|--|--|" >> README.md |
|
if [ -f /tmp/readme_entries.txt ]; then |
|
sort -t'|' -k1 -nr /tmp/readme_entries.txt | while IFS='|' read -r timestamp datetime name url; do |
|
echo "| [$name]($url) | $datetime |" >> README.md |
|
done |
|
fi |
|
|
|
- name: Commit README changes |
|
run: | |
|
git config user.name "github-actions[bot]" |
|
git config user.email "github-actions[bot]@users.noreply.github.com" |
|
git add README.md |
|
if git diff --staged --quiet; then |
|
echo "No README changes to commit" |
|
else |
|
git commit -m "Update README with file listings" |
|
git push |
|
fi |
|
|
|
- name: Setup Pages |
|
uses: actions/configure-pages@v5 |
|
|
|
- name: Upload artifact |
|
uses: actions/upload-pages-artifact@v3 |
|
with: |
|
path: '_site' |
|
|
|
- name: Deploy to GitHub Pages |
|
id: deployment |
|
uses: actions/deploy-pages@v4 |