Skip to content

Add Assets to Index #79

Add Assets to Index

Add Assets to Index #79

Workflow file for this run

name: Add Assets to Index
concurrency:
group: index
cancel-in-progress: false
on:
workflow_dispatch:
inputs:
project:
type: string
description: project name
urls:
type: string
description: asset urls
default: ""
index-branch:
type: string
description: index branch
required: false
default: idx-pages
republish:
type: boolean
description: republish pages
required: false
default: true
jobs:
add:
name: Push URLs to Index
runs-on: ubuntu-latest
permissions:
contents: write
env:
idx-checkout-path: idx-pages
steps:
- name: checkout index branch
uses: actions/checkout@v3
with:
path: ${{ env.idx-checkout-path }}
ref: ${{ inputs.index-branch }}
- name: update simple index
env:
proj: ${{ inputs.project }}
urls: ${{ inputs.urls }}
run: |
cd ${{ env.idx-checkout-path }}
if [ ! -f index.html ]; then
echo -e "<!DOCTYPE html>\n<html>\n <body>\n </body>\n</html>" > index.html
fi
proj=$(echo ${proj} | tr "\-_." "-" | tr -s "-" | tr "A-Z" "a-z")
echo "::debug::project=${proj}"
proj_html="${proj}/index.html"
if [[ $(grep ">${proj}<" index.html) == "" ]]; then
sed -i "/<\/body>/ i \ <a href=\"${proj}\/\">${proj}<\/a><br>" index.html
mkdir -p ${proj}
echo -e "<!DOCTYPE html>\n<html>\n <body>\n </body>\n</html>" > $proj_html
fi
for url in $urls; do
fname=$(basename $url)
fname=(${fname//#/ }[0])
if [[ $(cat $proj_html | grep ">${fname}<") == "" ]]; then
sed -i "/<\/body>/ i \ <a href=\"$url\">${fname}<\/a><br>" $proj_html
else
sed -i "/>${fname}</ c \ <a href=\"$url\">${fname}<\/a><br>" $proj_html
fi
done;
- name: commit index changes
run: |
cd ${{ env.idx-checkout-path }}
git config --local user.name 'github-actions[bot]'
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "update project \`${{ inputs.project }}\`"
git push
publish:
if: ${{ inputs.republish }}
needs: add
name: Republish Index Pages
permissions:
contents: read
pages: write
id-token: write
uses: aioqzone/gh-simple-api/.github/workflows/publish.yml@master