-
Notifications
You must be signed in to change notification settings - Fork 3
62 lines (53 loc) · 2.1 KB
/
update_index.yaml
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
name: Update index.md with Markdown Links
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
#https://www.meziantou.net/executing-github-actions-jobs-or-steps-only-when-specific-files-change.htm
conditional_job_check_files:
runs-on: 'ubuntu-20.04'
# Declare outputs for next jobs
outputs:
docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }}
steps:
- uses: actions/checkout@v4
with:
# Checkout as many commits as needed for the diff
fetch-depth: 2
- shell: pwsh
id: check_file_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff --name-only HEAD^ HEAD
# Check if a file under docs/ or with the .md extension has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '^docs/' -or $_ -match '.md$' }
$HasDiff = $SourceDiff.Length -gt 0
# Set the output named "docs_changed"
Write-Host "docs_changed=$HasDiff" >> $GITHUB_OUTPUT
# Run the job only with "docs_changed" equals "True"
conditional_update_index_job:
runs-on: 'ubuntu-20.04'
needs: [ conditional_job_check_files ]
if: needs.conditional_job_check_files.outputs.docs_changed == 'True'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract Markdown links and update index.md
run: |
find docs -type f -name "*.md" > links.txt
awk -F/ '{gsub(/\.md$/, ""); gsub(/ /, "\\ "); printf "[%s](%s)\n", $NF, $0}' links.txt > tmp && mv tmp links.txt
awk 'BEGIN{p=1} /^## Notes/{print "## Notes"; while(getline < "links.txt") {print; print "\n"}; p=0} p' index.md > temp_index.md && mv temp_index.md index.md
rm links.txt
- name: commit
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -am "Automated index.md update"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}