Sync Content #158
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: Sync Content | |
on: | |
schedule: | |
- cron: '0 5 * * *' | |
workflow_dispatch: | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
# Run only on main branch in upstream repo. | |
if: ${{ github.repository == 'scientific-python-translations/zarr.dev-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 zarr-developers.github.io | |
uses: actions/checkout@v4 | |
with: | |
repository: 'zarr-developers/zarr-developers.github.io' | |
path: 'zarr-developers.github.io' | |
ref: 'main' | |
- name: Checkout zarr.dev-translations | |
uses: actions/checkout@v4 | |
with: | |
path: 'zarr.dev-translations' | |
ref: 'main' | |
- name: Sync the website content | |
run: | | |
rsync -av --delete zarr-developers.github.io/ zarr.dev-translations/content/en | |
cd zarr.dev-translations | |
git checkout -b ${{ env.BRANCH_NAME }} | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git add . | |
# Only proceed to commit if there are changes | |
if git diff --staged --quiet; then | |
echo "No changes to commit." | |
echo "CONTENT_CHANGED=false" >> $GITHUB_ENV | |
else | |
git commit -m "Update website content" | |
echo "CONTENT_CHANGED=true" >> $GITHUB_ENV | |
git push -u origin ${{ env.BRANCH_NAME }} | |
fi | |
- 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 zarr-developers.github.io content." | |
working-directory: ./zarr.dev-translations |