Skip to content

Commit

Permalink
ci: use livecodes-ci github app
Browse files Browse the repository at this point in the history
  • Loading branch information
zyf722 committed Nov 1, 2024
1 parent 47a41e5 commit 007e761
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/i18n-update-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.merged && github.event.sender.login != 'github-actions[bot]' && !startsWith(github.head_ref, 'i18n/')
steps:
- 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
20 changes: 15 additions & 5 deletions .github/workflows/i18n-update-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ jobs:
skipReason: ${{ steps.fetch-pr.outputs.skipReason }}
newBranch: ${{ steps.fetch-pr.outputs.newBranch }}
branch: ${{ steps.fetch-pr.outputs.branch }}
token: ${{ steps.generate-token.outputs.token }}

steps:
- 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 @@ -50,7 +59,7 @@ jobs:
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 @@ -66,6 +75,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.precheck.outputs.newBranch }}
token: ${{ needs.precheck.outputs.token }}

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -88,8 +98,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 +114,7 @@ jobs:
- name: Create a new i18n PR, comment on source PR and reaction
uses: actions/github-script@v7
with:
github-token: ${{ needs.precheck.outputs.token }}
script: |
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.NEW_BRANCH}`;
Expand Down Expand Up @@ -168,8 +179,6 @@ jobs:
comment_id: ${{ github.event.comment.id }},
content: 'rocket'
});
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}
exception:
name: Exception
Expand All @@ -183,6 +192,7 @@ jobs:
- name: Create reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ needs.precheck.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
19 changes: 16 additions & 3 deletions .github/workflows/i18n-update-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ jobs:
skipReason: ${{ steps.fetch-pr.outputs.skipReason }}
newBranch: ${{ steps.fetch-pr.outputs.newBranch }}
branch: ${{ steps.fetch-pr.outputs.branch }}
token: ${{ steps.generate-token.outputs.token }}

steps:
- 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 Down Expand Up @@ -51,7 +60,7 @@ jobs:
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 @@ -65,6 +74,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
token: ${{ needs.precheck.outputs.token }}

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -84,8 +95,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 +114,7 @@ jobs:
- name: Create comment and reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ needs.precheck.outputs.token }}
script: |
const repoURL = context.payload.repository.html_url;
const branchURL = `${repoURL}/tree/${process.env.NEW_BRANCH}`;
Expand Down Expand Up @@ -143,6 +155,7 @@ jobs:
- name: Create comment and reaction on PR
uses: actions/github-script@v7
with:
github-token: ${{ needs.precheck.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
16 changes: 10 additions & 6 deletions .github/workflows/i18n-update-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- 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: |
Expand Down Expand Up @@ -56,8 +63,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 @@ -83,8 +90,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 @@ -109,6 +114,7 @@ jobs:
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 Expand Up @@ -159,5 +165,3 @@ jobs:
head: process.env.BRANCH,
base: '${{ github.event.repository.default_branch }}'
});
env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_PAT }}

0 comments on commit 007e761

Please sign in to comment.