feat(i18n): add auto update ci

This commit is contained in:
lawvs 2022-09-10 02:47:18 +08:00
parent e7ca1a7a25
commit 02be488271

View File

@ -0,0 +1,84 @@
name: Download Languages Resources
on:
schedule:
- cron: "0 0 * * 5" # At 00:00(UTC) on Friday.
workflow_dispatch:
# Cancels all previous workflow runs for pull requests that have not completed.
# See https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
# The concurrency group contains the workflow name and the branch name for
# pull requests or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
main:
strategy:
matrix:
node-version: [18]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 7
- name: Use Node.js ${{ matrix.node-version }}
# https://github.com/actions/setup-node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install node modules
run: pnpm install
- name: Sync Languages
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master'
working-directory: ./libs/datasource/i18n
run: pnpm run download-resources
env:
TOLGEE_API_KEY: ${{ secrets.TOLGEE_API_KEY }}
- name: Push Branch
id: push
run: |
git add libs/datasource/i18n
# Do not proceed if there are no file differences
COMMIT=$(git rev-parse --verify origin/$TARGET_BRANCH || echo HEAD)
FILES_CHANGED=$(git diff-index --name-only --cached $COMMIT | wc -l)
if [[ "$FILES_CHANGED" = "0" ]]; then
echo "No file changes detected."
echo "::set-output name=skipPR::true"
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git commit --message 'feat(i18n): new translations'
git remote set-url origin "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY"
git push --force origin HEAD:$TARGET_BRANCH
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
TARGET_BRANCH: bot/new-translations
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
# see https://github.com/repo-sync/pull-request
- name: Create Pull Request
if: steps.push.outputs.skipPR != 'true'
uses: repo-sync/pull-request@v2
with:
source_branch: 'bot/new-translations' # If blank, default: triggered branch
destination_branch: "develop"
pr_title: Update i18n (${{ steps.date.outputs.date }}) # Title of pull request
pr_label: 'data,bot' # Comma-separated list (no spaces)
github_token: ${{ secrets.GITHUB_TOKEN }}