trying prebuild scripts

This commit is contained in:
Trance-0
2025-11-19 16:08:36 -06:00
parent aca1e0698b
commit b9f761d256
2 changed files with 86 additions and 5 deletions

View File

@@ -0,0 +1,73 @@
name: Sync from Gitea (distribute→distribute, keep workflow)
on:
schedule:
# 2 times per day (UTC): 7:00, 11:00
- cron: '0 7,11 * * *'
workflow_dispatch: {}
permissions:
contents: write # allow pushing with GITHUB_TOKEN
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Check out GitHub repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch from Gitea
env:
GITEA_URL: ${{ secrets.GITEA_URL }}
GITEA_USER: ${{ secrets.GITEA_USERNAME }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
# Build authenticated Gitea URL: https://USER:TOKEN@...
AUTH_URL="${GITEA_URL/https:\/\//https:\/\/$GITEA_USER:$GITEA_TOKEN@}"
git remote add gitea "$AUTH_URL"
git fetch gitea --prune
- name: Update distribute from gitea/distribute, keep workflow, and force-push
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
# Configure identity for commits made by this workflow
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Authenticated push URL for GitHub
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GH_REPO}.git"
WF_PATH=".github/workflows/sync-from-gitea.yml"
# If the workflow exists in the current checkout, save a copy
if [ -f "$WF_PATH" ]; then
mkdir -p /tmp/gh-workflows
cp "$WF_PATH" /tmp/gh-workflows/
fi
# Reset local 'distribute' to exactly match gitea/distribute
if git show-ref --verify --quiet refs/remotes/gitea/distribute; then
git checkout -B distribute gitea/distribute
else
echo "No gitea/distribute found, nothing to sync."
exit 0
fi
# Restore the workflow into the new HEAD and commit if needed
if [ -f "/tmp/gh-workflows/sync-from-gitea.yml" ]; then
mkdir -p .github/workflows
cp /tmp/gh-workflows/sync-from-gitea.yml "$WF_PATH"
git add "$WF_PATH"
if ! git diff --cached --quiet; then
git commit -m "Inject GitHub sync workflow"
fi
fi
# Force-push distribute so GitHub mirrors Gitea + workflow
git push origin distribute --force

View File

@@ -1,11 +1,19 @@
# This is pre-build script that cleans up resources and compiles for selected pages, then finally you may combine those subdirectories into one via nginx. # This is pre-build script that cleans up resources and compiles for selected pages, then finally you may combine those subdirectories into one via nginx.
echo 'Currently compiling pages: $KEEP_PAGES' export KEEP_PAGES="Math3200"
echo "Currently compiling pages: ${KEEP_PAGES}"
# Rewrite base _meta.js and next.config.js for export pages # Rewrite base _meta.js and next.config.js for export pages
echo 'Rewrite base _meta.js and keeping $KEEP_PAGES' echo "Rewrite base _meta.js and keeping ${KEEP_PAGES}"
sed 's/(\w+\d+.):(\s*{\n.+\n.+)\n.+\n.+\n.+(\n.+},)/$1_link:$2\n href:'/$1'$3/g' -i ../content/_meta.js $first =~ s@(\w+\d+.*)\s*:\s*(\{\s+.+\s+.+)\s+.+\s+.+\s+.+\s+(\},)@$1_link:$2\n href: \x27/$1\x27\n $3@gmx
perl -0777 -pe first -i ./content/_meta.js
$second =~ s@(\$KEEP_PAGES\{_link})\s*:\s*(\{\s+.+\s+.+)\s+.+\s+.+\s+.+\s+(\},)@${KEEP_PAGES}:$2\n theme:{\n timestamp: true,\n }\n $3@gmx
# Write saved pages back
perl -0777 -pe '' -i ./content/_meta.js
# cat ./content/_meta.js
echo 'First step replaced file:'
cat ../content/_meta.js