Delete docs/test.md #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_cond: ${{ 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 | |
- id: check_file_changed | |
name: Check the docs directory for new markdown documents | |
shell: pwsh | |
run: | | |
# Diff HEAD with the previous commit | |
$diff = git diff --name-only --diff-filter=AD HEAD^ HEAD | |
# Check if a markdown file and only a markdown file in the docs/ directory has been added or deleted | |
$SourceDiff = $diff | Where-Object { ($_ -match '^A' -or $_ -match '^D') -and $_ -match '^docs/' } | |
$HasDiff = $SourceDiff.Length -gt 0 | |
# Set the output named "docs_changed" | |
Write-Output "$HasDiff, The index.md should be changed." | |
Write-Output "docs_changed=$HasDiff" >> $env:GITHUB_OUTPUT | |
# Run the job only with "docs_changed" equals "True" | |
conditional_update_index_job: | |
needs: conditional_job_check_files | |
if: ${{ needs.conditional_job_check_files.outputs.docs_cond == 'True' }} | |
runs-on: 'ubuntu-20.04' | |
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 }} |