forked from rhnfzl/reddit-stash
-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (45 loc) · 1.99 KB
/
Copy pathdropbox-sync.yml
File metadata and controls
54 lines (45 loc) · 1.99 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
name: Sync to Dropbox
on:
push:
branches:
- main
- master
workflow_dispatch:
jobs:
dropbox-sync:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6 # Upgraded to native Node.js 24 support!
- name: Sync Folder to Dropbox via API
env:
DROPBOX_APP_KEY: "${{ secrets.DROPBOX_APP_KEY }}"
DROPBOX_APP_SECRET: "${{ secrets.DROPBOX_APP_SECRET }}"
DROPBOX_REFRESH_TOKEN: "${{ secrets.DROPBOX_REFRESH_TOKEN }}"
REPO_NAME: "${{ github.event.repository.name }}"
run: |
# 1. Clear out internal Git and GitHub tracking configurations
rm -rf .git .github
# 2. Use your refresh token to request a short-lived access token
RESPONSE=$(curl -s -X POST https://api.dropbox.com/oauth2/token \
-u "$DROPBOX_APP_KEY:$DROPBOX_APP_SECRET" \
-d grant_type=refresh_token \
-d refresh_token="$DROPBOX_REFRESH_TOKEN")
ACCESS_TOKEN=$(echo "$RESPONSE" | grep -o '"access_token": "[^"]*' | grep -o '[^"]*$')
if [ -z "$ACCESS_TOKEN" ]; then
echo "Error: Failed to obtain Dropbox Access Token."
echo "API Response: $RESPONSE"
exit 1
fi
# 3. Recursively upload every file in the repository individually
find . -type f | while read -r file; do
# Format file pathing cleanly for the API target destination
CLEAN_PATH=$(echo "$file" | sed 's|^\./||')
DROPBOX_PATH="/$REPO_NAME/$CLEAN_PATH"
echo "Uploading: $CLEAN_PATH -> Dropbox: $DROPBOX_PATH"
curl -X POST https://content.dropboxapi.com/2/files/upload \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Dropbox-API-Arg: {\"path\": \"$DROPBOX_PATH\",\"mode\": \"overwrite\",\"autorename\": false,\"mute\": true}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$file"
done