First pass at auto-update shortlinks

- Swapped out to multi-repo checkout (changing paths)
- Check out byjp.fyi — expects GITHUB_PAT to be set as a secret
This commit is contained in:
JP Hastings-Spital 2024-07-16 21:24:50 +01:00
parent 49fedda65e
commit d49aad2485
2 changed files with 37 additions and 4 deletions

View file

@ -57,6 +57,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
path: ./www.byjp.me
submodules: recursive submodules: recursive
- name: Setup Pages - name: Setup Pages
id: pages id: pages
@ -69,19 +70,35 @@ jobs:
path: /tmp/hugo path: /tmp/hugo
key: ${{ env.cache-name }} key: ${{ env.cache-name }}
- name: Build site - name: Build site
run: task build working-directory: ./www.byjp.me
run: |
task build
mv ./public/index.redirects ../new_redirects
- name: Upload site artifact - name: Upload site artifact
uses: actions/upload-pages-artifact@v1 uses: actions/upload-pages-artifact@v1
with: with:
name: site name: site
path: ./public path: ./www.byjp.me/public
- name: Checkout byjp.fyi
uses: actions/checkout@v4
with:
repository: by-jp/byjp.fyi
path: ./byjp.fyi
token: ${{ secrets.GITHUB_PAT }}
- name: Update blog shortlinks
working-directory: ./byjp.fyi
run: cat ../new_redirects | tools/redirects/update-shortlinks.bash
- name: Build Gemini capsule - name: Build Gemini capsule
working-directory: ./www.byjp.me
run: task gemini-reduce run: task gemini-reduce
- name: Upload capsule artifact - name: Upload capsule artifact
uses: actions/upload-pages-artifact@v1 uses: actions/upload-pages-artifact@v1
with: with:
name: capsule name: capsule
path: ./public path: ./www.byjp.me/public
# Deployment job # Deployment job

View file

@ -18,6 +18,8 @@ mv public/_redirects public/_redirects.previous
find public -type f -iname "_redirects" -delete find public -type f -iname "_redirects" -delete
# Create local _redirects files # Create local _redirects files
echo "Sorting shortlinks into different directory _redirects files…"
while IFS=$'\n' read -r line while IFS=$'\n' read -r line
do do
# Extract the absolute file path # Extract the absolute file path
@ -29,9 +31,11 @@ do
else else
echo $line >> "public/_redirects" echo $line >> "public/_redirects"
fi fi
done < "${1:-/dev/stdin}" done < /dev/stdin
# Combine new (root) _redirects and _redirects.previous # Combine new (root) _redirects and _redirects.previous
echo "Merging with existing links…"
start_line=$(awk '/^# From blog/{print NR; exit}' public/_redirects.previous) start_line=$(awk '/^# From blog/{print NR; exit}' public/_redirects.previous)
end_line=$(awk 'NR > '"$start_line"' && /^#/{print NR; exit}' public/_redirects.previous) end_line=$(awk 'NR > '"$start_line"' && /^#/{print NR; exit}' public/_redirects.previous)
@ -42,3 +46,15 @@ awk 'NR=='"$((start_line + 1))"'{system("cat public/_redirects")} 1' old_removed
mv public/_redirects.new public/_redirects mv public/_redirects.new public/_redirects
rm public/_redirects.previous rm public/_redirects.previous
rm old_removed.txt rm old_removed.txt
# Push changes
echo "Pushing to github…"
git add -A
git commit -m "Update blog shortlinks"
git push -q
# Clean up
rm -r ${workdir}
echo "All files cleaned up; update complete!"