forked from RyanMcCleary/nvda-mathcat
-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (100 loc) · 4.16 KB
/
fetchAssets.yaml
File metadata and controls
116 lines (100 loc) · 4.16 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
name: Fetch Assets
on:
schedule:
- cron: '0 0 * * 1'
workflow_dispatch:
permissions:
contents: write
jobs:
fetch-and-commit-assets:
runs-on: ubuntu-latest
env:
REQUIRED_ASSETS: |
Rules.zip
libmathcat_py-64-3.13-win.zip
RELEASE_URL: https://api.github.com/repos/NSoiffer/MathCATForPython/releases/latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Delete previously downloaded assets
run: rm -rf assets/*
- name: Download assets
run: |
echo "REQUIRED_ASSETS=$REQUIRED_ASSETS"
release_data=$(curl -s -H 'Accept: application/vnd.github.v3+json' "$RELEASE_URL")
if [[ ! -d assets ]] ; then
echo 'Directory "assets" does not exist. Creating it.'
mkdir assets
else
echo 'Directory "assets" exists.'
fi
while IFS= read -r asset_name; do
if [[ "$asset_name" =~ ^[[:space:]]*$ ]]; then
continue
fi
echo "asset_name=$asset_name"
asset_url=$(echo "$release_data" | jq -r ".assets[] | select(.name == \"$asset_name\") | .url")
if [[ "$asset_url" != "null" ]]; then
echo "Downloading $asset_name"
curl -L -H "Accept: application/octet-stream" -o "$asset_name" "$asset_url"
else
echo "Asset $asset_name not found in the latest release."
exit 1
fi
unzip -o "$asset_name" -d assets
rm -f "$asset_name"
done <<< "$REQUIRED_ASSETS"
# Extract nested zip files inside Rules directory
find assets/Rules -type f -name '*.zip' -print0 \
| xargs -0 -I {} sh -c 'unzip "{}" -d "$(dirname "{}")" && rm -f "{}"'
- name: Commit and push downloaded assets
run: |
git add assets
git diff --cached --quiet && echo "No changes to commit" && exit 0
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git commit -m "Add downloaded assets"
git push
- name: Open PR to nvda repo
env:
GH_PUSH_TOKEN: ${{ secrets.NVDA_PUSH_TOKEN }}
GH_PR_TOKEN: ${{ secrets.NVDA_PR_TOKEN }}
run: |
# Authenticate with GitHub CLI
gh auth login --with-token <<< "${GH_PUSH_TOKEN}"
# Get the fork owner (the authenticated user/organization)
fork_owner=$(gh api user --jq '.login')
# Clone the fork
git clone https://x-access-token:${GH_PUSH_TOKEN}@github.com/${fork_owner}/nvda.git
cd nvda
# Configure git
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
# Add upstream remote
git remote add upstream https://github.com/nvaccess/nvda.git
# Fetch latest changes from upstream
git fetch upstream master
# Create new branch for our changes
new_branch="update-mathcat-submodule-$(date +%Y-%m-%d_%H-%M-%S)"
git checkout -b "$new_branch" upstream/master
# Update the submodule
git submodule sync --recursive
git submodule update --init --recursive
cd include/nvda-mathcat
git pull origin main
cd ../..
git add include/nvda-mathcat
# Check if there are any changes to commit
git diff --cached --quiet && echo 'No submodule updates; skipping PR.' && exit 0
# Commit and push to fork
git commit -m "Update nvda-mathcat submodule"
# Authenticate with GitHub CLI
gh auth login --with-token <<< "${GH_PR_TOKEN}"
git push origin "$new_branch"
# Create PR from fork to upstream
gh pr create \
--repo nvaccess/nvda \
--title "Update nvda-mathcat submodule" \
--body "Automated update of the nvda-mathcat submodule with latest assets. Reminder: the changelog needs to be updated manually to reflect these changes." \
--head "${fork_owner}:${new_branch}" \
--base master