-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (129 loc) · 5.22 KB
/
ci-maven-build.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Maven build java
on:
workflow_call:
inputs:
java-version:
description: Main version of java
default: "11"
required: false
type: string
setup-npm-auth:
description: Configure private NPM registry authentication
default: false
required: false
type: boolean
application-path:
default: "./"
required: false
type: string
jobs:
verify-pull-request-title:
if: ${{ github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # [email protected]
with:
script: |
const REGEX = new RegExp("^[^…]+$"); // Title must match this regex
const MIN_LENGTH = 10; // Min length of the title
const MAX_LENGTH = 100; // Max length of the title (-1 is no max)
const ALLOWED_PREFIXES = ['Bump','ID-','MIN-','PBLEID-','MP-','KRR-','PF-','AOS-','SP-','EIN-']; // Title must start with one of these prefixes
const PREFIX_CASE_SENSITIVE = false; // Whether the prefix is case sensitive
const validateTitlePrefix = (title, prefix) =>
PREFIX_CASE_SENSITIVE
? title.startsWith(prefix)
: title.toLowerCase().startsWith(prefix.toLowerCase());
const { title } = context.payload.pull_request;
if (!REGEX.test(title)) {
core.setFailed(
`Pull Request title "${title}" failed to match regex - ${REGEX}`
);
return;
}
if (title.length < MIN_LENGTH) {
core.setFailed(
`Pull Request title "${title}" is smaller than the minimum length - ${MIN_LENGTH}`
);
return;
}
if (MAX_LENGTH > 0 && title.length > MAX_LENGTH) {
core.setFailed(
`Pull Request title "${title}" is greater than the maximum length - ${MAX_LENGTH}`
);
return;
}
core.info(`Allowed Prefixes: ${ALLOWED_PREFIXES}`);
if (
ALLOWED_PREFIXES.length &&
!ALLOWED_PREFIXES.some((prefix) => validateTitlePrefix(title, prefix))
) {
core.setFailed(
`Pull Request title "${title}" did not start with any of the required prefixes - ${ALLOWED_PREFIXES}`
);
return;
}
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # [email protected]
- name: Check if YAML files exist
id: yaml-files-exists
run: |
if [ -f "${{ inputs.application-path }}src/main/resources/application*.y*ml" ]; then
echo "file-exists=true" >> "$GITHUB_OUTPUT"
echo "- \`${{ inputs.application-path }}src/main/resources/application*.y*ml\` file exists :white_check_mark:" >> "$GITHUB_STEP_SUMMARY"
else
echo "file-exists=false" >> "$GITHUB_OUTPUT"
{
echo "- \`${{ inputs.application-path }}src/main/resources/application*.y*ml\` file exists :x:"
echo " - Skipping yamllint"
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Run yamllint
if: steps.yaml-files-exists.outputs.file_exists == 'true'
uses: ibiqlik/action-yamllint@2576378a8e339169678f9939646ee3ee325e845c # [email protected]
with:
file_or_dir: ${{ inputs.application-path }}src/main/resources/application*.y*ml
config_data: |
extends: default
rules:
empty-lines: disable
line-length:
max: 150
level: warning
- name: Set up JDK ${{ inputs.java-version }}
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # [email protected]
with:
distribution: "liberica"
java-version: ${{ inputs.java-version }}
- name: Cache Maven packages
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # [email protected]
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- uses: s4u/maven-settings-action@7802f6aec16c9098b4798ad1f1d8ac75198194bd # [email protected]
with:
servers: |
[{
"id": "github-oidc-sdk",
"username": "${{ secrets.MAVEN_USER }}",
"password": "${{ secrets.MAVEN_PASSWORD }}"
},
{
"id": "github",
"username": "${{ secrets.MAVEN_USER }}",
"password": "${{ secrets.MAVEN_PASSWORD }}"
}]
- name: Configure private NPM registry authentication
if: ${{ inputs.setup-npm-auth == true }}
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # [email protected]
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@felleslosninger'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build with Maven
run: mvn -B test