Skip to content

Commit 35d0f4b

Browse files
committed
chore(ci): add linting
1 parent 49a40a4 commit 35d0f4b

File tree

10 files changed

+195
-13
lines changed

10 files changed

+195
-13
lines changed

.github/actionlint.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
self-hosted-runner:
3+
labels:
4+
- blacksmith-2vcpu-ubuntu-2204
5+
6+
paths:
7+
.github/workflows/lifecycle.yml:
8+
ignore:
9+
- '.+ is not defined in object type .+'

.github/workflows/flex-build.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
# checkov:skip=CKV_GHA_1:FIXME
23
name: Flex Build
34

45
"on":
@@ -63,7 +64,7 @@ jobs:
6364

6465
- if: |
6566
steps.cache.outputs.cache-hit != 'true'
66-
&& !inputs.release
67+
&& !inputs.publish
6768
name: Gradle build
6869
run: >
6970
./gradlew build --stacktrace
@@ -72,7 +73,7 @@ jobs:
7273
-Pneoforge_version=${{ inputs.neo }}
7374
working-directory: ${{ inputs.dir }}
7475
75-
- if: inputs.release
76+
- if: inputs.publish
7677
name: Gradle publish
7778
env:
7879
IS_MAVEN_PUB: true

.github/workflows/lifecycle.yml

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
# checkov:skip=CKV_GHA_1:FIXME
23
name: Lifecycle
34

45
"on":
@@ -13,6 +14,7 @@ name: Lifecycle
1314
- reopened
1415
workflow_dispatch:
1516
inputs:
17+
# checkov:skip=CKV_GHA_7:These inputs are used to construct the build matrix
1618
dirs:
1719
description: Comma-delimited directories to build and run (i.e. api,1_20,1_21 )
1820
default: "all"
@@ -29,6 +31,7 @@ concurrency: # FIXME: prevent release commit cancellation
2931

3032
jobs:
3133
release-please:
34+
if: github.event.action != 'closed'
3235
name: Release Please
3336
runs-on: blacksmith-2vcpu-ubuntu-2204
3437
outputs:
@@ -45,9 +48,109 @@ jobs:
4548
with:
4649
token: ${{ secrets.GITHUB_TOKEN }}
4750

51+
lint:
52+
name: Linters
53+
runs-on: blacksmith-2vcpu-ubuntu-2204
54+
# if: |
55+
# github.event.action != 'closed'
56+
# && !contains(github.actor, 'darcusk')
57+
env:
58+
APPLY_FIXES: all
59+
APPLY_FIXES_EVENT: all
60+
APPLY_FIXES_MODE: commit
61+
outputs:
62+
changes_detected: ${{ steps.autocommit.outputs.changes_detected }}
63+
commit_hash: ${{ steps.autocommit.outputs.commit_hash }}
64+
permissions:
65+
contents: write
66+
issues: write
67+
pull-requests: write
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v4
71+
with:
72+
fetch-depth: 1
73+
ref: ${{ github.head_ref }}
74+
75+
- name: Paths filter
76+
uses: dorny/paths-filter@v3.0.2
77+
id: filter
78+
with:
79+
list-files: shell
80+
filters: |
81+
addedOrModified:
82+
- added|modified: '**'
83+
84+
- name: Setup Python
85+
uses: useblacksmith/setup-python@v6
86+
with:
87+
python-version: "3.12"
88+
89+
- name: Cache pre-commit
90+
uses: useblacksmith/cache@v5
91+
with:
92+
path: ~/.cache/pre-commit
93+
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
94+
95+
- name: Install pre-commit
96+
shell: bash
97+
run: |
98+
python -m pip install pre-commit==4.0.1
99+
python -m pip freeze --local
100+
101+
- name: Run pre-commit
102+
id: precommit
103+
shell: bash
104+
run: |
105+
# Run against changes if addedOrModified is true, else run against all files
106+
if [[ "${{ steps.filter.outputs.addedOrModified }}" == "true" ]]; then
107+
pre-commit run --show-diff-on-failure --color=always --files "${{ steps.filter.outputs.addedOrModified_files }}" || RETRY="changes"
108+
else
109+
pre-commit run --show-diff-on-failure --color=always --all-files || RETRY="allfiles"
110+
fi
111+
112+
# Retry logic
113+
if [[ "$RETRY" == "changes" ]]; then
114+
pre-commit run --show-diff-on-failure --color=always --files "${{ steps.filter.outputs.addedOrModified_files }}"
115+
elif [[ "$RETRY" == "allfiles" ]]; then
116+
pre-commit run --show-diff-on-failure --color=always --all-files
117+
fi
118+
119+
- name: Run Mega-Linter
120+
if: ${{ !cancelled() }}
121+
uses: oxsecurity/megalinter/flavors/java@v8.3.0
122+
123+
- name: Archive production artifacts
124+
if: ${{ !cancelled() }}
125+
uses: actions/upload-artifact@v4
126+
with:
127+
name: Mega-Linter reports
128+
path: |
129+
megalinter-reports
130+
mega-linter.log
131+
132+
- name: Add reports directory to gitignore
133+
if: ${{ !cancelled() }}
134+
run: |
135+
touch .gitignore; grep -qxF 'megalinter-reports/' .gitignore ||
136+
echo 'megalinter-reports/' >> .gitignore
137+
wget https://raw.githubusercontent.com/packwiz/packwiz/refs/heads/main/go.sum
138+
139+
- name: Prepare commit
140+
if: ${{ !cancelled() }}
141+
run: sudo chown -Rc $UID .git/
142+
143+
- name: Commit and push applied linter fixes
144+
id: autocommit
145+
if: ${{ !cancelled() }}
146+
uses: stefanzweifel/git-auto-commit-action@v5.0.1
147+
with:
148+
branch: ${{ github.head_ref }}
149+
commit_message: "chore: apply linter fixes"
150+
48151
matrices:
49-
if: github.event.action != 'closed'
50152
name: Construct matrices
153+
if: github.job == 'notajob'
51154
needs: release-please
52155
runs-on: blacksmith-2vcpu-ubuntu-2204
53156
outputs:

.github/workflows/publish-api.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
# checkov:skip=CKV_GHA_1:FIXME
23
name: Publish API
34

45
"on":

.github/workflows/run-gametests.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
2+
# checkov:skip=CKV_GHA_1:FIXME
23
name: Run gametests
34

4-
"on":
5+
on:
56
workflow_dispatch: # TODO: add relevant inputs
67

78
jobs: # TODO: add cleanup job
@@ -10,8 +11,16 @@ jobs: # TODO: add cleanup job
1011
strategy:
1112
matrix:
1213
include:
13-
- { dir: gametest, mc: 1.20.4, lex: 49.0.38, neo: 219, java: 17 }
14-
- { dir: 1_20, mc: 1.20.4, lex: 49.0.38, neo: 219, java: 17 }
14+
- dir: gametest
15+
mc: 1.20.4
16+
lex: 49.0.38
17+
neo: 219
18+
java: 17
19+
- dir: 1_20
20+
mc: 1.20.4
21+
lex: 49.0.38
22+
neo: 219
23+
java: 17
1524
uses: ./.github/workflows/flex-build.yml
1625
with:
1726
dir: ${{ matrix.dir }}
@@ -36,9 +45,21 @@ jobs: # TODO: add cleanup job
3645
strategy:
3746
matrix:
3847
include:
39-
- { mc: 1.20.4, type: lexforge, modloader: forge, regex: .*forge.*, java: 17 }
40-
- { mc: 1.20.4, type: neoforge, modloader: neoforge, regex: .*neoforge.*, java: 17 }
41-
- { mc: 1.20.4, type: fabric, modloader: fabric, regex: .*fabric.*, java: 17 }
48+
- mc: 1.20.4
49+
type: lexforge
50+
modloader: forge
51+
regex: .*forge.*
52+
java: 17
53+
- mc: 1.20.4
54+
type: neoforge
55+
modloader: neoforge
56+
regex: .*neoforge.*
57+
java: 17
58+
- mc: 1.20.4
59+
type: fabric
60+
modloader: fabric
61+
regex: .*fabric.*
62+
java: 17
4263
runs-on: blacksmith-2vcpu-ubuntu-2204
4364
steps:
4465
- name: Download artifacts

.github/workflows/test-local-action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
2+
# checkov:skip=CKV_GHA_1:FIXME
23
name: Test local action
34

45
"on":
56
workflow_dispatch:
67
inputs:
8+
# checkov:skip=CKV_GHA_7:The is a test workflow
79
ref:
810
description: Git ref to checkout before build (i.e. my-feature-branch )
911
default: "main"

.mega-linter.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
DEFAULT_BRANCH: main
3+
JSON_PRETTIER_FILTER_REGEX_EXCLUDE: ".release-please-manifest.json"
4+
MARKDOWN_FILTER_REGEX_EXCLUDE: "CHANGELOG.md"
5+
VALIDATE_ALL_CODEBASE: false
6+
DISABLE:
7+
- COPYPASTE
8+
- SPELL
9+
FILEIO_REPORTER: false
10+
FLAVOR_SUGGESTIONS: false
11+
SHOW_ELAPSED_TIME: true
12+
APPLY_FIXES: all

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
# See https://pre-commit.com for more information
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: fix-byte-order-marker
10+
- id: mixed-line-ending
11+
- id: check-merge-conflict
12+
- id: check-case-conflict
13+
- id: check-executables-have-shebangs
14+
- id: check-shebang-scripts-are-executable
15+
- id: check-symlinks
16+
- id: check-json
17+
- id: check-toml
18+
- id: check-vcs-permalinks
19+
- id: check-yaml
20+
- repo: https://github.com/Lucas-C/pre-commit-hooks
21+
rev: v1.5.5
22+
hooks:
23+
- id: remove-crlf
24+
- id: remove-tabs
25+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
26+
rev: v2.14.0
27+
hooks:
28+
- id: pretty-format-java
29+
args: [--autofix]
30+
- id: pretty-format-kotlin
31+
args: [--autofix]
32+
- id: pretty-format-toml
33+
args: [--autofix]

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![CodeFactor](https://www.codefactor.io/repository/github/headlesshq/mc-runtime-test/badge/main)](https://www.codefactor.io/repository/github/headlesshq/mc-runtime-test/overview/main)
88
[![GitHub All Releases](https://img.shields.io/github/downloads/headlesshq/mc-runtime-test/total.svg)](https://github.com/headlesshq/mc-runtime-test/releases)
9-
![](https://github.com/headlesshq/mc-runtime-test/actions/workflows/run-matrix.yml/badge.svg)
9+
![Lifecycle](https://github.com/headlesshq/mc-runtime-test/actions/workflows/lifecycle.yml/badge.svg)
1010
![GitHub](https://img.shields.io/github/license/headlesshq/mc-runtime-test)
1111
![Github last-commit](https://img.shields.io/github/last-commit/headlesshq/mc-runtime-test)
1212

@@ -86,12 +86,11 @@ jobs:
8686
java: ${{ env.java_version }}
8787
```
8888
<!-- x-release-please-end -->
89-
An example workflow in action can be found
90-
[here](https://github.com/3arthqu4ke/hmc-optimizations/blob/1.20.4/.github/workflows/run-fabric.yml).
89+
9190
An example for a large matrix workflow
9291
which tests 20 different versions of Minecraft
9392
at once can be found
94-
[here](https://github.com/3arthqu4ke/hmc-specifics/blob/main/.github/workflows/run-matrix.yml).
93+
[here](https://github.com/3arthqu4ke/hmc-optimizations/blob/1592865073edf99c76184d7832f0f498c1299c7a/.github/workflows/run-matrix.yml).
9594
9695
# Inputs
9796
- `mc`: The MC version to use, e.g. `1.20.4`.

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: MC-Runtime-Test
23
description: Runs the MC client inside your CI
34
author: HeadlessHQ

0 commit comments

Comments
 (0)