Skip to content

Commit d6b7fde

Browse files
maxprilutskiymainstar123
authored andcommitted
feat: pr flag for gha
1 parent 3f1912e commit d6b7fde

18 files changed

Lines changed: 248 additions & 60 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
jobs:
1010
check:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
1215
steps:
1316
- name: Checkout
1417
uses: actions/checkout@v4
@@ -38,6 +41,16 @@ jobs:
3841
restore-keys: |
3942
${{ runner.os }}-pnpm-store-
4043
44+
- name: Replexica
45+
uses: ./
46+
with:
47+
api-key: ${{ secrets.REPLEXICA_API_KEY }}
48+
pull-request: true
49+
pull_request_assignees: maxprilutskiy,vrcprl
50+
pull_request_labels: i18n
51+
env:
52+
GH_TOKEN: ${{ github.token }}
53+
4154
- name: Install deps
4255
run: pnpm install
4356

.github/workflows/release.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ on:
66
branches:
77
- main
88

9-
permissions:
10-
contents: write
11-
pull-requests: write
12-
139
jobs:
1410
release:
1511
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
1615
steps:
1716
- name: Checkout
1817
uses: actions/checkout@v4
@@ -42,12 +41,15 @@ jobs:
4241
- name: Install deps
4342
run: pnpm install
4443

45-
# use action from current repo
4644
- name: Replexica
4745
uses: ./
4846
with:
4947
api-key: ${{ secrets.REPLEXICA_API_KEY }}
50-
version: 0.38
48+
pull-request: true
49+
pull_request_assignees: maxprilutskiy,vrcprl
50+
pull_request_labels: i18n
51+
env:
52+
GH_TOKEN: ${{ github.token }}
5153

5254
- name: Setup
5355
run: |

action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,36 @@ inputs:
1111
description: Version of the Replexica CLI
1212
required: false
1313
default: 'latest'
14+
commit-message:
15+
description: 'Commit message for the changes'
16+
required: false
17+
default: 'feat: update translations'
18+
pull-request:
19+
description: 'Create a pull request with the changes'
20+
required: false
21+
default: 'false'
22+
pull-request-title:
23+
description: 'Title of the pull request'
24+
required: false
25+
default: 'feat: update translations'
26+
pull_request_assignees:
27+
description: List of PR assignees (comma separated)
28+
required: false
29+
pull_request_labels:
30+
description: List of PR labels (comma separated)
31+
required: false
1432

1533
runs:
1634
using: 'docker'
1735
image: 'action/Dockerfile'
1836
env:
1937
REPLEXICA_API_KEY: ${{ inputs.api-key }}
2038
REPLEXICA_VERSION: ${{ inputs.version }}
39+
REPLEXICA_COMMIT_MESSAGE: ${{ inputs.commit-message }}
40+
REPLEXICA_PULL_REQUEST: ${{ inputs.pull-request }}
41+
REPLEXICA_PULL_REQUEST_TITLE: ${{ inputs.pull-request-title }}
42+
REPLEXICA_PULL_REQUEST_ASSIGNEES: ${{ inputs.pull_request_assignees }}
43+
REPLEXICA_PULL_REQUEST_LABELS: ${{ inputs.pull_request_labels }}
2144

2245
branding:
2346
icon: './content/logo.png'

action/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Container image that runs your code
22
FROM node:20-alpine
33

4-
# Install git
5-
RUN apk add --no-cache git
4+
# Install git and github-cli
5+
RUN apk add --no-cache git github-cli
66

77
# Copies your code file from your action repository to the filesystem path `/` of the container
88
COPY entrypoint.sh /entrypoint.sh
9+
COPY pr.md /pr.md
10+
11+
# Make entrypoint.sh executable
12+
RUN chmod +x /entrypoint.sh
913

1014
# Code file to execute when the docker container starts up (`entrypoint.sh`)
11-
ENTRYPOINT ["/entrypoint.sh"]
15+
ENTRYPOINT ["/entrypoint.sh"]

action/entrypoint.sh

Lines changed: 162 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,164 @@
11
#!/bin/sh -l
22

3-
# Run Replexica CLI to localize missing strings
4-
# USe REPLEXICA_VERSION env variable to specify the version of Replexica CLI
5-
npx replexica@${REPLEXICA_VERSION} i18n
6-
# Return exit code 1 if the previous command fails
7-
if [ $? -eq 1 ]; then
8-
echo "::error::🚨 Replexica incurred an error while applying translations. Discord: https://replexica.com/go/discord"
9-
exit 1
10-
fi
11-
# Commit the changes into the current branch
12-
git config --global --add safe.directory $PWD
13-
git config --global user.name "Replexica"
14-
git config --global user.email "support@replexica.com"
15-
git add .
16-
if git diff --staged --quiet; then
17-
echo "::notice::Replexica has not found any missing translations"
18-
else
19-
git commit -m "feat: add missing translations"
20-
# Pull the latest changes from the remote repository
21-
git pull --rebase
22-
git push
23-
# retrieve the last commit hash
24-
COMMIT_HASH=$(git rev-parse HEAD)
25-
# build a github url to the commit
26-
COMMIT_URL="https://github.com/$GITHUB_REPOSITORY/commit/$COMMIT_HASH"
27-
# output the commit url to the github actions announcements using ::notice::
28-
echo "::notice::Replexica has just added missing translations and pushed them to the repo! The commit: $COMMIT_URL"
29-
fi
3+
set -e
4+
5+
# Function to run Replexica CLI
6+
run_replexica() {
7+
npx replexica@${REPLEXICA_VERSION} i18n
8+
if [ $? -eq 1 ]; then
9+
echo "::error::Replexica: Translation update failed. For assistance, join our Discord: https://replexica.com/go/discord"
10+
exit 1
11+
fi
12+
}
13+
14+
# Function to configure git
15+
configure_git() {
16+
git config --global --add safe.directory $PWD
17+
git config --global user.name "Replexica"
18+
git config --global user.email "support@replexica.com"
19+
}
20+
21+
# Function to get the current branch name
22+
get_current_branch() {
23+
local branch_name=""
24+
25+
if [ -n "$GITHUB_HEAD_REF" ]; then
26+
# Pull request
27+
branch_name="$GITHUB_HEAD_REF"
28+
elif [ -n "$GITHUB_REF_NAME" ]; then
29+
# Push or workflow_dispatch
30+
if echo "$GITHUB_REF" | grep -q "^refs/tags/"; then
31+
# It's a tag, return the default branch
32+
branch_name=$(gh api repos/:owner/:repo | jq -r .default_branch)
33+
else
34+
branch_name="$GITHUB_REF_NAME"
35+
fi
36+
elif [ -n "$GITHUB_REF" ]; then
37+
# Fallback for other cases
38+
branch_name=$(echo "$GITHUB_REF" | sed 's:^refs/[^/]*/::')
39+
else
40+
echo "::error::Replexica: Unable to determine the current branch name. For assistance, join our Discord: https://replexica.com/go/discord"
41+
exit 1
42+
fi
43+
44+
echo "$branch_name"
45+
}
46+
47+
# Function to commit changes
48+
commit_changes() {
49+
git add .
50+
if ! git diff --staged --quiet; then
51+
git commit -m "${REPLEXICA_COMMIT_MESSAGE}"
52+
echo "Changes committed successfully"
53+
return 0
54+
else
55+
echo "::notice::Replexica: All translations are up to date."
56+
return 1
57+
fi
58+
}
59+
60+
# Function to create or update PR
61+
create_or_update_pr() {
62+
local current_branch=$(get_current_branch)
63+
local pr_branch="replexica/${current_branch}"
64+
local pr_title="${REPLEXICA_PULL_REQUEST_TITLE}"
65+
66+
# Create or update the branch
67+
git checkout -B "$pr_branch"
68+
git push -f origin "$pr_branch"
69+
70+
# Check if PR already exists
71+
existing_pr=$(gh pr list --head "$pr_branch" --json number --jq '.[0].number')
72+
73+
# Read PR body from adjacent file called pr.md
74+
pr_body_file="/pr.md"
75+
76+
local pr_create_args="--title \"$pr_title\" --body-file \"$pr_body_file\" --head \"$pr_branch\""
77+
local pr_edit_args="--title \"$pr_title\" --body-file \"$pr_body_file\""
78+
79+
add_assignees_to_pr_args
80+
add_labels_to_pr_args "$existing_pr"
81+
82+
# Create new PR or update existing one
83+
if [ -n "$existing_pr" ]; then
84+
eval gh pr edit "$existing_pr" $pr_edit_args
85+
echo "::notice::Replexica: Updated existing PR #$existing_pr with translations. Review it here: https://github.com/$GITHUB_REPOSITORY/pull/$existing_pr"
86+
else
87+
new_pr=$(eval gh pr create $pr_create_args)
88+
echo "::notice::Replexica: Created new PR with translations. Review it here: $new_pr"
89+
fi
90+
}
91+
92+
# Function to add assignees to PR arguments
93+
add_assignees_to_pr_args() {
94+
if [ -n "$REPLEXICA_PULL_REQUEST_ASSIGNEES" ]; then
95+
OLD_IFS="$IFS"
96+
IFS=','
97+
for assignee in $REPLEXICA_PULL_REQUEST_ASSIGNEES; do
98+
pr_create_args="$pr_create_args --assignee \"$assignee\""
99+
pr_edit_args="$pr_edit_args --add-assignee \"$assignee\""
100+
done
101+
IFS="$OLD_IFS"
102+
fi
103+
}
104+
105+
# Function to add labels to PR arguments
106+
add_labels_to_pr_args() {
107+
local existing_pr="$1"
108+
if [ -n "$REPLEXICA_PULL_REQUEST_LABELS" ]; then
109+
OLD_IFS="$IFS"
110+
IFS=','
111+
for label in $REPLEXICA_PULL_REQUEST_LABELS; do
112+
# Check if label exists in the repository
113+
if ! gh label list | grep -q "^$label "; then
114+
# Create label if it doesn't exist in the repository
115+
gh label create "$label" --color "#1ac964" || true > /dev/null
116+
fi
117+
118+
# For new PRs, add all labels
119+
if [ -z "$existing_pr" ]; then
120+
pr_create_args="$pr_create_args --label \"$label\""
121+
else
122+
# For existing PRs, check if the label is already present
123+
if ! gh pr view "$existing_pr" --json labels --jq '.labels[].name' | grep -q "^$label$"; then
124+
pr_edit_args="$pr_edit_args --add-label \"$label\""
125+
fi
126+
fi
127+
done
128+
IFS="$OLD_IFS"
129+
fi
130+
}
131+
132+
# Main execution
133+
main() {
134+
if [ "$REPLEXICA_PULL_REQUEST" = "true" ]; then
135+
if [ -z "$GH_TOKEN" ]; then
136+
echo "::error::Replexica: GitHub token is missing. Add 'GH_TOKEN: \${{ github.token }}' to your Replexica action configuration env section."
137+
exit 1
138+
fi
139+
fi
140+
141+
# Run Replexica to update translations
142+
run_replexica
143+
144+
# Configure git for committing changes
145+
configure_git
146+
147+
# Commit changes if any are found
148+
if commit_changes; then
149+
if [ "$REPLEXICA_PULL_REQUEST" = "true" ]; then
150+
# Create or update pull request
151+
create_or_update_pr
152+
else
153+
# Push changes directly to the repository
154+
git pull --rebase
155+
git push
156+
COMMIT_HASH=$(git rev-parse HEAD)
157+
COMMIT_URL="https://github.com/$GITHUB_REPOSITORY/commit/$COMMIT_HASH"
158+
echo "::notice::Replexica: Translation updates pushed successfully. View the commit: $COMMIT_URL"
159+
fi
160+
fi
161+
}
162+
163+
# Run the main function
164+
main

action/pr.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Hey team, [**Replexica AI**](https://replexica.com) here with fresh translations!
2+
3+
### What's New?
4+
5+
- Added missing translations
6+
- Improved localization coverage
7+
8+
### Next Steps
9+
10+
- [ ] Review the changes
11+
- [ ] Merge when ready

i18n.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ version: 1
22
checksums:
33
4188a166aad2705b4f09401f924502ed:
44
name: ef1fb56b8dafd605fb267df2b0a8a91f
5-
what-is-replexica: acc49247f34f287b6e11b48b61c454fd
5+
what-is-replexica: 91c8c28857f67df37fcdab9f493f9ba9
66
how-it-works: b6582d6a1c8615076c0b242fa1342a8b
77
why-not-use-google-translate: 3fb644a50bf390dcb82bbd26aae76110
8-
why-not-use-human-translators: 44a6f03f35e6e04bd7f0f5a81e590356
8+
why-not-use-human-translators: 12d33ca3a17fe0df29edea4c52ec688a
99
how-fast-can-i-translate-my-product: 4c2c6e8361b5fa621e457e4da23c0765
1010
is-replexica-expensive: 35f554291d9a341f1abfe33492198c4d
1111
how-soon-can-i-get-started: fac711e991d0684d7afbc9a341bbc048

i18n/ar.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "Replexica",
3-
"what-is-replexica": "Replexica هي تقنية ذكاء اصطناعي تمكّن فرق التطوير من شحن المنتجات متعددة اللغات أسرع بمئة مرة.",
3+
"what-is-replexica": "ريپليكسا - تقنية الذكاء الاصطناعي التي تمكن فرق التطوير من شحن المنتجات متعددة اللغات بسرعة أكبر بمئة مرة.",
44
"how-it-works": "Replexica تستخدم الذكاء الاصطناعي لترجمة منتجك تلقائيًا إلى لغات متعددة. تتكامل مع سير العمل والأدوات الحالية لديك، بحيث يمكنك شحن المنتجات متعددة اللغات دون أي جهد إضافي.",
55
"why-not-use-google-translate": "Google Translate رائع لترجمة الكلمات الفردية أو العبارات القصيرة، لكنه ليس مصممًا لترجمة المنتجات بالكامل. Replexica مصممة خصيصًا للمطورين وفرق المنتجات، لذا يمكنك الوثوق بأن الترجمات ستكون دقيقة وملائمة للسياق.",
6-
"why-not-use-human-translators": "المترجمون البشريون يعيقون تسليم المشاريع، وبصراحة – يكرهون ترجمة تسميات الأزرار في تطبيقك. Replexica سريعة، ميسورة التكلفة، ومصممة للمطورين وفرق المنتجات.",
6+
"why-not-use-human-translators": "المترجمون البشريون يعوقون تسليم المشاريع، ولنكن صادقين: هم يكرهون ترجمة تسميات الأزرار في تطبيقك. ريپليكسا سريعة، ميسورة التكلفة، ومصممة للمطورين وفرق المنتجات.",
77
"how-fast-can-i-translate-my-product": "ريپليكسا تترجم المنتجات إلى لغات متعددة في دقائق، مما يسمح للفرق بإطلاق منتجات متعددة اللغات أسرع بمئة مرة.",
88
"is-replexica-expensive": "ريپليكسا متاحة للفرق من جميع الأحجام: التسعير يعتمد على استخدامك للمنصة، ويتراوح من عدة مئات إلى عدة آلاف من الدولارات سنويًا.",
99
"how-soon-can-i-get-started": "يمكن لفريقك البدء مع ريپليكسا في أقل من ساعة. فقط اشترك وحدد موعدًا مع فريقنا.",

i18n/de.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "Replexica",
3-
"what-is-replexica": "Replexica ist eine KI-Technologie, die Entwicklerteams ermöglicht, mehrsprachige Produkte hundertmal schneller zu liefern.",
3+
"what-is-replexica": "Replexica - KI-Technologie, die Entwicklerteams ermöglicht, mehrsprachige Produkte hundertmal schneller zu liefern.",
44
"how-it-works": "Replexica nutzt KI, um dein Produkt automatisch in mehrere Sprachen zu übersetzen. Es integriert sich in deinen bestehenden Workflow und deine Tools, sodass du mehrsprachige Produkte ohne zusätzlichen Aufwand liefern kannst.",
55
"why-not-use-google-translate": "Google Translate ist super für einzelne Wörter oder kurze Sätze, aber nicht für ganze Produkte. Replexica ist speziell für Entwickler und Produktteams gebaut, damit du dich auf genaue und kontextuell relevante Übersetzungen verlassen kannst.",
6-
"why-not-use-human-translators": "Menschliche Übersetzer verzögern die Projektabwicklung und, mal ehrlich – sie hassen es, die Beschriftungen deiner App-Buttons zu übersetzen. Replexica ist schnell, erschwinglich und für Entwickler und Produktteams konzipiert.",
6+
"why-not-use-human-translators": "Menschliche Übersetzer verzögern die Projektabwicklung und, seien wir ehrlich: Sie hassen es, die Beschriftungen der Schaltflächen in Ihrer App zu übersetzen. Replexica ist schnell, kostengünstig und für Entwickler- und Produktteams konzipiert.",
77
"how-fast-can-i-translate-my-product": "Replexica lokalisiert Produkte in mehreren Sprachen in Minuten, sodass Teams x100 schneller mehrsprachige Produkte ausliefern können.",
88
"is-replexica-expensive": "Teams jeder Größe können sich Replexica leisten: Die Preise basieren auf der Nutzung der Plattform und variieren von mehreren hundert bis zu mehreren tausend Dollar pro Jahr.",
99
"how-soon-can-i-get-started": "Ihr Team kann Replexica in weniger als einer Stunde nutzen. Einfach anmelden und einen Termin mit unserem Team buchen.",

i18n/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "Replexica",
3-
"what-is-replexica": "Replexica is an AI technology that enables dev teams ship multilingual products x100 faster.",
3+
"what-is-replexica": "Replexica - AI technology that enables dev teams ship multilingual products x100 faster.",
44
"how-it-works": "Replexica uses AI to automatically translate your product into multiple languages. It integrates with your existing workflow and tools, so you can ship multilingual products without any extra effort.",
55
"why-not-use-google-translate": "Google Translate is great for translating individual words or short phrases, but it's not designed for translating entire products. Replexica is built specifically for developers and product teams, so you can trust that your translations will be accurate and contextually relevant.",
6-
"why-not-use-human-translators": "Human translators block project delivery, and let's be honest hate translating labels of the buttons in your app. Replexica is fast, affordable, and designed for developers and product teams.",
6+
"why-not-use-human-translators": "Human translators block project delivery, and let's be honest: they hate translating labels of the buttons in your app. Replexica is fast, affordable, and designed for developers and product teams.",
77
"how-fast-can-i-translate-my-product": "Replexica localizes products into multiple languages in minutes, so teams can ship multilingual products x100 faster.",
88
"is-replexica-expensive": "Teams of all sizes can afford Replexica: pricing is based on how much you use the platform, and varies from several hundred to several thousand dollars per year.",
99
"how-soon-can-i-get-started": "Your team can go live with Replexica in under an hour. Just sign up, and book a call with our team.",

0 commit comments

Comments
 (0)