Skip to content

Commit c2e2952

Browse files
committed
ci: port infrastructure improvements from xinyi-relay
1 parent 6953221 commit c2e2952

23 files changed

Lines changed: 197 additions & 236 deletions

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ permissions:
33
contents: read
44

55
concurrency:
6-
group: ci-${{ github.event.pull_request.number || github.ref }}
6+
group: ${{ github.workflow }}
77
cancel-in-progress: true
88

99
on:
1010
pull_request:
1111
push:
1212
branches:
1313
- beta
14-
- master
14+
workflow_dispatch:
1515

1616
jobs:
1717
build:
1818
runs-on: ubuntu-latest
1919
env:
2020
GRADLE_OPTS: -Dorg.gradle.warning.mode=all
2121
steps:
22-
- uses: actions/checkout@v6
22+
- uses: actions/checkout@v7
2323
with:
2424
submodules: recursive
2525
fetch-depth: 0

‎.github/workflows/dependabot-auto-merge.yml‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,10 @@ jobs:
3333
)
3434
)
3535
steps:
36-
- name: Checkout PR branch
37-
uses: actions/checkout@v6
38-
with:
39-
repository: ${{ github.event.pull_request.head.repo.full_name }}
40-
ref: ${{ github.event.pull_request.head.ref }}
41-
token: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || github.token }}
42-
submodules: recursive
43-
fetch-depth: 0
44-
45-
- name: Set up JDK 26
46-
uses: actions/setup-java@v5
47-
with:
48-
distribution: temurin
49-
java-version: "26"
50-
51-
- name: Setup Gradle
52-
uses: gradle/actions/setup-gradle@v6
53-
with:
54-
validate-wrappers: false
55-
allow-snapshot-wrappers: true
56-
5736
- name: Enable auto-merge for dependency PRs
5837
env:
5938
PR_URL: ${{github.event.pull_request.html_url}}
60-
GH_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
39+
GH_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || github.token }}
6140
run: |
6241
set -euo pipefail
6342
test -n "$GH_TOKEN"

‎.github/workflows/dependency-force-manager.yml‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ permissions:
1010
pull-requests: write
1111
security-events: read
1212

13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
15+
1316
jobs:
1417
dependency-force:
1518
name: Attempt dependency remediation
@@ -24,7 +27,7 @@ jobs:
2427
DEPENDENCY_FORCE_HISTORICAL_ALERT_COOLDOWN_HOURS: 168
2528
steps:
2629
- name: Checkout
27-
uses: actions/checkout@v6
30+
uses: actions/checkout@v7
2831
with:
2932
ref: beta
3033
submodules: recursive
@@ -46,14 +49,14 @@ jobs:
4649
- name: Read current forced dependencies
4750
id: forced
4851
run: |
49-
python3 scripts/manage_dependency_forces.py read-forces \
52+
python3 scripts/security/manage_dependency_forces.py read-forces \
5053
--build-file build.gradle.kts \
5154
--toml-file gradle/libs.versions.toml \
5255
--output /tmp/forced.json
5356
5457
- name: Temporarily remove all force rules
5558
run: |
56-
python3 scripts/manage_dependency_forces.py strip-force-lines --build-file build.gradle.kts
59+
python3 scripts/security/manage_dependency_forces.py strip-force-lines --build-file build.gradle.kts
5760
5861
- name: Resolve natural versions (multi-variant)
5962
run: |
@@ -62,7 +65,7 @@ jobs:
6265
for config in "${configs[@]}"; do
6366
args+=(--config "$config")
6467
done
65-
python3 scripts/manage_dependency_forces.py resolve-natural \
68+
python3 scripts/security/manage_dependency_forces.py resolve-natural \
6669
--project "$DEPENDENCY_FORCE_PROJECT" \
6770
--forced-json /tmp/forced.json \
6871
--output /tmp/natural.json \
@@ -91,7 +94,7 @@ jobs:
9194
env:
9295
GH_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || github.token }}
9396
run: |
94-
python3 scripts/manage_dependency_forces.py determine-removable \
97+
python3 scripts/security/manage_dependency_forces.py determine-removable \
9598
--forced-json /tmp/forced.json \
9699
--natural-json /tmp/natural.json \
97100
--alerts-json /tmp/dependabot-alerts.json \
@@ -112,7 +115,7 @@ jobs:
112115
for config in "${configs[@]}"; do
113116
args+=(--config "$config")
114117
done
115-
python3 scripts/manage_dependency_forces.py resolve-alert-natural \
118+
python3 scripts/security/manage_dependency_forces.py resolve-alert-natural \
116119
--project "$DEPENDENCY_FORCE_PROJECT" \
117120
--alerts-json /tmp/dependabot-alerts.json \
118121
--output /tmp/security-natural.json \
@@ -121,7 +124,7 @@ jobs:
121124
- name: Apply updates (remove + add security forces)
122125
id: apply
123126
run: |
124-
python3 scripts/manage_dependency_forces.py apply-updates \
127+
python3 scripts/security/manage_dependency_forces.py apply-updates \
125128
--build-file build.gradle.kts \
126129
--toml-file gradle/libs.versions.toml \
127130
--removable-json /tmp/removable.json \

‎.github/workflows/dependency-janitor.yml‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ permissions:
1111
security-events: read
1212
checks: read
1313

14+
concurrency:
15+
group: ${{ github.workflow }}
16+
cancel-in-progress: true
17+
1418
jobs:
1519
janitor:
1620
name: Automated Security Dependency Fixes
1721
runs-on: ubuntu-latest
1822
if: github.ref_name == github.event.repository.default_branch
1923
steps:
20-
- uses: actions/checkout@v6
24+
- uses: actions/checkout@v7
2125
with:
2226
fetch-depth: 0
2327
submodules: recursive
@@ -34,16 +38,16 @@ jobs:
3438
GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
3539
GITHUB_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
3640
run: |
37-
chmod +x scripts/janitor_security_fixes.sh
38-
scripts/janitor_security_fixes.sh
41+
chmod +x scripts/security/janitor_security_fixes.sh
42+
scripts/security/janitor_security_fixes.sh
3943
4044
- name: Report alert coverage (no auto-dismiss)
4145
env:
4246
GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
4347
GITHUB_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
4448
run: |
45-
chmod +x scripts/reconcile_dependabot_alerts.sh
46-
scripts/reconcile_dependabot_alerts.sh
49+
chmod +x scripts/security/reconcile_dependabot_alerts.sh
50+
scripts/security/reconcile_dependabot_alerts.sh
4751
4852
- name: Create janitor PR if changed
4953
uses: peter-evans/create-pull-request@v8

‎.github/workflows/dependency-submission.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ jobs:
1212
permissions:
1313
contents: write
1414
security-events: read
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
1517

1618
steps:
17-
- uses: actions/checkout@v6
19+
- uses: actions/checkout@v7
1820
with:
1921
submodules: recursive
2022

@@ -38,10 +40,10 @@ jobs:
3840
GH_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || github.token }}
3941
GITHUB_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || github.token }}
4042
run: |
41-
chmod +x scripts/validate_dependabot_graph.sh
43+
chmod +x scripts/security/validate_dependabot_graph.sh
4244
snapshot="${{ steps.dependency-graph.outputs.dependency-graph-file }}"
4345
test -n "${snapshot}"
44-
scripts/validate_dependabot_graph.sh --snapshot "${snapshot}"
46+
scripts/security/validate_dependabot_graph.sh --snapshot "${snapshot}"
4547
4648
- name: Submit Dependency Graph
4749
env:

‎.github/workflows/detekt-autofix.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ permissions:
99
contents: write
1010
pull-requests: write
1111

12+
env:
13+
GITHUB_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
14+
15+
concurrency:
16+
group: ${{ github.workflow }}
17+
cancel-in-progress: true
1218

1319
jobs:
1420
autofix:
1521
runs-on: ubuntu-latest
1622
steps:
17-
- uses: actions/checkout@v6
23+
- uses: actions/checkout@v7
1824
with:
1925
submodules: recursive
2026
fetch-depth: 0

‎.github/workflows/detekt.yml‎

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
# This workflow performs a static analysis of your Kotlin source code using
7-
# Detekt.
8-
#
9-
# Scans are triggered:
10-
# 1. On every push to default and protected branches
11-
# 2. On every Pull Request targeting the default branch
12-
# 3. On a weekly schedule
13-
# 4. Manually, on demand, via the "workflow_dispatch" event
14-
#
15-
# The workflow should work with no modifications, but you might like to use a
16-
# later version of the Detekt CLI by modifying the $DETEKT_RELEASE_TAG
17-
# environment variable.
181
name: Scan with Detekt
192

203
on:
21-
# Triggers the workflow on push or pull request events but only for default and protected branches
224
push:
235
branches: [ "beta" ]
246
pull_request:
257
branches: [ "beta" ]
268
schedule:
279
- cron: '0 0 * * *'
28-
29-
# Allows you to run this workflow manually from the Actions tab
3010
workflow_dispatch:
3111

12+
permissions:
13+
security-events: write
14+
contents: read
15+
16+
concurrency:
17+
group: ${{ github.workflow }}
18+
cancel-in-progress: true
19+
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
22+
3223
jobs:
3324
scan:
3425
name: Scan
3526
runs-on: ubuntu-latest
36-
permissions:
37-
security-events: write
38-
contents: read
27+
if: github.actor != 'dependabot[bot]'
3928

4029
steps:
41-
- uses: actions/checkout@v6
30+
- uses: actions/checkout@v7
4231
with:
4332
submodules: recursive
4433
fetch-depth: 0
@@ -59,50 +48,45 @@ jobs:
5948
continue-on-error: true
6049
run: ./gradlew detekt --continue
6150

62-
- name: Check reports existence
63-
id: check
64-
if: always()
65-
run: |
66-
if [ -f app/build/reports/detekt/detekt.sarif ]; then echo "app=true" >> $GITHUB_OUTPUT; fi
67-
if [ -f core/build/reports/detekt/detekt.sarif ]; then echo "core=true" >> $GITHUB_OUTPUT; fi
68-
if [ -f runtime/build/reports/detekt/detekt.sarif ]; then echo "runtime=true" >> $GITHUB_OUTPUT; fi
69-
7051
- name: Merge SARIF files
52+
id: merge_sarif
7153
if: always()
7254
run: |
7355
mkdir -p merged-sarif
74-
# Merge all available SARIF files into one. If app SARIF is missing, use a fallback or skip gracefully.
75-
if [ ! -f app/build/reports/detekt/detekt.sarif ] && [ ! -f runtime/build/reports/detekt/detekt.sarif ] && [ ! -f core/build/reports/detekt/detekt.sarif ]; then
76-
echo "No Detekt SARIF reports found to merge."
56+
mapfile -t sarif_files < <(find . -path '*/build/reports/detekt/detekt.sarif' -type f | sort)
57+
if (( ${#sarif_files[@]} == 0 )); then
58+
echo "No SARIF files found"
59+
echo "exists=false" >> "$GITHUB_OUTPUT"
7760
exit 0
7861
fi
7962
80-
jq -s '
81-
if length == 0 then empty else
82-
{
83-
"$schema": .[0]."$schema",
84-
"version": .[0].version,
85-
"runs": [
86-
{
87-
"tool": .[0].runs[0].tool,
88-
"results": ([.[].runs[].results] | add)
89-
}
90-
]
91-
}
92-
end
93-
' $([ -f app/build/reports/detekt/detekt.sarif ] && echo "app/build/reports/detekt/detekt.sarif") \
94-
$([ -f runtime/build/reports/detekt/detekt.sarif ] && echo "runtime/build/reports/detekt/detekt.sarif") \
95-
$([ -f core/build/reports/detekt/detekt.sarif ] && echo "core/build/reports/detekt/detekt.sarif") \
96-
> merged-sarif/detekt.sarif 2>/dev/null || {
97-
# Fallback if jq fails or files are missing
98-
[ -f app/build/reports/detekt/detekt.sarif ] && cp app/build/reports/detekt/detekt.sarif merged-sarif/detekt.sarif || \
99-
[ -f runtime/build/reports/detekt/detekt.sarif ] && cp runtime/build/reports/detekt/detekt.sarif merged-sarif/detekt.sarif || \
100-
[ -f core/build/reports/detekt/detekt.sarif ] && cp core/build/reports/detekt/detekt.sarif merged-sarif/detekt.sarif
101-
}
63+
python3 - "${sarif_files[@]}" <<'PY'
64+
import json
65+
import sys
66+
from pathlib import Path
67+
68+
inputs = [Path(path) for path in sys.argv[1:]]
69+
merged = None
70+
merged_runs = []
71+
72+
for path in inputs:
73+
data = json.loads(path.read_text())
74+
if merged is None:
75+
merged = data
76+
merged["runs"] = []
77+
merged_runs.extend(data.get("runs") or [])
78+
79+
if merged is None:
80+
raise SystemExit("No SARIF inputs")
81+
82+
merged["runs"] = merged_runs
83+
Path("merged-sarif/detekt.sarif").write_text(json.dumps(merged))
84+
PY
85+
echo "exists=true" >> "$GITHUB_OUTPUT"
10286
10387
- name: Upload merged SARIF results
10488
uses: github/codeql-action/upload-sarif@v4
105-
if: always()
89+
if: always() && steps.merge_sarif.outputs.exists == 'true'
10690
continue-on-error: true
10791
with:
10892
sarif_file: merged-sarif/detekt.sarif

‎.github/workflows/legacy-ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
env:
2121
GRADLE_OPTS: -Dorg.gradle.warning.mode=all
2222
steps:
23-
- uses: actions/checkout@v6
23+
- uses: actions/checkout@v7
2424
with:
2525
submodules: recursive
2626
fetch-depth: 0

‎.github/workflows/notification.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
workflow_run:
55
types: [completed]
66
workflows: [CI, Release]
7+
release:
8+
types: [published]
79
workflow_dispatch:
810

911
jobs:
@@ -13,9 +15,9 @@ jobs:
1315
actions: read
1416
contents: read
1517
steps:
16-
- uses: actions/checkout@v6
18+
- uses: actions/checkout@v7
1719
with:
18-
ref: ${{ github.event.workflow_run.head_sha || github.ref }}
20+
submodules: recursive
1921
fetch-depth: 0
2022

2123
- name: Download artifacts

0 commit comments

Comments
 (0)