Skip to content

Commit

Permalink
Merge pull request #644 from zyf722/i18next-integration-draft
Browse files Browse the repository at this point in the history
I18n Workflow Fixes, Improvements & Github App for CI Integration
  • Loading branch information
hatemhosny authored Nov 2, 2024
2 parents e08c415 + 68d8997 commit 2531fd4
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 41 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ jobs:
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Use Node.js
uses: actions/setup-node@v4
Expand All @@ -33,6 +40,6 @@ jobs:
- name: Deploy
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${{github.repository}}.git
npm run deploy -- -u "github-actions-bot <support+actions@github.com>"
npm run deploy -- -u "livecodes-ci[bot] <186997172+livecodes-ci[bot]@users.noreply.github.com>"
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
8 changes: 8 additions & 0 deletions .github/workflows/i18n-update-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.merged && github.event.sender.login != 'github-actions[bot]' && !startsWith(github.head_ref, 'i18n/')
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Create comment on PR
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const commentBody = `## i18n Actions
Source PR has been merged into the default branch.
Expand Down
35 changes: 32 additions & 3 deletions .github/workflows/i18n-update-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ jobs:
branch: ${{ steps.fetch-pr.outputs.branch }}

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}

- name: Fetch PR details
id: fetch-pr
Expand All @@ -46,11 +55,14 @@ jobs:
echo "newBranch=$NEW_BRANCH" >> $GITHUB_OUTPUT
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
if [[ ! $(git ls-remote --heads origin $NEW_BRANCH) ]]; then
skip "Branch \`$NEW_BRANCH\` does not exist."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

runner:
name: Runner
Expand All @@ -62,10 +74,18 @@ jobs:
PR_BRANCH: ${{ needs.precheck.outputs.branch }}

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ needs.precheck.outputs.newBranch }}
token: ${{ steps.generate-token.outputs.token }}

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -88,8 +108,8 @@ jobs:

- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
git add .
# Only commit if there are changes
Expand All @@ -104,6 +124,7 @@ jobs:
- name: Create a new i18n PR, comment on source PR and reaction
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.NEW_BRANCH}`;
Expand Down Expand Up @@ -178,9 +199,17 @@ jobs:
SKIP_REASON: ${{ needs.precheck.outputs.skipReason }}

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Create reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const runURL = `${context.payload.repository.html_url}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const commentBody = `## i18n Actions: \`.i18n-update-pull\`
Expand Down
36 changes: 33 additions & 3 deletions .github/workflows/i18n-update-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ jobs:
branch: ${{ steps.fetch-pr.outputs.branch }}

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}

- name: Fetch PR details
id: fetch-pr
Expand All @@ -44,14 +53,17 @@ jobs:
echo "newBranch=$NEW_BRANCH" >> $GITHUB_OUTPUT
echo "branch=$PR_BRANCH" >> $GITHUB_OUTPUT
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
if [[ $(git ls-remote --heads origin $NEW_BRANCH) ]]; then
SKIP_REASON="Branch \`$NEW_BRANCH\` already exists."
echo "$SKIP_REASON Exiting..."
echo "skip=true" >> $GITHUB_OUTPUT
echo "skipReason=$SKIP_REASON" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

runner:
name: Runner
Expand All @@ -63,8 +75,17 @@ jobs:
PR_BRANCH: ${{ needs.precheck.outputs.branch }}

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -84,8 +105,8 @@ jobs:

- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
git add .
# Only commit if there are changes
Expand All @@ -103,6 +124,7 @@ jobs:
- name: Create comment and reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.NEW_BRANCH}`;
Expand Down Expand Up @@ -140,9 +162,17 @@ jobs:
SKIP_REASON: ${{ needs.precheck.outputs.skipReason }}

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Create comment and reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const runURL = `${context.payload.repository.html_url}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const commentBody = `## i18n Actions: \`.i18n-update-push\`
Expand Down
44 changes: 27 additions & 17 deletions .github/workflows/i18n-update-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,24 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}

- name: Switch to i18n branch
run: |
git config --global user.name "livecodes-ci[bot]"
git config --global user.email "186997172+livecodes-ci[bot]@users.noreply.github.com"
if [[ $(git ls-remote --heads origin $BRANCH) ]]; then
git config pull.rebase false
git fetch origin $BRANCH:$BRANCH
Expand All @@ -51,26 +62,24 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Linting and fixing
run: npm run fix
# - name: Linting and fixing
# run: npm run fix

- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
# - name: Commit changes
# run: |
# git add .

# Only commit if there are changes
git diff-index --quiet HEAD || git commit -m "i18n: update source texts"
# # Only commit if there are changes
# git diff-index --quiet HEAD || git commit -m "i18n: update source texts"

# Save SHA of the latest commit to English locale
echo "LAST_COMMIT_SHA_PUSH=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV
# # Save SHA of the latest commit to English locale
# echo "LAST_COMMIT_SHA_PUSH=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV

- name: Push changes
run: git push origin $BRANCH
# - name: Push changes
# run: git push origin $BRANCH

- name: Push source texts to Lokalise
run: npm run i18n-update-push -- $LOKALISE_BRANCH
# - name: Push source texts to Lokalise
# run: npm run i18n-update-push -- $LOKALISE_BRANCH

- name: Import from Lokalise
run: |
Expand All @@ -83,8 +92,6 @@ jobs:

- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
# Only commit if there are changes
Expand All @@ -105,10 +112,13 @@ jobs:
echo "SKIP=true" >> $GITHUB_ENV
fi
echo "LAST_COMMIT_SHA_PUSH=$(git log -n 1 --format="%H" -- src/livecodes/i18n/locales/en)" >> $GITHUB_ENV
- name: Create a new i18n PR if not exists
uses: actions/github-script@v7
if: steps.check-diff.outputs.SKIP != 'true'
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const prInfo = await github.rest.pulls.list({
owner: context.repo.owner,
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ jobs:
runs-on: ubuntu-latest
if: contains(github.ref, 'refs/heads/releases/')
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Get version
id: vars
Expand All @@ -19,4 +26,4 @@ jobs:
- name: Create pull request to develop
run: gh pr create --title "Prepare release ${{steps.vars.outputs.version}}" --body "Prepare release ${{steps.vars.outputs.version}}" --base develop --head "${{github.ref_name}}"
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
15 changes: 11 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ jobs:
env:
NODE_OPTIONS: '--max_old_space_size=4096'
steps:
- name: Generate Github Token for CI Bot
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.CI_APP_ID }}
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Get version
id: vars
Expand Down Expand Up @@ -64,7 +71,7 @@ jobs:
files: |
livecodes-${{steps.vars.outputs.version}}.tar.gz
livecodes-${{steps.vars.outputs.version}}.zip
token: ${{ secrets.GH_ACTIONS_REPO_PAT }}
token: ${{ steps.generate-token.outputs.token }}

- name: Create permanent URL
if: startsWith(github.head_ref, 'releases/v')
Expand All @@ -88,10 +95,10 @@ jobs:
if: startsWith(github.head_ref, 'releases/v')
run: gh pr create --title "release ${{steps.vars.outputs.version}}" --body "https://${{steps.vars.outputs.version}}.livecodes.io" --base main --head develop
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_token: ${{ steps.generate-token.outputs.token }}

- name: Create pull request to main (SDK)
if: startsWith(github.head_ref, 'releases/sdk-v')
run: gh pr create --title "release ${{steps.vars.outputs.version}}" --body "https://www.npmjs.com/package/livecodes" --base main --head develop
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
GITHUB_token: ${{ steps.generate-token.outputs.token }}
Loading

0 comments on commit 2531fd4

Please sign in to comment.