How to change a file name based on the directory it is in for packaging - deployment

I have the following gradle task:
task copyToDeployDir(dependsOn: preDeploy) << {
copy {
from codeDir
into deployDir
}
}
This works great for copying from my code dir (usually main or src) into a deployment directory. However, I want to rename a few of these files. Specifically, since I'm using CodeIgniter, I want to rename a couple of the controllers to start with an "install" controller.
Ideally, what I want is to copy over all of the files into deployDir, except any files that are in codeDir/application/controllers, I want to rename to have a suffix of .dist.
I'm not really sure how to go about doing this. I previously tried the renaming stuff in Working with Files in the gradle documentation, but it doesn't seem to work with gradle 2.2.

Try:
task copyToDeployDir(dependsOn: preDeploy, type: Copy) << {
from(codeDir) {
exclude '**/application/controllers/*'
}
from(codeDir) {
include '**/application/controllers/*'
rename {
"${it}.suffix"
}
}
into deployDir
}

Related

Can't exclude folders for VS Code OmniSharp's Code Analyser

I use VS Code with Unity and I'm trying to ignore the code analysis of third party code bases.
I've read OmniSharp's github page, and tried excluding those folders but I failed to do so. What I did was:
I've created an omnisharp.json file where the .csproj files are, with this content:
{
"fileOptions": {
"excludeSearchPatterns": [
"Assets/ThirdPartyFolder/**/*"
]
}
}
I've also tried using systemExcludeSearchPatterns instead of excludeSearchPatterns but to no avail.
(And also tried adding the "/**/*" path for fun, but still everything was analyzed. :\ )
I always restarted OmniSharp after changing the json file:
But the "want-to-be-excluded folders" are still analyzed.
Like after I added "Assets/AltUnityTester/**/*":
Create .editorconfig file in your project root folder with the following content:
root = true
[Assets/Assetstore/**.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
[Assets/Plugins/**.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
My omnisharp.json located in the project root folder:
{
"RoslynExtensionsOptions": {
"EnableEditorConfigSupport": true,
"EnableAnalyzersSupport": true,
"LocationPaths": [
"./NuGet/microsoft.unity.analyzers.1.12.0"
]
}
}
This solution works for me. See Enabling Unity warnings.
C# for Visual Studio Code: v1.24.1

Is there a way to include whole folder with changelogs in Liquibase db versioning?

I have a problem with Liquibase database versioning, because I want to include all changelog files in folder, without specifing its names and do update using them. Is that possible? My structure:
db--
|
--release-v1
|
--fistchangelog.sql
--secondchangelog.sql
|
--release-v2
|
--newchangelog.sql
...
And with every release I want to use all *.sql files from its folder. I don't want to hardcode names of sql files. I use only liquibase command lines for CI/CD in Azure.
I found something like (liquibase.org/get-started/best-practices), but it only works with xml files and I use sql extension.
I have one idea but it seems bad for me and I ll use it as a last resort. Just making a loop, for every file in folder, in cmd...
Does someone know is there a simpler and better way?
You can do like this:
have a parent change log file:
databaseChangeLog = {
include file: "releases/ref1.groovy", relativeToChangelogFile: true
include file: "releases/release1.groovy", relativeToChangelogFile: true
include file: "releases/release2.groovy", relativeToChangelogFile: true
include file: "releases/release3.groovy", relativeToChangelogFile: true
}
in releases folder ref1 file can have:
databaseChangeLog = {
include file: "../tables/changelog.groovy", relativeToChangelogFile: true
}
So inside the same releases folder you can have tables folder which then have create, delete update folders. So you can have another file in tables like, in create folder, you have all the necessary files that have been added in different releases:
databaseChangeLog = {
include file: "create/changelog.groovy", relativeToChangelogFile: true
include file: "update/changelog.groovy", relativeToChangelogFile: true
include file: "data/changelog.groovy", relativeToChangelogFile: true
}
finally in releases main folder you can add a file like release1.groovy:
databaseChangeLog = {
include file: "../tables/create/your_structured_sql_file.groovy",
relativeToChangelogFile: true
}
These are in groovy but the structuring is the same.
i think you should just use "includeAll" tag. Then liquibase will execute all .sql files inside the folder. but remember that if you not specifying every single file, Liquibase will execute those files in alphabetical order.
Sth like:
<includeAll path="com/example/changelogs/"/>
Read here -> https://docs.liquibase.com/concepts/changelogs/attributes/includeall.html

How can we check in Jenkins home directory to Github?

We want to check in the Jenkins home directory into Github, certainly ignoring some files/folders. As we want to have everything defined by code, we try to achieve this using Job DSL & Pipeline DSL (not writing the pipeline script inside Jenkins GUI but having it read from a workspace file - see below).
My problem right now is that, being not very proficient in both DSL's yet, I don't know how to force git to do an initial clone of the remote repo (and later push) inside the home directory - which is a parent directory of the job's directory.
I tried this pipeline:
node('master') {
dir('../..') {
scm {
git {
remote {
github('company/repo', 'https')
credentials('xyz')
}
}
}
}
}
The job itself is defined like this:
pipelineJob('backup') {
definition {
cps {
script(readFileFromWorkspace('pipelines/backup.groovy'))
sandbox(true)
}
}
}
The job fails with this error message:
ERROR: ‘checkout scm’ is only available when using “Multibranch Pipeline” or “Pipeline script from SCM”
So I guess the above used 'pipelineJob(backup)' does not fit. Should I change this, and if, how, or should I take another approach?
Another shot at this was trying to rewrite the pipeline like this:
node {
dir('../..') {
git url: 'https://github.com/company/repo.git'
}
}
But then it won't work because credentials are missing...

Group Item: cannot install file to same location

In my project, I have several plugins depending on a single module, containing a Group item similar to:
Group {
name: "group"
qbs.install: true
qbs.installDir: "../"
files: <filename>
}
But compilation fails with "error: Cannot install files 'filename' and 'filename' to the same location 'location'". Basically, qbs cannot copy same file to same location twice (seems illogical to me)
How can this bug be resolved or is there any elegant workaround?
This is a job for the qbs.installSourceBase property. Basically, you set this to the base directory containing the files in your Group, and Qbs will install the listed files into qbs.installDir hierarchically based on their paths relative to the aforementioned base directory.
For example, given the following Group:
// defined in /source/myproject/myproject.qbs
Group {
qbs.install: true
qbs.installDir: "share/stuff"
qbs.installSourceBase: "." // relative to /source/myproject
files: [
"fileA.txt",
"fileB.txt",
"subdir/fileB.txt",
]
}
and the following command line invocation:
$ qbs [...] --install-root /sample/some-root
the following filesystem hierarchy will result:
/sample/some-root/share/stuff/fileA.txt
/sample/some-root/share/stuff/fileB.txt
/sample/some-root/share/stuff/subdir/fileB.txt
See the Qbs Installation Properties documentation for more info.
There is a workaround, which may require some restructuring of a project:
instead of:
Module {
name: "somemodule"
// module properties set to dependant products
Group {
// files to install
qbs.install: true
}
}
we can use:
Product {
name: "somemodule"
Group {
// files to install
qbs.install: true
}
Export {
// module properties set to dependant products
}
}
This way, files are only installed once when steps for mymodule are run, thus eliminating the conflict. Module properties, exported via Export Item, work just as ones exported via Module.
Limitations:
Product has to be added to references of the Project Item
Modules cannot depend on Product Items, which may require to restructure all dependant modules into Project/Export pairs too

Copy different files to build directory based on executed Gradle task

I have created a plugin for Gradle to deploy to my company's OpenVMS directory structures, which adds deployDev, deployTest, and, when credentials are provided, deployProd tasks to an application build. I have extracted our configuration files for all environments to a separate project so that we can deploy configuration separately from the application.
These custom tasks depend on the application plugin's distZip task and I haven't found a good way to get the appropriate configuration files into the zip based on the called task (e.g. deployDev includes dev config).
I have tried having the deploy* tasks copy configuration files during the configuration phase with:
task distZip(type:Zip, overwrite:true) {
archiveName = 'config.zip'
from "build/props"
}
deployDev.configure {
copyResources('dev')
}
deployTest.configure {
copyResources('test')
}
project.tasks.findByName('deployProd')?.configure {
copyResources('prod')
}
def copyResources(String environment){
copy {
from "src/$environment/resources"
into 'build/props'
}
}
This doesn't work due to configuration phase executing on all tasks, so even when we execute deployDev, the test configuration has been copied over the dev resources.
I also have tried:
file('build/props').mkdirs()
task distZip(type:Zip, overwrite:true) {
archiveName = 'config.zip'
from "build/props"
outputs.upToDateWhen {false}
}
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask('deployProd')) {
copyResources('prod')
}else if(graph.hasTask('deployTest')){
copyResources('test')
}else if(graph.hasTask('deployDev')){
copyResources('dev')
}
}
def copyResources(String environment){
copy {
from "src/$environment/resources"
into 'build/props'
}
}
However, with this proposal the distZip task always is UP-TO-DATE. Is there a correct way to do this?