-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (97 loc) · 3.44 KB
/
sync.yml
File metadata and controls
115 lines (97 loc) · 3.44 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Sync Articles to Zendesk
on:
push:
branches: [main]
paths:
- "articles/**"
workflow_dispatch:
inputs:
full_sync:
description: "Run a full sync of all articles"
required: false
default: "false"
type: choice
options:
- "false"
- "true"
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Determine changed files
id: changes
if: github.event_name == 'push'
run: |
ADDED_MODIFIED=$(git diff --name-only --diff-filter=ACMR HEAD~1 HEAD -- 'articles/' | grep '\.md$' || true)
DELETED=$(git diff --name-only --diff-filter=D HEAD~1 HEAD -- 'articles/' | grep '\.md$' || true)
echo "added_modified<<EOF" >> "$GITHUB_OUTPUT"
echo "$ADDED_MODIFIED" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "deleted<<EOF" >> "$GITHUB_OUTPUT"
echo "$DELETED" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
if [ -z "$ADDED_MODIFIED" ] && [ -z "$DELETED" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Full sync
if: github.event.inputs.full_sync == 'true'
env:
ZENDESK_SUBDOMAIN: ${{ secrets.ZENDESK_SUBDOMAIN }}
ZENDESK_EMAIL: ${{ secrets.ZENDESK_EMAIL }}
ZENDESK_API_TOKEN: ${{ secrets.ZENDESK_API_TOKEN }}
run: |
cd scripts
python sync.py --full --verbose
- name: Diff-based sync
if: github.event_name == 'push' && steps.changes.outputs.has_changes == 'true' && github.event.inputs.full_sync != 'true'
env:
ZENDESK_SUBDOMAIN: ${{ secrets.ZENDESK_SUBDOMAIN }}
ZENDESK_EMAIL: ${{ secrets.ZENDESK_EMAIL }}
ZENDESK_API_TOKEN: ${{ secrets.ZENDESK_API_TOKEN }}
run: |
cd scripts
ADDED_MODIFIED="${{ steps.changes.outputs.added_modified }}"
DELETED="${{ steps.changes.outputs.deleted }}"
ARGS=""
if [ -n "$ADDED_MODIFIED" ]; then
while IFS= read -r file; do
[ -n "$file" ] && ARGS="$ARGS ../$file"
done <<< "$ADDED_MODIFIED"
fi
DELETE_ARGS=""
if [ -n "$DELETED" ]; then
while IFS= read -r file; do
[ -n "$file" ] && DELETE_ARGS="$DELETE_ARGS ../$file"
done <<< "$DELETED"
fi
CMD="python sync.py --verbose"
[ -n "$ARGS" ] && CMD="$CMD $ARGS"
[ -n "$DELETE_ARGS" ] && CMD="$CMD --deleted $DELETE_ARGS"
eval $CMD
- name: Commit updated article IDs
if: success()
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add articles/
if git diff --cached --quiet; then
echo "No article ID updates to commit."
else
git commit -m "chore: update article IDs from Zendesk sync"
git push
fi