-
Notifications
You must be signed in to change notification settings - Fork 8
195 lines (163 loc) · 6.96 KB
/
Copy pathmain.yml
File metadata and controls
195 lines (163 loc) · 6.96 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Validate and Sync Content
on:
push:
branches:
- main
pull_request_target:
types: [ labeled, synchronize, opened ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: false
jobs:
validate:
name: Validate HTML Content
runs-on: arc-runners-small
steps:
- name: Checkout base branch for pull_request_target
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Checkout current ref for push and workflow_dispatch
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v6
- name: Configure git identity
if: github.event_name == 'pull_request_target'
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
- name: Fetch head branch for pull_request_target
if: github.event_name == 'pull_request_target'
run: git fetch https://github.com/${{ github.event.pull_request.head.repo.full_name }} ${{ github.event.pull_request.head.ref }}
- name: Merge head into base for pull_request_target
if: github.event_name == 'pull_request_target'
run: |
git merge --no-ff FETCH_HEAD || (echo "Merge conflict detected" && exit 1)
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
- name: Install dependencies (Node)
# Assuming package.json is at the root and contains necessary deps for validation script
run: npm install
- name: Validate HTML content
run: node .github/scripts/validate-content.js
- name: Post comment
if: |
(failure() || success()) && github.event_name == 'pull_request_target'
uses: mshick/add-pr-comment@v2
with:
refresh-message-position: true
message-id: validation
message: failure
message-success: |
## Validation Success
message-failure: |
## Validation is failed
Please check [run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
sync-templates:
name: Sync Templates to Supabase
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: arc-runners-small
needs: validate # Depends on the 'validate' job succeeding
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Install dependencies (Python)
run: |
python -m pip install --upgrade pip
pip install supabase
- name: Sync templates to Supabase
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
run: python .github/scripts/sync_templates.py
sync-content:
name: Sync Stage Content to Supabase
if: github.event_name != 'pull_request_target' || contains(github.event.pull_request.labels.*.name, 'safe-to-run')
runs-on: arc-runners-small
needs: validate # Depends on the 'validate' job succeeding
steps:
- name: Checkout base branch for pull_request_target
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
- name: Checkout current ref for push and workflow_dispatch
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Configure git identity
if: github.event_name == 'pull_request_target'
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
- name: Fetch head branch for pull_request_target
if: github.event_name == 'pull_request_target'
run: git fetch https://github.com/${{ github.event.pull_request.head.repo.full_name }} ${{ github.event.pull_request.head.ref }}
- name: Merge head into base for pull_request_target
if: github.event_name == 'pull_request_target'
run: |
git merge --no-ff FETCH_HEAD || (echo "Merge conflict detected" && exit 1)
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Install dependencies (Python)
run: |
python -m pip install --upgrade pip
pip install supabase
- name: Sync stage content to Supabase
id: sync-content
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
PR_NUMBER: ${{ github.event.number }}
run: |
python .github/scripts/sync_content.py | tee sync_output.log
# Extract draft project information from the output
if grep -q "DRAFT_PROJECT:" sync_output.log; then
echo "draft_projects_found=true" >> $GITHUB_OUTPUT
grep "DRAFT_PROJECT:" sync_output.log > draft_projects.txt
else
echo "draft_projects_found=false" >> $GITHUB_OUTPUT
fi
- name: Generate comment body with draft project links
if: ${{ github.event_name == 'pull_request_target' && steps.sync-content.outputs.draft_projects_found == 'true' }}
id: generate-comment
run: |
# Read draft projects data
COMMENT_BODY=""
while IFS= read -r line; do
if [[ $line == DRAFT_PROJECT:* ]]; then
# Parse the line: DRAFT_PROJECT:<draft_id>:<original_id>:<title>
IFS=':' read -r _ DRAFT_ID ORIGINAL_ID TITLE_REST <<< "$line"
# Handle titles that might contain colons
TITLE="${line#DRAFT_PROJECT:$DRAFT_ID:$ORIGINAL_ID:}"
# Add project to comment body
COMMENT_BODY+="- [${TITLE}](https://enlightby.ai/projects/${DRAFT_ID}) (Draft ID: ${DRAFT_ID}, Original ID: ${ORIGINAL_ID})"
fi
done < draft_projects.txt
# Escape newlines for GitHub Actions output
COMMENT_BODY="${COMMENT_BODY//'%'/'%25'}"
COMMENT_BODY="${COMMENT_BODY//$'\n'/'%0A'}"
COMMENT_BODY="${COMMENT_BODY//$'\r'/'%0D'}"
echo "comment_body=${COMMENT_BODY}" >> $GITHUB_OUTPUT
- name: Post comment with draft project links
if: ${{ github.event_name == 'pull_request_target' && steps.sync-content.outputs.draft_projects_found == 'true' }}
uses: mshick/add-pr-comment@v2
with:
refresh-message-position: true
message-id: draft
status: success
message-success: |
## 🚀 Draft Projects Created
The following draft projects have been created in this PR:
${{ steps.generate-comment.outputs.comment_body }}