Skip to content

Sync Content

Sync Content #260

Workflow file for this run

name: Sync Content
on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
if: ${{ github.repository == 'scientific-python-translations/xarray-translations' && github.ref == 'refs/heads/main' }}
steps:
- name: Set the branch name with more granularity
run: echo "BRANCH_NAME=updates-$(date +%Y-%m-%d-%H-%M-%S)" >> $GITHUB_ENV
- name: Checkout xarray
uses: actions/checkout@v4
with:
repository: 'xarray-contrib/xarray.dev'
path: 'xarray.dev'
ref: 'main'
- name: Checkout xarray-translations
uses: actions/checkout@v4
with:
path: 'xarray-translations'
ref: 'main'
- name: Sync the website content
run: rsync -av --delete --exclude '*.po' xarray.dev/src/ xarray-translations/src/en/
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Process content and check for changes
run: |
cd xarray-translations
npm install
npx jscodeshift -t add_lingui_macros_components.js src/en/components/**/*.js src/en/components/*.js
npx jscodeshift -t add_lingui_macros_components.js src/en/pages/index.js src/en/pages/team.js
npx jscodeshift -t add_lingui_macros_data.js src/en/data/**/*.js src/en/data/*.js
git checkout -b ${{ env.BRANCH_NAME }}
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add .
if git diff --staged --quiet; then
echo "No changes to commit."
echo "CONTENT_CHANGED=false" >> $GITHUB_ENV
else
echo "CONTENT_CHANGED=true" >> $GITHUB_ENV
fi
- name: Extract .po files and commit
if: env.CONTENT_CHANGED == 'true'
run: |
cd xarray-translations
npx lingui extract
git add .
git commit -m "Update website content and translations"
git push -u origin ${{ env.BRANCH_NAME }}
- name: Create Pull Request
if: env.CONTENT_CHANGED == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr create --base main --head ${{ env.BRANCH_NAME }} --title "Update source content" --body "Automated update of xarray.dev content and translations."
working-directory: ./xarray-translations