-
Notifications
You must be signed in to change notification settings - Fork 15
132 lines (114 loc) · 4.23 KB
/
Copy pathsync-tolk-grammar.yml
File metadata and controls
132 lines (114 loc) · 4.23 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Sync Tolk tree-sitter Grammar
on:
push:
paths:
- "server/src/languages/tolk/tree-sitter-tolk/**"
branches:
- main
workflow_dispatch:
inputs:
force_sync:
description: "Force sync even without changes"
required: false
default: false
type: boolean
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GRAMMAR_REPO: "ton-blockchain/tree-sitter-tolk"
GRAMMAR_PATH: "server/src/languages/tolk/tree-sitter-tolk"
jobs:
sync-grammar:
name: Sync Tolk Grammar
runs-on: ubuntu-latest
if: github.repository == 'ton-blockchain/ton-language-server'
permissions:
contents: read
steps:
- name: Checkout source repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
path: source
- name: Checkout target repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
repository: ${{ env.GRAMMAR_REPO }}
token: ${{ secrets.GRAMMAR_SYNC_TOKEN }}
path: target
- name: Setup Git in target repository
working-directory: target
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Sync grammar files
env:
SOURCE_GRAMMAR_PATH: ${{ env.GRAMMAR_PATH }}
run: |
rsync -a --delete \
--exclude='.git' \
--exclude='node_modules' \
--exclude='.yarn' \
--exclude='build' \
--exclude='target' \
--exclude='.DS_Store' \
"source/${SOURCE_GRAMMAR_PATH}/" "target/"
- name: Check for changes
id: changes
working-directory: target
run: |
git add .
if git diff --cached --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "No changes to sync"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "Changes detected:"
git diff --cached --name-status
fi
- name: Create commit and push
if: steps.changes.outputs.has_changes == 'true' || github.event.inputs.force_sync == 'true'
working-directory: target
env:
FORCE_SYNC: ${{ github.event.inputs.force_sync || 'false' }}
run: |
# Get the latest commit info from source
cd ../source
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_MSG=$(git log -1 --pretty=format:"%s")
COMMIT_AUTHOR=$(git log -1 --pretty=format:"%an")
cd ../target
# Create commit message
if [ "$FORCE_SYNC" = "true" ]; then
SYNC_MSG="chore: force sync from ton-language-server@${COMMIT_SHA:0:7}"
else
SYNC_MSG="sync: ${COMMIT_MSG}"
fi
echo "Creating commit: $SYNC_MSG"
git add .
git commit -m "$SYNC_MSG" \
-m "Synced from: ton-blockchain/ton-language-server@$COMMIT_SHA" \
-m "Original author: $COMMIT_AUTHOR" || true
# Push changes
git push origin main
- name: Create summary
env:
FORCE_SYNC: ${{ github.event.inputs.force_sync || 'false' }}
HAS_CHANGES: ${{ steps.changes.outputs.has_changes }}
TARGET_GRAMMAR_REPO: ${{ env.GRAMMAR_REPO }}
TRIGGER_EVENT: ${{ github.event_name }}
run: |
echo "## Grammar Sync Summary" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
if [ "$HAS_CHANGES" = "true" ] || [ "$FORCE_SYNC" = "true" ]; then
echo "✅ Grammar successfully synced to [${TARGET_GRAMMAR_REPO}](https://github.com/${TARGET_GRAMMAR_REPO})" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Source commit:** $(cd source && git rev-parse HEAD)" >> "$GITHUB_STEP_SUMMARY"
echo "**Trigger:** $TRIGGER_EVENT" >> "$GITHUB_STEP_SUMMARY"
else
echo "ℹ️ No changes to sync" >> "$GITHUB_STEP_SUMMARY"
fi