generated from aioqzone/gh-simple-api
-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (81 loc) · 2.57 KB
/
add.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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