-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (55 loc) · 2.33 KB
/
drive-sync.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
name: Google Drive Sync
on:
workflow_dispatch:
schedule:
# 12 hourly
- cron: '0 */12 * * *'
permissions:
contents: write
env:
CONTENT_DIR: "./content"
jobs:
download_and_sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Print Directory Contents
run: ls -al
- 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 gdown
- name: Delete Existing Content
run: |
rm -rf ${{ env.CONTENT_DIR }}
- name: Download files from Google Drive
env:
OUTPUT_DIR: "./content"
run: |
gdown --folder --id "${{ secrets.GOOGLE_DRIVE_FOLDER_ID }}" --output "${{ env.OUTPUT_DIR }}"
ls -al ${{ env.OUTPUT_DIR }}
- name: Commit Diff
run: |
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config user.name "${{ github.actor }}"
git add .
git commit -m "Drive sync: $(date +'%B %d, %Y %H:%M %p')" || echo "No changes to commit."
- name: Push Commit
run: |
git push origin ${{ github.head_ref || github.ref }} || echo "No changes to push."
- name: Trigger Deploy Workflow if Changes Were Pushed
env:
DEPLOY_FILE: "deploy.yml"
run: |
if [ -n "$(git diff --name-only HEAD^ HEAD)" ]; then
echo "Changes detected. Triggering deploy workflow."
export BRANCH_NAME=$(echo ${{ github.head_ref || github.ref }} | awk -F'/' '{print $NF}')
curl -X POST -H "Authorization: Bearer ${{ secrets.GHUB_PERSONAL_ACCESS_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/actions/workflows/${{ env.DEPLOY_FILE }}/dispatches -d "{\"ref\":\"$BRANCH_NAME\"}"
else
echo "No changes detected. Skipping deploy workflow."
fi