-
Notifications
You must be signed in to change notification settings - Fork 72
82 lines (67 loc) · 2.26 KB
/
build-and-deploy.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
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Build and Deploy
on:
schedule:
- cron: '0 */6 * * *' # Runs every 6 hours
push:
branches:
- main
workflow_dispatch: # Allows manual trigger
concurrency:
group: build-and-deploy
cancel-in-progress: false
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Skip Workflow for Forks
if: ${{ github.repository != 'mozilla/standards-positions' }}
run: |
echo "Skipping job for fork repository."
exit 0
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for proper merging
- name: Set up SSH for Git (deploy key)
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Dependencies
run: |
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- name: Configure Git User
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch and Check Out `gh-pages`
run: |
git fetch origin gh-pages:gh-pages
git checkout gh-pages
- name: Merge `main` into `gh-pages`
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git merge ${{ github.sha }} --strategy recursive -X theirs --no-edit
- name: Generate Merged Data
run: |
python3 gh-data.py
python3 merge-data.py
- name: Commit and Push Updates
run: |
# Add changes
git add -f merged-data.json
# Commit changes if there are any
if ! git diff --cached --quiet; then
git commit -m "Update GitHub Pages with latest data"
else
echo "No changes to commit."
fi
# Push changes back to `gh-pages`
git remote set-url origin [email protected]:${{ github.repository }}.git
git push origin gh-pages