Skip to content

Commit cc1b1f3

Browse files
committed
Streamlined updates with Actions and App tokens
1 parent b8f6cc7 commit cc1b1f3

4 files changed

Lines changed: 53 additions & 65 deletions

File tree

.github/scripts/cache.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ set -eu
55
### VARIABLES ###
66

77
# From action env:
8-
# BOT_TOKEN
9-
# DATA_REPO
8+
# REPO_DIR
109

1110
ACT_SCRIPT_PATH=_visualize/scripts
1211

1312
### SETUP ###
1413

15-
export GITHUB_API_TOKEN=$BOT_TOKEN
16-
17-
DATA_TIMESTAMP=$(date -u "+%F-%H")
18-
1914
# Store absolute path
20-
cd $DATA_REPO
15+
cd $REPO_DIR
2116
REPO_ROOT=$(pwd)
2217

2318
### RUN CACHE SCRIPT ###

.github/scripts/update.sh

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ set -eu
55
### VARIABLES ###
66

77
# From action env:
8-
# BOT_USER
9-
# BOT_TOKEN
10-
# DATA_REPO
8+
# REPO_DIR
119

1210
ACT_LOG_PATH=_visualize/LAST_MASTER_UPDATE.txt
1311
ACT_INPUT_PATH=_visualize
@@ -16,16 +14,8 @@ ACT_SCRIPT_PATH=_visualize/scripts
1614

1715
### SETUP ###
1816

19-
export GITHUB_API_TOKEN=$BOT_TOKEN
20-
21-
DATA_TIMESTAMP=$(date -u "+%F-%H")
22-
23-
# Configure git
24-
git config --global user.name "${BOT_USER}"
25-
git config --global user.email "${BOT_USER}@users.noreply.github.com"
26-
2717
# Store absolute path
28-
cd $DATA_REPO
18+
cd $REPO_DIR
2919
REPO_ROOT=$(pwd)
3020

3121
# Store previous END timestamp
@@ -83,12 +73,4 @@ if [ "$CHANGE_COUNT" -ne "$VALID_COUNT" ]
8373
echo "Changed files validated"
8474
fi
8575

86-
### COMMIT UPDATE ###
87-
git stash
88-
git pull --ff-only
89-
git stash pop
90-
git add -A .
91-
git commit -m "${DATA_TIMESTAMP} Data Update by ${BOT_USER}"
92-
git push
93-
9476
exit 0

.github/workflows/cache.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ on:
44
schedule:
55
- cron: "45 8 * * *"
66

7-
env:
8-
# GitHub username (owner of BOT_TOKEN, will be credited for updates)
9-
BOT_USER: lc-bot
10-
# Paths used to store cloned repositories
11-
ACTION_REPO: thisrepo
12-
DATA_REPO: thisrepo
13-
147
defaults:
158
run:
169
shell: bash
@@ -20,6 +13,7 @@ jobs:
2013
name: Run Cache Request
2114
runs-on: ubuntu-latest
2215
env:
16+
REPO_DIR: main
2317
TIMESTAMP: X
2418
steps:
2519
- name: Store timestamp
@@ -28,32 +22,32 @@ jobs:
2822
- name: Checkout
2923
uses: actions/checkout@v4
3024
with:
31-
path: ${{ env.ACTION_REPO }}
32-
token: ${{ secrets.BOT_TOKEN }}
25+
path: ${{ env.REPO_DIR }}
26+
token: ${{ secrets.GITHUB_TOKEN }}
3327
- name: Setup python
3428
uses: actions/setup-python@v5
3529
with:
3630
python-version: "3.11"
3731
cache: "pip"
38-
cache-dependency-path: "${{ env.DATA_REPO }}/_visualize/scripts/requirements.txt"
32+
cache-dependency-path: "${{ env.REPO_DIR }}/_visualize/scripts/requirements.txt"
3933
- name: Install dependencies
40-
run: pip install -r $DATA_REPO/_visualize/scripts/requirements.txt
34+
run: pip install -r $REPO_DIR/_visualize/scripts/requirements.txt
4135
- name: Run cache script
42-
run: ./$ACTION_REPO/.github/scripts/cache.sh
36+
run: ./$REPO_DIR/.github/scripts/cache.sh
4337
env:
44-
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
38+
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4539
- name: Show health stats
4640
if: ${{ always() }}
4741
run: |
48-
cat $DATA_REPO/_visualize/LAST_CACHE_REQUEST.txt || true
49-
echo "Warning Count: $(grep -c 'Warning' $DATA_REPO/_visualize/LAST_CACHE_REQUEST.log)"
50-
echo "From Timeouts: $(grep -c 'but failed' $DATA_REPO/_visualize/LAST_CACHE_REQUEST.log)"
51-
echo "Limit Reached: $(grep -c 'rate limit exceeded' $DATA_REPO/_visualize/LAST_CACHE_REQUEST.log)"
42+
cat $REPO_DIR/_visualize/LAST_CACHE_REQUEST.txt || true
43+
echo "Warning Count: $(grep -c 'Warning' $REPO_DIR/_visualize/LAST_CACHE_REQUEST.log)"
44+
echo "From Timeouts: $(grep -c 'but failed' $REPO_DIR/_visualize/LAST_CACHE_REQUEST.log)"
45+
echo "Limit Reached: $(grep -c 'rate limit exceeded' $REPO_DIR/_visualize/LAST_CACHE_REQUEST.log)"
5246
- name: Save log files
5347
if: ${{ always() }}
5448
uses: actions/upload-artifact@v4
5549
with:
5650
name: logfiles_${{ env.TIMESTAMP }}_cache
5751
path: |
58-
${{ env.DATA_REPO }}/_visualize/LAST_CACHE_REQUEST.txt
59-
${{ env.DATA_REPO }}/_visualize/LAST_CACHE_REQUEST.log
52+
${{ env.REPO_DIR }}/_visualize/LAST_CACHE_REQUEST.txt
53+
${{ env.REPO_DIR }}/_visualize/LAST_CACHE_REQUEST.log

.github/workflows/update.yml

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ on:
44
schedule:
55
- cron: "45 10 * * *"
66

7-
env:
8-
# GitHub username (owner of BOT_TOKEN, will be credited for updates)
9-
BOT_USER: lc-bot
10-
# Paths used to store cloned repositories
11-
ACTION_REPO: thisrepo
12-
DATA_REPO: thisrepo
13-
147
defaults:
158
run:
169
shell: bash
@@ -20,6 +13,7 @@ jobs:
2013
name: Run Data Update
2114
runs-on: ubuntu-latest
2215
env:
16+
REPO_DIR: main
2317
TIMESTAMP: X
2418
steps:
2519
- name: Store timestamp
@@ -28,32 +22,55 @@ jobs:
2822
- name: Checkout
2923
uses: actions/checkout@v4
3024
with:
31-
path: ${{ env.ACTION_REPO }}
32-
token: ${{ secrets.BOT_TOKEN }}
25+
path: ${{ env.REPO_DIR }}
26+
token: ${{ secrets.GITHUB_TOKEN }}
3327
- name: Setup python
3428
uses: actions/setup-python@v5
3529
with:
3630
python-version: "3.11"
3731
cache: "pip"
38-
cache-dependency-path: "${{ env.DATA_REPO }}/_visualize/scripts/requirements.txt"
32+
cache-dependency-path: "${{ env.REPO_DIR }}/_visualize/scripts/requirements.txt"
3933
- name: Install dependencies
40-
run: pip install -r $DATA_REPO/_visualize/scripts/requirements.txt
34+
run: pip install -r $REPO_DIR/_visualize/scripts/requirements.txt
4135
- name: Run update script
42-
run: ./$ACTION_REPO/.github/scripts/update.sh
36+
run: ./$REPO_DIR/.github/scripts/update.sh
37+
env:
38+
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
- name: Create GitHub App Installation Token
40+
uses: actions/create-github-app-token@v2
41+
id: app-token
42+
with:
43+
app-id: ${{ vars.APP_ID }}
44+
private-key: ${{ secrets.PRIVATE_KEY }}
45+
- name: Get GitHub App User ID
46+
id: get-user-id
47+
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
4348
env:
44-
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
49+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
50+
- name: Git config
51+
run: |
52+
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
53+
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
54+
- name: Commit updated data
55+
run: |
56+
git stash
57+
git pull --ff-only
58+
git stash pop
59+
git add -A .
60+
git commit -m "${{ env.TIMESTAMP }} Data Update by ${{ steps.app-token.outputs.app-slug }}"
61+
git push
4562
- name: Show health stats
4663
if: ${{ always() }}
4764
run: |
48-
cat $DATA_REPO/_visualize/LAST_MASTER_UPDATE.txt || true
49-
echo "Warning Count: $(grep -c 'Warning' $DATA_REPO/_visualize/LAST_MASTER_UPDATE.log)"
50-
echo "From Timeouts: $(grep -c 'but failed' $DATA_REPO/_visualize/LAST_MASTER_UPDATE.log)"
51-
echo "Limit Reached: $(grep -c 'rate limit exceeded' $DATA_REPO/_visualize/LAST_MASTER_UPDATE.log)"
65+
cat $REPO_DIR/_visualize/LAST_MASTER_UPDATE.txt || true
66+
echo "Warning Count: $(grep -c 'Warning' $REPO_DIR/_visualize/LAST_MASTER_UPDATE.log)"
67+
echo "From Timeouts: $(grep -c 'but failed' $REPO_DIR/_visualize/LAST_MASTER_UPDATE.log)"
68+
echo "Limit Reached: $(grep -c 'rate limit exceeded' $REPO_DIR/_visualize/LAST_MASTER_UPDATE.log)"
5269
- name: Save log files
5370
if: ${{ always() }}
5471
uses: actions/upload-artifact@v4
5572
with:
5673
name: logfiles_${{ env.TIMESTAMP }}_update
5774
path: |
58-
${{ env.DATA_REPO }}/_visualize/LAST_MASTER_UPDATE.txt
59-
${{ env.DATA_REPO }}/_visualize/LAST_MASTER_UPDATE.log
75+
${{ env.REPO_DIR }}/_visualize/LAST_MASTER_UPDATE.txt
76+
${{ env.REPO_DIR }}/_visualize/LAST_MASTER_UPDATE.log

0 commit comments

Comments
 (0)