Fetch upstream #218
This file contains hidden or 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: Fetch upstream | |
| on: | |
| schedule: | |
| - cron: '30 8 * * 4' # run every week *before* release | |
| workflow_dispatch: | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| env: | |
| UPSTREAM_DIR: ./rime-cantonese-upstream | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Checkout Upstream | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: CanCLID/rime-cantonese-upstream | |
| path: ${{ env.UPSTREAM_DIR }} | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install -U pip | |
| python -m pip install pytz | |
| - name: Rebuild Dictionary from Upstream | |
| run: | | |
| UPSTREAM_TIME=$(git -C "$UPSTREAM_DIR" log -1 --format=%aI) | |
| python scripts/fetch_upstream.py "$UPSTREAM_DIR" "$UPSTREAM_TIME" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git config diff.notimestamp.textconv 'sed "/^version:/d"' | |
| echo "*.dict.yaml diff=notimestamp" > .gitattributes | |
| git add "*.dict.yaml" | |
| if [ -n "$(git diff --cached)" ]; then # Push to GitHub if contents changed. Don't use `--name-only` because this flag prevents the actual content from being computed by the command specified by textconv (same for `git status`). | |
| UPSTREAM_SHA=$(git -C "$UPSTREAM_DIR" rev-parse HEAD) | |
| git commit -m "Update from upstream https://github.com/CanCLID/rime-cantonese-upstream/commit/$UPSTREAM_SHA" | |
| git push origin main | |
| fi |