Skip to content

Add .env file creation step in GitHub Actions workflow #340

Add .env file creation step in GitHub Actions workflow

Add .env file creation step in GitHub Actions workflow #340

Workflow file for this run

name: Deploy and Update Analytics
on:
push:
branches:
- main
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC
workflow_dispatch: # Allows manual triggering
jobs:
deploy:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write # Ensure GitHub Actions can push to the repository
steps:
- uses: actions/checkout@v4
with:
ref: 'main'
fetch-depth: '0'
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://[email protected]/
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- name: Build site
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
publish_branch: gh-pages
update-analytics:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
environment: github-pages
permissions:
contents: write # Ensure GitHub Actions can push to the repository
steps:
- uses: actions/checkout@v4
with:
ref: 'main'
fetch-depth: '0'
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://[email protected]/
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- name: Create .env File
run: |
echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> .env
echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> .env
echo GOOGLE_REFRESH_TOKEN=${{ secrets.GOOGLE_REFRESH_TOKEN }} >> .env
echo PROPERTY_ID=${{ secrets.PROPERTY_ID }} >> .env
- name: Run analytics update
run: npm run analytics
- name: Build site
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
publish_branch: gh-pages