Skip to content

Commit 6262371

Browse files
Merge pull request #657 from shawnthompson/shawn-fix-deploy
refactor: consolidate GitHub Actions workflow for analytics update and deploy
2 parents b386066 + ce75431 commit 6262371

File tree

5 files changed

+1082
-44
lines changed

5 files changed

+1082
-44
lines changed

.github/workflows/gh-pages.yml

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: Deploy and Update Analytics
22

33
on:
4-
push:
5-
branches:
6-
- main
74
schedule:
85
- cron: '0 0 * * *' # Runs every day at midnight UTC
96
workflow_dispatch: # Allows manual triggering
7+
pull_request:
8+
types: [closed]
9+
branches:
10+
- main
1011

1112
jobs:
12-
update-analytics:
13-
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
13+
update-analytics-and-deploy:
14+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.ref == 'refs/heads/main')
1415
runs-on: ubuntu-latest
1516
environment: github-pages # Specify the environment here
1617
steps:
@@ -31,46 +32,14 @@ jobs:
3132
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
3233
PROPERTY_ID: ${{ secrets.PROPERTY_ID }}
3334

34-
deploy:
35-
if: github.event_name == 'push'
36-
runs-on: ubuntu-latest
37-
environment: github-pages # Specify the environment here
38-
steps:
39-
- uses: actions/checkout@v4
40-
with:
41-
ref: 'main'
42-
fetch-depth: '0'
43-
44-
- name: Setup Node
45-
uses: actions/setup-node@v2.1.2
46-
with:
47-
node-version: '20.x'
48-
49-
- name: Reconfigure git to use HTTP authentication
50-
run: >
51-
git config --global url."https://github.com/".insteadOf
52-
ssh://git@github.com/
53-
54-
- name: Cache dependencies
55-
uses: actions/cache@v3
56-
with:
57-
path: ~/.npm
58-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
59-
restore-keys: |
60-
${{ runner.os }}-node-
61-
62-
- run: npm ci
63-
- run: npm run build
64-
env:
65-
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
66-
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
67-
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
68-
PROPERTY_ID: ${{ secrets.PROPERTY_ID }}
35+
- name: Build site
36+
run: npm run build
6937

70-
- name: Deploy
38+
- name: Deploy to GitHub Pages
7139
uses: peaceiris/actions-gh-pages@v4
7240
with:
7341
github_token: ${{ secrets.GITHUB_TOKEN }}
7442
publish_dir: ./_site
7543
user_name: 'github-actions[bot]'
7644
user_email: 'github-actions[bot]@users.noreply.github.com'
45+
publish_branch: gh-pages

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Analytics file created on build
1+
# Ignore analytics.json to prevent frequent commits
22
src/_data/analytics.json
33

44
# Logs

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"start": "cross-env ELEVENTY_WATCH=true ELEVENTY_ENV=local npm-run-all sass-start serve:port --parallel watch:*",
2020
"start-dev": "cross-env ELEVENTY_WATCH=true ELEVENTY_ENV=dev npm-run-all sass-start serve:port --parallel watch:*",
2121
"start-prod": "cross-env ELEVENTY_WATCH=true ELEVENTY_ENV=prod npm-run-all sass-start serve:port --parallel watch:*",
22-
"dev": "cross-env ELEVENTY_ENV=dev npm-run-all analytics sass-build --parallel eleventy",
22+
"dev": "cross-env ELEVENTY_ENV=dev npm-run-all sass-build --parallel eleventy",
2323
"debug": "DEBUG=Eleventy* npx @11ty/eleventy",
24-
"build": "npm-run-all analytics sass-build eleventy"
24+
"build": "npm-run-all sass-build eleventy"
2525
},
2626
"repository": {
2727
"type": "git",

scripts/fetch-analytics.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Generate analytics.json script
2+
// Note: This script requires Google Analytics API keys to successfully run.
3+
// If you intend to update or regenerate the analytics.json file, ensure you have the following keys available in your local .env file:
4+
// GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REFRESH_TOKEN, PROPERTY_ID
5+
16
const { google } = require('googleapis');
27
const analyticsData = google.analyticsdata('v1beta');
38
require('dotenv').config();

0 commit comments

Comments
 (0)