Skip to content

Commit 6ccb10c

Browse files
committed
ci: check pr changes before running
1 parent 42d2cdf commit 6ccb10c

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

.github/workflows/code-analysis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ on:
1717

1818
permissions: {}
1919

20+
env:
21+
RUN_LINT: "yes"
22+
2023
jobs:
2124
build:
2225
runs-on: ubuntu-latest
23-
if: github.event_name != 'pull_request_review' || github.event.review.state == 'approved'
2426

2527
steps:
2628
- uses: actions/checkout@v4
@@ -39,7 +41,14 @@ jobs:
3941
- name: 🚧 Do prerequisites
4042
run: npm ci
4143

44+
- name: 🔎 Check pull request changes
45+
if: github.event_name == 'pull_request_target'
46+
run: |
47+
git fetch origin "${{ github.base_ref }}" --depth=1
48+
echo "RUN_LINT=$(npm run git:diff-files-yn 'origin/${{ github.base_ref }}' 'app/' 'i18n/' 'gradle/')" >> $GITHUB_ENV
49+
4250
- name: 🚨 Analyze code
51+
if: env.RUN_LINT == 'no'
4352
run: |
4453
npm run prebuild
4554
chmod +x ./gradlew

.github/workflows/i18n-summary.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ permissions:
1717
contents: write
1818
pull-requests: write
1919

20+
env:
21+
PR_COMMENT: "no"
22+
2023
jobs:
2124
i18n-summary:
2225
runs-on: ubuntu-latest
@@ -44,8 +47,14 @@ jobs:
4447
checkout-orphan: true
4548
force: true
4649

47-
- name: 💬 Comment summary
50+
- name: 🔎 Check pull request changes
4851
if: github.event_name == 'pull_request_target'
52+
run: |
53+
git fetch origin "${{ github.base_ref }}" --depth=1
54+
echo "PR_COMMENT=$(npm run git:diff-files-yn 'origin/${{ github.base_ref }}' '.phrasey/' 'i18n/')" >> $GITHUB_ENV
55+
56+
- name: 💬 Comment summary
57+
if: github.event_name == 'pull_request_target' && env.PR_COMMENT == 'yes'
4958
uses: actions/github-script@v7
5059
with:
5160
script: |

cli/git/diff-files-yn.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Git } from "../helpers/git";
2+
3+
const main = async () => {
4+
const [branch, ...pathPrefix] = process.argv.slice(2);
5+
if (!branch) throw new Error("Missing argument: tag");
6+
if (!pathPrefix.length) throw new Error("Missing argument: pathPrefix");
7+
const files = await Git.diffNames(branch);
8+
const affected = files.some((x) => affectsPathPrefix(pathPrefix, x));
9+
console.log(!affected ? "yes" : "no");
10+
};
11+
12+
main();
13+
14+
function affectsPathPrefix(pathPrefix: string[], file: string) {
15+
return pathPrefix.some((x) => file.startsWith(x));
16+
}

cli/helpers/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class Git {
3737
return proc.status === 0;
3838
}
3939

40-
static async diffNames(tag: string) {
41-
const proc = await Git.spawn(["diff", "--name-only", tag, "."]);
40+
static async diffNames(branch: string) {
41+
const proc = await Git.spawn(["diff", "--name-only", branch, "."]);
4242
if (proc.status !== 0) {
4343
throw new Error(`Unable to get diff (${proc.stderr})`);
4444
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"git:tag-exists": "tsx ./cli/git/tag-exists.ts",
1414
"git:tag-exists-yn": "tsx ./cli/git/tag-exists-yn.ts",
1515
"git:latest-tag": "tsx ./cli/git/latest-tag.ts",
16+
"git:diff-files-yn": "tsx ./cli/git/diff-files-yn.ts",
1617
"android:move-outputs": "tsx ./cli/android/move-outputs.ts",
1718
"prebuild": "npm run i18n:build",
1819
"postbuild": "npm run android:move-outputs",

0 commit comments

Comments
 (0)