-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 2.51 KB
/
codeql-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Code analysis
on:
push:
branches:
- develop
pull_request:
branches-ignore:
- master
workflow_dispatch:
jobs:
format-and-lint:
name: Format code
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache SBT
uses: actions/cache@v3
with:
path: |
~/.ivy2/cache
~/.sbt
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }}
- name: Setup JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Setup Scala and SBT
uses: olafurpg/setup-scala@v14
with:
java-version: '8'
- name: Check and format code with Scalafmt
run: sbt scalafmtAll
- name: Check and fix code with Scalafix
run: sbt scalafixAll
- name: Check for changes and commit
id: git-check
run: |
if [ -n "$(git status --porcelain | grep -v '^??')" ]; then
echo "changes=true" >> $GITHUB_ENV # Use environment file to set output
git config --global user.name 'GitHub Actions Bot'
git config --global user.email '[email protected]'
git add -u
git commit -m "Apply code quality checks (auto-formatted)"
git fetch --prune
git pull --rebase origin ${{ github.head_ref }}
git push origin HEAD:${{ github.head_ref }}
else
echo "No changes to commit."
fi
env:
CI: true
- name: Post retry comment
if: env.changes == 'true'
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request ? context.payload.pull_request.number : null;
if (prNumber) {
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const newBody = pr.body + '\n\nAuto-commit applied. A retry was triggered due to a failure in formatting/linting checks.';
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: newBody
});
} else {
console.log('No pull request context found, unable to update PR description.');
}