|
65 | 65 | - name: Update and download scripts |
66 | 66 | run: | |
67 | 67 | sudo apt-get update |
68 | | - sudo apt-get install wget -y |
| 68 | + sudo apt-get install -y wget gh |
69 | 69 | mkdir scripts |
70 | 70 | cd scripts |
71 | 71 | wget -O get_and_save_refs.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/get_and_save_refs.py |
@@ -123,57 +123,35 @@ jobs: |
123 | 123 | git pull |
124 | 124 | MDBOOK_BOOK__LANGUAGE=$BRANCH mdbook build || (echo "Error logs" && cat hacktricks-preprocessor-error.log && echo "" && echo "" && echo "Debug logs" && (cat hacktricks-preprocessor.log | tail -n 20) && exit 1) |
125 | 125 | |
126 | | - - name: Update searchindex.js in repo (purge history, keep current on HEAD) |
| 126 | + - name: Publish search index release asset |
127 | 127 | shell: bash |
| 128 | + env: |
| 129 | + PAT_TOKEN: ${{ secrets.PAT_TOKEN }} |
128 | 130 | run: | |
129 | 131 | set -euo pipefail |
130 | 132 |
|
131 | | - # Be explicit about workspace trust (avoids "dubious ownership") |
132 | | - git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 133 | + ASSET="book/searchindex.js" |
| 134 | + TAG="searchindex-${BRANCH}" |
| 135 | + TITLE="Search Index (${BRANCH})" |
133 | 136 |
|
134 | | - git checkout "$BRANCH" |
135 | | - git fetch origin "$BRANCH" --quiet |
136 | | - git pull --ff-only |
137 | | -
|
138 | | - # Choose the file to keep at HEAD: |
139 | | - # 1) Prefer freshly built version from book/ |
140 | | - # 2) Fallback to the file currently at HEAD (if it exists) |
141 | | - HAS_FILE=0 |
142 | | - if [ -f "book/searchindex.js" ]; then |
143 | | - cp "book/searchindex.js" /tmp/sidx.js |
144 | | - HAS_FILE=1 |
145 | | - elif git cat-file -e "HEAD:searchindex.js" 2>/dev/null; then |
146 | | - git show "HEAD:searchindex.js" > /tmp/sidx.js |
147 | | - HAS_FILE=1 |
| 137 | + if [ ! -f "$ASSET" ]; then |
| 138 | + echo "Expected $ASSET to exist after build" >&2 |
| 139 | + exit 1 |
148 | 140 | fi |
149 | 141 |
|
150 | | - # Skip if there's nothing to purge AND nothing to keep |
151 | | - if [ "$HAS_FILE" = "1" ] || git rev-list -n 1 "$BRANCH" -- "searchindex.js" >/dev/null 2>&1; then |
152 | | - # **Fail early if working tree is dirty** (prevents confusing filter results) |
153 | | - git diff --quiet || { echo "Working tree has uncommitted changes; aborting purge." >&2; exit 1; } |
154 | | -
|
155 | | - # Make sure git-filter-repo is callable via `git filter-repo` |
156 | | - python -m pip install --quiet --user git-filter-repo |
157 | | - export PATH="$HOME/.local/bin:$PATH" |
158 | | -
|
159 | | - # Rewrite ONLY this branch, dropping all historical blobs of searchindex.js |
160 | | - git filter-repo --force --path "searchindex.js" --invert-paths --refs "refs/heads/$BRANCH" |
161 | | -
|
162 | | - # Re-add the current version on top of rewritten history (keep it in HEAD) |
163 | | - if [ "$HAS_FILE" = "1" ]; then |
164 | | - mv /tmp/sidx.js "searchindex.js" |
165 | | - git add "searchindex.js" |
166 | | - git commit -m "Update searchindex (purged history; keep current)" |
167 | | - else |
168 | | - echo "No current searchindex.js to re-add after purge." |
169 | | - fi |
| 142 | + TOKEN="${PAT_TOKEN:-${GITHUB_TOKEN:-}}" |
| 143 | + if [ -z "$TOKEN" ]; then |
| 144 | + echo "No token available for GitHub CLI" >&2 |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | + export GH_TOKEN="$TOKEN" |
170 | 148 |
|
171 | | - # **Safer force push** (prevents clobbering unexpected remote updates) |
172 | | - git push --force-with-lease origin "$BRANCH" |
| 149 | + if ! gh release view "$TAG" >/dev/null 2>&1; then |
| 150 | + gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for $BRANCH" --repo "$GITHUB_REPOSITORY" |
173 | 151 | else |
174 | | - echo "Nothing to purge; skipping." |
| 152 | + gh release upload "$TAG" "$ASSET" --clobber --repo "$GITHUB_REPOSITORY" |
175 | 153 | fi |
176 | | - |
| 154 | +
|
177 | 155 | # Login in AWs |
178 | 156 | - name: Configure AWS credentials using OIDC |
179 | 157 | uses: aws-actions/configure-aws-credentials@v3 |
|
0 commit comments