-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (57 loc) · 2.29 KB
/
conditional_convert_via_pandoc.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
name: conditional_convert_via_pandoc
#
# A script to check for changed and added .md files in content/ and convert those with pandoc (except for _index.md)
#
# Thanks to Gérald Barré aka. meziantou for the basic template of the condition check
# Written by Marcel Kaiser
#
# published: 2024-10-29
# last edit: 2024-11-16
#
on:
push:
branches:
- 'main' # Do the work exclusively for the branch deploying the website
jobs:
# Seperate jobs to be able to possibly use condition_check_files for other tasks as well
condition_check_files:
runs-on: 'ubuntu-22.04'
outputs:
bool_files_changed: ${{ steps.check_file_changed.outputs.bool_files_changed }}
list_changed_files: ${{ steps.check_file_changed.outputs.list_changed_files }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- shell: pwsh
id: check_file_changed
run: |
# Look only for changed files (A - added, M - modified) and return their path+name (the specific changes are irrelevant)
$diff=git diff --name-only --diff-filter=AM "HEAD^" HEAD
# Filter the files under content/ with the .md extension excluding the Hugo associated _index.md files
$FilesDiff=$diff | Where-Object { $_ -match 'content/' -and $_ -match '.md$' -and -not ($_ -match '_index.md') }
$HasDiff=$FilesDiff.Length -gt 0
# Set the output named "bool_files_changed"
echo "bool_files_changed=$HasDiff" >> $env:GITHUB_OUTPUT
echo "list_changed_files=$FilesDiff" >> $env:GITHUB_OUTPUT
# Run the job only with 'bool_files_changed' equals 'True'
# - name: install_pandoc
# uses: pandoc/actions/setup@v1
# with:
# version: 3.5
conditional_pandoc:
runs-on: 'ubuntu-22.04'
needs: [ condition_check_files ]
if: needs.condition_check_files.outputs.bool_files_changed == 'true'
env:
list_changed_files: ${{ needs.condition_check_files.outputs.list_changed_files }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: run_pandoc
uses: docker://pandoc/latex:3.5
with:
run: |
echo "$list_changed_files"
bash ./pandoc.sh "$list_changed_files"