Build and Deploy #132
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |