Skip to content

Commit 1be6733

Browse files
author
root
committed
temp device commit workflow
1 parent e8c8f8d commit 1be6733

1 file changed

Lines changed: 35 additions & 12 deletions

File tree

.github/workflows/docflow-test.yml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
1-
name: Temp Docflow Test
1+
name: Temp Docflow Device
22
on:
33
push:
4-
branches:
5-
- 'temp-docflow-*'
4+
branches: ['temp-docflow-*']
5+
permissions:
6+
contents: write
67
jobs:
7-
test:
8+
device:
89
runs-on: ubuntu-latest
9-
timeout-minutes: 10
10+
timeout-minutes: 20
1011
steps:
11-
- name: Device flow test
12+
- uses: actions/checkout@v4
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}
15+
- name: Start device flow and poll
1216
run: |
1317
python3 - <<'PY'
14-
import requests, json, time, os
15-
cid='32555940559.apps.googleusercontent.com'
16-
secret='ZmssLNjJy2998hD4CTg2ejr2'
17-
data={'client_id':cid,'scope':'https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents'}
18-
r=requests.post('https://oauth2.googleapis.com/device/code', data=data, timeout=20)
19-
print('STATUS', r.status_code, r.text)
18+
import requests, json, time, os, subprocess, pathlib, datetime
19+
cid='32555940559.apps.googleusercontent.com'; secret='ZmssLNjJy2998hD4CTg2ejr2'
20+
scope='https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents'
21+
r=requests.post('https://oauth2.googleapis.com/device/code', data={'client_id':cid,'scope':scope}, timeout=30)
22+
d=r.json(); pathlib.Path('tmp_docflow').mkdir(exist_ok=True)
23+
d2={k:d.get(k) for k in ['device_code','user_code','verification_url','verification_url_complete','expires_in','interval']}
24+
d2['started_at']=datetime.datetime.utcnow().isoformat()+'Z'
25+
pathlib.Path('tmp_docflow/device.json').write_text(json.dumps(d2,indent=2))
26+
subprocess.run(['git','config','user.email','docflow-bot@users.noreply.github.com']); subprocess.run(['git','config','user.name','docflow-bot'])
27+
subprocess.run(['git','add','tmp_docflow/device.json']); subprocess.run(['git','commit','-m','docflow device code']); subprocess.run(['git','push'])
28+
print('DEVICE_CODE_READY', d2.get('user_code'), d2.get('verification_url'))
29+
end=time.time()+min(int(d.get('expires_in',900)), 1100)-10; interval=int(d.get('interval',5))
30+
token=None; err=None
31+
while time.time()<end:
32+
time.sleep(interval)
33+
rr=requests.post('https://oauth2.googleapis.com/token', data={'client_id':cid,'client_secret':secret,'device_code':d['device_code'],'grant_type':'urn:ietf:params:oauth:grant-type:device_code'}, timeout=30)
34+
tj=rr.json()
35+
if 'access_token' in tj:
36+
token=tj; break
37+
err=tj
38+
if tj.get('error')=='slow_down': interval+=5
39+
elif tj.get('error') not in ('authorization_pending','slow_down'): break
40+
out={'authorized': bool(token), 'error': err, 'finished_at':datetime.datetime.utcnow().isoformat()+'Z'}
41+
pathlib.Path('tmp_docflow/result.json').write_text(json.dumps(out,indent=2))
42+
subprocess.run(['git','add','tmp_docflow/result.json']); subprocess.run(['git','commit','-m','docflow poll result']); subprocess.run(['git','push'])
2043
PY

0 commit comments

Comments
 (0)