-
Notifications
You must be signed in to change notification settings - Fork 47
97 lines (86 loc) · 3.12 KB
/
process_mdx_file.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
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
name: Process MDX Files
on:
pull_request_target:
paths:
- '**/*.mdx'
jobs:
process-mdx:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
pip install pillow
sudo apt-get install jq
- name: Get list of changed .mdx files
id: changed_files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Fetching PR details..."
PR_NUMBER=$(jq -r .number < "$GITHUB_EVENT_PATH")
REPO_FULL_NAME=$(jq -r .pull_request.base.repo.full_name < "$GITHUB_EVENT_PATH")
echo "PR Number: $PR_NUMBER"
echo "Repository: $REPO_FULL_NAME"
RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_FULL_NAME/pulls/$PR_NUMBER/files")
echo "GitHub API response: $RESPONSE"
CHANGED_FILES=$(echo "$RESPONSE" | jq -r '.[] | select(.filename | endswith(".mdx")) | .filename')
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
echo "Changed files: $CHANGED_FILES"
- name: Run image processing script and check for changes
id: run_script
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CHANGED_FILES: ${{ env.CHANGED_FILES }}
run: |
echo "Running script"
if [ -z "$CHANGED_FILES" ]; then
echo "No .mdx files changed."
else
echo "Running script with files: $CHANGED_FILES"
python scripts/process_images.py $CHANGED_FILES | tee script_output.txt
fi
continue-on-error: true
- name: Set change detection flag
id: set_changes_flag
run: |
if grep -q "CHANGES_MADE" script_output.txt; then
echo "script_changes=true" >> $GITHUB_ENV
else
echo "script_changes=false" >> $GITHUB_ENV
fi
- name: Print changes made by the script
if: env.script_changes == 'true'
run: |
echo "Printing changes made by the script:"
git diff
- name: Commit and push changes
if: env.script_changes == 'true'
env:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "Processed images in MDX files"
git push https://github-actions:${{ secrets.PAT_TOKEN }}@github.com/${{ github.event.pull_request.head.repo.full_name }} HEAD:${{ github.event.pull_request.head.ref }}
continue-on-error: true
- name: Debugging Upload Failure
if: failure()
run: |
echo "Upload failed. Debugging information:"
git status
git log -1
echo "End of debugging information."