Skip to content

Commit fa2e57e

Browse files
author
Fabian Martinez
authored
lint mt ocp template and check db version matches (#2074)
1 parent c97eee0 commit fa2e57e

File tree

6 files changed

+86
-1
lines changed

6 files changed

+86
-1
lines changed

.github/scripts/install-tools.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
npm install -g @stoplight/spectral-cli

.github/workflows/lint.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Linting Workflow
2+
on:
3+
push:
4+
paths-ignore:
5+
- '.gitignore'
6+
- 'LICENSE'
7+
- 'README*'
8+
- 'docs/**'
9+
branches: [master]
10+
pull_request:
11+
paths-ignore:
12+
- '.gitignore'
13+
- 'LICENSE'
14+
- 'README*'
15+
- 'docs/**'
16+
branches: [master, 2.0.x]
17+
18+
jobs:
19+
lint:
20+
name: Lint
21+
runs-on: ubuntu-18.04
22+
if: github.repository_owner == 'Apicurio'
23+
steps:
24+
- name: Checkout Code with Ref '${{ github.ref }}'
25+
uses: actions/checkout@v2
26+
27+
- name: Install tools
28+
run: .github/scripts/install-tools.sh
29+
30+
- name: Run linter
31+
run: ./scripts/validate-files.sh

app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
import io.apicurio.registry.types.RuleType;
109109
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
110110
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
111+
import io.apicurio.registry.utils.IoUtil;
111112
import io.apicurio.registry.utils.StringUtil;
112113
import io.apicurio.registry.utils.impexp.ArtifactRuleEntity;
113114
import io.apicurio.registry.utils.impexp.ArtifactVersionEntity;
@@ -125,7 +126,8 @@
125126
*/
126127
public abstract class AbstractSqlRegistryStorage extends AbstractRegistryStorage {
127128

128-
private static int DB_VERSION = 5;
129+
private static int DB_VERSION = Integer.valueOf(
130+
IoUtil.toString(AbstractSqlRegistryStorage.class.getResourceAsStream("db-version"))).intValue();
129131
private static final Object dbMutex = new Object();
130132
private static final Object inmemorySequencesMutex = new Object();
131133

@@ -230,6 +232,7 @@ private boolean isDatabaseInitialized(Handle handle) {
230232
*/
231233
private boolean isDatabaseCurrent(Handle handle) {
232234
log.info("Checking to see if the DB is up-to-date.");
235+
log.info("Build's DB version is {}", DB_VERSION);
233236
int version = this.getDatabaseVersion(handle);
234237
return version == DB_VERSION;
235238
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5

scripts/ocp-template-ruleset.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const seen = [];
2+
var notRepeated = function(value) {
3+
if (seen.includes(value)) {
4+
return [{
5+
message: `Duplicated value '${value}'`
6+
}];
7+
} else {
8+
seen.push(value);
9+
}
10+
return [];
11+
}
12+
13+
module.exports = {
14+
rules: {
15+
"parameters-not-repeated": {
16+
message: "{{error}}",
17+
given: "$.parameters[*].name",
18+
severity: "error",
19+
then: {
20+
function: notRepeated,
21+
},
22+
},
23+
},
24+
};

scripts/validate-files.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# DB_VERSION_BUILD=$(yq .project.properties."registry.sql.storage.db-version" app/pom.xml -r)
4+
DB_VERSION_BUILD=$(cat app/src/main/resources/io/apicurio/registry/storage/impl/sql/db-version)
5+
echo "Build's DB version is $DB_VERSION_BUILD"
6+
7+
DDLS="app/src/main/resources/io/apicurio/registry/storage/impl/sql/postgresql.ddl app/src/main/resources/io/apicurio/registry/storage/impl/sql/h2.ddl"
8+
for ddl in $DDLS
9+
do
10+
echo "Processing DDL $ddl"
11+
DB_VERSION_INSERT=$(grep "INSERT INTO apicurio (prop_name, prop_value) VALUES ('db_version'" $ddl)
12+
DB_VERSION_IN_DDL=$(echo $DB_VERSION_INSERT | awk '{ print $8 }' - | awk -F ")" '{ print $1}' -)
13+
echo "DB version in DDL is $DB_VERSION_IN_DDL"
14+
15+
if (( $(echo "$DB_VERSION_BUILD $DB_VERSION_IN_DDL" | awk '{print ($1 != $2)}') )); then
16+
echo "DB version mismatch between DDL and build"
17+
exit 1
18+
fi
19+
done
20+
echo "DB version ok between build and DDLs"
21+
22+
echo "Linting openshift templates"
23+
spectral lint distro/openshift-template/mt/apicurio-registry-mt-template.yaml --ruleset scripts/ocp-template-ruleset.js

0 commit comments

Comments
 (0)