Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#338 Generate ci script #339

Merged
merged 12 commits into from
Aug 5, 2022
4 changes: 2 additions & 2 deletions .github/workflows/test_linux_build_on_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: go install github.com/google/[email protected]
- name: Build project-keeper
run: |
mvn clean package -DskipTests \
mvn clean package -DskipTests -DtrimStackTrace=false \
--batch-mode \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: Strip version number
Expand Down Expand Up @@ -97,4 +97,4 @@ jobs:
"-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
- name: run project-keeper
shell: pwsh
run: mvn --batch-mode com.exasol:project-keeper-maven-plugin:verify --projects .
run: mvn --batch-mode -DtrimStackTrace=false com.exasol:project-keeper-maven-plugin:verify --projects .
4 changes: 2 additions & 2 deletions .github/workflows/test_on_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ jobs:
- name: Install Go tools
run: go install github.com/google/[email protected]
- name: Build and install
run: mvn --batch-mode clean install
run: mvn --batch-mode -DtrimStackTrace=false clean install
- name: Run project-keeper itself
run: mvn --batch-mode com.exasol:project-keeper-maven-plugin:verify --projects .
run: mvn --batch-mode -DtrimStackTrace=false com.exasol:project-keeper-maven-plugin:verify --projects .
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.generate.finalModifiers": true
},
"java.saveActions.organizeImports": true,
"java.sources.organizeImports.starThreshold": 3,
"java.sources.organizeImports.staticStarThreshold": 3,
"java.test.config": {
"vmArgs": [
"-Djava.util.logging.config.file=src/test/resources/logging.properties"
]
},
}
411 changes: 207 additions & 204 deletions dependencies.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion doc/changes/changes_2.5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Code name: Fix Golang dependencies

## Summary

This release fixes retrieving of Golang dependencies, it should now work for most Golang projects.
This release fixes retrieving of Golang dependencies, it should now work for most Golang projects. It also generates a script for non-Maven projects that allows running PK in CI and locally.
kaklakariada marked this conversation as resolved.
Show resolved Hide resolved

## Features

* #321: Added default link replacement for Exasol JDBC driver
* #162: Omit heading for empty dependency updates section in changelog
* #132: Ensured that the reproducible-build-maven-plugin is the last one in the plugins list
* #338: Generate a script for verifying non-Maven projects

## Bugfixes

Expand All @@ -32,6 +33,7 @@ This release fixes retrieving of Golang dependencies, it should now work for mos
* Updated `org.junit.jupiter:junit-jupiter-engine:5.8.2` to `5.9.0`
* Updated `org.junit.jupiter:junit-jupiter-params:5.8.2` to `5.9.0`
* Updated `org.mockito:mockito-core:4.6.0` to `4.6.1`
* Added `org.slf4j:slf4j-jdk14:1.7.36`

#### Plugin Dependency Updates

Expand All @@ -57,6 +59,7 @@ This release fixes retrieving of Golang dependencies, it should now work for mos
* Updated `org.junit.jupiter:junit-jupiter-engine:5.8.2` to `5.9.0`
* Updated `org.junit.jupiter:junit-jupiter-params:5.8.2` to `5.9.0`
* Updated `org.mockito:mockito-junit-jupiter:4.6.0` to `4.6.1`
* Added `org.slf4j:slf4j-jdk14:1.7.36`

#### Plugin Dependency Updates

Expand Down Expand Up @@ -93,6 +96,7 @@ This release fixes retrieving of Golang dependencies, it should now work for mos
* Updated `org.junit.jupiter:junit-jupiter-engine:5.8.2` to `5.9.0`
* Updated `org.junit.jupiter:junit-jupiter-params:5.8.2` to `5.9.0`
* Updated `org.mockito:mockito-core:4.6.0` to `4.6.1`
* Added `org.slf4j:slf4j-jdk14:1.7.36`

#### Plugin Dependency Updates

Expand Down
8 changes: 7 additions & 1 deletion project-keeper-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
<artifactId>maven-plugin-integration-testing</artifactId>
<scope>test</scope>
</dependency>
<!-- Fix warning from SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -122,4 +128,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
8 changes: 7 additions & 1 deletion project-keeper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>
<!-- Fix warning from SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
kaklakariada marked this conversation as resolved.
Show resolved Hide resolved
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -135,4 +141,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ private ProjectKeeper(final Logger logger, final Path projectDir, final Path mvn
* @return built {@link ProjectKeeper}
*/
public static ProjectKeeper createProjectKeeper(final Logger logger, final Path projectDir, final Path mvnRepo) {
final String ownVersion = ProjectKeeper.class.getPackage().getImplementationVersion();
return new ProjectKeeper(logger, projectDir, mvnRepo, readConfig(projectDir), ownVersion);
return new ProjectKeeper(logger, projectDir, mvnRepo, readConfig(projectDir), getOwnVersion());
}

private static String getOwnVersion() {
final String packageVersion = ProjectKeeper.class.getPackage().getImplementationVersion();
if (packageVersion != null) {
return packageVersion;
}
return "(unknownVersion)";
kaklakariada marked this conversation as resolved.
Show resolved Hide resolved
ckunki marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -133,7 +140,7 @@ private List<Validator> getPhase2Validators() {
final String projectName = getProjectName(analyzedSources);
final var brokenLinkReplacer = new BrokenLinkReplacer(this.config.getLinkReplacements());
final String projectVersion = new ProjectVersionDetector().detectVersion(this.config, analyzedSources);
return List.of(new ProjectFilesValidator(this.projectDir, analyzedSources, this.logger),
return List.of(new ProjectFilesValidator(this.projectDir, analyzedSources, this.logger, this.ownVersion),
new ReadmeFileValidator(this.projectDir, projectName, this.repoName, analyzedSources),
new ChangesFileValidator(projectVersion, projectName, this.projectDir, analyzedSources),
new DependenciesValidator(analyzedSources, this.projectDir, brokenLinkReplacer),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.exasol.projectkeeper.validators.files;

import java.nio.file.Path;

/** Interface for templates for project files. */
public interface FileTemplate {
/**
Expand All @@ -14,7 +16,7 @@ public interface FileTemplate {
*
* @return path
*/
java.nio.file.Path getPathInProject();
Path getPathInProject();

/**
* Get the template type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FileTemplateFromResource implements FileTemplate {
*/
public FileTemplateFromResource(final String pathInProject, final TemplateType templateType) {
this.pathInProject = pathInProject;
this.pathToTemplate = pathInProject;
this.pathToTemplate = "templates/" + pathInProject;
this.templateType = templateType;
}

Expand All @@ -48,6 +48,6 @@ public Path getPathInProject() {

@Override
public String getContent() {
return new ResourceReader().readFromResource("templates/" + this.pathInProject);
return new ResourceReader().readFromResource(this.pathToTemplate);
ckunki marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.exasol.projectkeeper.shared.config.ProjectKeeperModule.*;
import static com.exasol.projectkeeper.validators.files.FileTemplate.TemplateType.REQUIRE_EXACT;
import static com.exasol.projectkeeper.validators.files.FileTemplate.TemplateType.REQUIRE_EXIST;
import static java.util.Collections.emptyList;

import java.util.*;

Expand All @@ -12,14 +11,17 @@
import com.exasol.projectkeeper.shared.config.ProjectKeeperModule;
import com.exasol.projectkeeper.sources.*;

import lombok.RequiredArgsConstructor;

/**
* Factory for file templates.
*/
@RequiredArgsConstructor
kaklakariada marked this conversation as resolved.
Show resolved Hide resolved
class FileTemplatesFactory {
private final Logger logger;
private final String ownVersion;

public FileTemplatesFactory(final Logger logger, final String ownVersion) {
this.logger = logger;
this.ownVersion = ownVersion;
}

List<FileTemplate> getGlobalTemplates(final List<AnalyzedSource> sources) {
final List<FileTemplate> templates = new ArrayList<>();
Expand All @@ -32,6 +34,8 @@ List<FileTemplate> getGlobalTemplates(final List<AnalyzedSource> sources) {
templates.add(new FileTemplateFromResource(
".github/workflows/release_droid_release_on_maven_central.yml", REQUIRE_EXACT));
}
} else if (onlyGolangProjects(sources)) {
templates.addAll(getGolangTemplates());
ckunki marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.logger.warn(ExaError.messageBuilder("W-PK-CORE-91")
.message("For this project structure project keeper does not know how to configure ci-build.")
Expand All @@ -57,7 +61,7 @@ private List<FileTemplate> getGenericMavenTemplates(final Set<ProjectKeeperModul
private FileTemplateFromResource getCiBuildTemplate(final Set<ProjectKeeperModule> modules) {
if (modules.contains(NATIVE_IMAGE)) {
return new FileTemplateFromResource(".github/workflows/ci-build.yml",
".github/workflows/ci-build-native-image.yml", REQUIRE_EXACT);
"templates/.github/workflows/ci-build-native-build.yml", REQUIRE_EXACT);
} else {
return new FileTemplateFromResource(".github/workflows/ci-build.yml", REQUIRE_EXACT);
}
Expand All @@ -67,6 +71,10 @@ private boolean isMvnRootProject(final AnalyzedSource source) {
return (source instanceof AnalyzedMavenSource) && (((AnalyzedMavenSource) source).isRootProject());
}

private boolean onlyGolangProjects(final List<AnalyzedSource> sources) {
return sources.stream().allMatch(AnalyzedGolangSource.class::isInstance);
}

List<FileTemplate> getTemplatesForSource(final AnalyzedSource source) {
if (source instanceof AnalyzedMavenSource) {
return getMavenTemplates((AnalyzedMavenSource) source);
Expand Down Expand Up @@ -101,6 +109,10 @@ private List<FileTemplate> getMavenTemplates(final AnalyzedMavenSource source) {
}

private List<FileTemplate> getGolangTemplates() {
return emptyList();
final ArrayList<FileTemplate> templates = new ArrayList<>();
final String pathInProject = ".github/workflows/project-keeper-verify.yml";
templates.add(new FileTemplateFromResource(pathInProject, "golang_templates/" + pathInProject, REQUIRE_EXACT));
templates.add(new ProjectKeeperShellScript(this.ownVersion));
return templates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@ public class ProjectFilesValidator implements Validator {
private final Path projectDirectory;
private final List<AnalyzedSource> sources;
private final Logger logger;
private final String ownVersion;

/**
* Crate a new instance of {@link ProjectFilesValidator}.
*
*
* @param projectDirectory project's root directory
* @param sources list of sources
* @param logger logger
* @param ownVersion the version of the currently running project keeper
*/
public ProjectFilesValidator(final Path projectDirectory, final List<AnalyzedSource> sources, final Logger logger) {
public ProjectFilesValidator(final Path projectDirectory, final List<AnalyzedSource> sources, final Logger logger,
final String ownVersion) {
kaklakariada marked this conversation as resolved.
Show resolved Hide resolved
this.projectDirectory = projectDirectory;
this.sources = sources;
this.logger = logger;
this.ownVersion = ownVersion;
}

@Override
public List<ValidationFinding> validate() {
final List<ValidationFinding> findings = new ArrayList<>();
final FileTemplatesFactory templatesFactory = new FileTemplatesFactory(this.logger);
final FileTemplatesFactory templatesFactory = new FileTemplatesFactory(this.logger, this.ownVersion);
findings.addAll(validateTemplatesRelativeToRepo(templatesFactory));
findings.addAll(validateTemplatesRelativeToSource(templatesFactory));
return findings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.exasol.projectkeeper.validators.files;

import java.nio.file.Path;
import java.nio.file.Paths;

class ProjectKeeperShellScript implements FileTemplate {
private static final String TEMPLATE_PATH = ".github/workflows/project-keeper.sh";

private final String ownVersion;

ProjectKeeperShellScript(final String ownVersion) {
this.ownVersion = ownVersion;
}

@Override
public String getContent() {
String template = new ResourceReader().readFromResource("non_maven_templates/" + TEMPLATE_PATH);
template = template.replace("##VERSION##", this.ownVersion);
return template;
}

@Override
public Path getPathInProject() {
return Paths.get(TEMPLATE_PATH);
}

@Override
public TemplateType getTemplateType() {
return TemplateType.REQUIRE_EXACT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Project Keeper Verify

on:
push:
branches:
- main
pull_request:

jobs:
project-keeper-verify:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: Cache Project Keeper
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-pk-${{ hashFiles('.github/workflows/project-keeper.sh') }}
restore-keys: |
${{ runner.os }}-pk-

- name: Cache go-licenses
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-licenses-${{ hashFiles('.github/workflows/project-keeper-verify.yml') }}
restore-keys: |
${{ runner.os }}-go-licenses-${{ hashFiles('.github/workflows/project-keeper-verify.yml') }}
${{ runner.os }}-go-licenses-

- name: Install go-licenses
run: go install github.com/google/[email protected]

- name: Project Keeper Verify
run: ./.github/workflows/project-keeper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

readonly pk_mode="${1-verify}";
readonly version="##VERSION##"

readonly pk_jar="$HOME/.m2/repository/com/exasol/project-keeper-cli/$version/project-keeper-cli-$version.jar"

if [ ! -f "$pk_jar" ]; then
echo "Downloading Using Project Keeper $version"
mvn --batch-mode org.apache.maven.plugins:maven-dependency-plugin:3.3.0:get -Dartifact=com.exasol:project-keeper-cli:$version
ckunki marked this conversation as resolved.
Show resolved Hide resolved
fi

echo "Running Project Keeper with mode $pk_mode from $pk_jar"
java -jar "$pk_jar" "$pk_mode"
Loading