Skip to content

Mirror SPEDAS bleeding_edge #31

Mirror SPEDAS bleeding_edge

Mirror SPEDAS bleeding_edge #31

name: Mirror SPEDAS bleeding_edge
on:
schedule:
# Runs every Monday at 02:17 America/Los_Angeles (09:17 UTC). Adjust as desired.
- cron: "00 12 * * 1"
workflow_dispatch:
inputs:
url:
description: "Override bleeding_edge.zip URL (optional)"
required: false
type: string
# Let this workflow push commits
permissions:
contents: write
concurrency:
group: mirror-bleeding-edge
cancel-in-progress: false
env:
# Change if your default branch is not 'main'
TARGET_BRANCH: master
# Prefer a manual 'url' input; otherwise use repo variable BLEEDING_URL
BLEEDING_URL: ${{ github.event.inputs.url || vars.BLEEDING_URL }}
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Check required config
shell: bash
run: |
set -euo pipefail
if [[ -z "${BLEEDING_URL:-}" ]]; then
echo "ERROR: BLEEDING_URL not set. Define it as a repo variable or pass via workflow_dispatch input."
exit 1
fi
echo "BLEEDING_URL=${BLEEDING_URL}"
- name: Checkout repository
uses: actions/checkout@v4
with:
# Ensure we're on the branch we want to update
ref: ${{ env.TARGET_BRANCH }}
fetch-depth: 0
- name: Sync bleeding_edge.zip into repo and push
shell: bash
run: |
set -euo pipefail
# Create a temp workspace
WORK="$(mktemp -d)"
echo "Working dir: $WORK"
echo "Downloading $BLEEDING_URL ..."
curl -fL "$BLEEDING_URL" -o "$WORK/bleeding_edge.zip"
echo "Unzipping ..."
unzip -q "$WORK/bleeding_edge.zip" -d "$WORK/extracted"
# If the zip contains a single top-level folder, use its contents;
# otherwise use the extraction root.
shopt -s dotglob nullglob
entries=("$WORK/extracted"/*)
if [[ ${#entries[@]} -eq 1 && -d "${entries[0]}" ]]; then
SRC="${entries[0]}"
else
SRC="$WORK/extracted"
fi
echo "Source to mirror: $SRC"
# Mirror contents into repo root while preserving repo infrastructure.
# Tweak the --exclude list if you want to keep additional files.
echo "Rsync to repo root ..."
rsync -a --delete \
--exclude ".git/" \
--exclude ".github/" \
--exclude "/README.md" \
--exclude "/LICENSE.txt" \
--exclude ".gitattributes" \
--exclude ".gitignore" \
"$SRC"/ ./ || rc=$?
if [[ ${rc:-0} -ne 0 && ${rc} -ne 24 ]]; then
echo "rsync failed with code $rc"
exit $rc
fi
# Make Git deterministic on the runner
git config core.autocrlf false
git config core.eol lf
echo "Git status after rsync (pre-normalization, filtering out generated html docs):"
git status --porcelain | grep -v \.html || true
# Stage everything (adds/deletes), then normalize staged content per .gitattributes
git add -A
git add --renormalize .
# If nothing is staged after normalization, exit successfully
if git diff --cached --quiet --exit-code; then
echo "No changes after normalization; exiting successfully."
exit 0
fi
# Commit and push (will not run if nothing was staged)
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
SHA="$(sha256sum "$WORK/bleeding_edge.zip" | awk '{print $1}')"
MSG="Mirror SPEDAS bleeding_edge.zip (${SHA:0:12}) on $(date -u +'%Y-%m-%d %H:%M:%SZ')"
git commit -m "$MSG" -m "Source: $BLEEDING_URL"
git push origin "${TARGET_BRANCH}"