Commit Based
Every time there is a commit on a particular branch, translate it.
Workflow Settings Overview
gpt-translate-commit.yml
name: GPT Translate per Commit
on:
push:
branches:
- main
jobs:
gpt_translate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository with two latest commits
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: get changed files name
id: changed_files
run: |
echo "files=$(git diff --name-only HEAD^ HEAD | grep '\.md$' | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Run GPT Translate
uses: 3ru/gpt-translate@master
with:
apikey: ${{ secrets.OPENAI_API_KEY }}
inputFiles: ${{ steps.changed_files.outputs.files }}
outputFiles: 'JA/**/*.md FR/**/*.md'
languages: 'Japanese French'
Explanation
on:
push:
branches:
- main
It is invoked whenever there is a commit on the main
branch.
steps:
- name: Checkout repository with two latest commits
uses: actions/checkout@v3
with:
fetch-depth: 2
Check out the two most recent commits (HEAD and the one before it).
By comparing the latest commit with the one before it, we can get the diff files.
- name: get changed files name
id: changed_files
run: |
echo "files=$(git diff --name-only HEAD^ HEAD | grep '\.md$' | tr '\n' ' ')" >> $GITHUB_OUTPUT
id: changed_files
- Set id (
changed_files
) to refer to it from other steps.
- Set id (
git diff --name-only HEAD^ HEAD | grep '\.md$'
- Only markdown files are extracted from the diff files by the command in
run
.
- Only markdown files are extracted from the diff files by the command in
tr '\n' ' '
- The files are then converted to a space-delimited format.
>> $GITHUB_OUTPUT
- Setting output parameters.
- name: Run GPT Translate
uses: 3ru/gpt-translate@master
with:
apikey: ${{ secrets.OPENAI_API_KEY }}
inputFiles: ${{ steps.changed_files.outputs.files }}
outputFiles: 'JA/**/*.md FR/**/*.md'
languages: 'Japanese French'
inputFiles
- Pass the file path value for the file to be translated that was output in the previous step.
outputFiles
- Specify two directories,
JA
andFR
, as output destinations.
- Specify two directories,
languages
- Specify translation into
Japanese
andFrench
. It is important that the order matches the order of theoutputFiles
.
- Specify translation into