-
Notifications
You must be signed in to change notification settings - Fork 25
Gitlab Pipeline generator #147
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
Open
ultymatom
wants to merge
5
commits into
devonfw:master
Choose a base branch
from
ultymatom:feature/pipeline-generator-gitlab
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6b1b32a
first commit (adding glab pipe gen and creating artifact function)
ultymatom 54a04e1
adding gitlab-ci file
ultymatom edf91dc
fixing some little errors
ultymatom 35d433a
Merge branch 'master' into feature/pipeline-generator-gitlab
ultymatom 115cf29
L pipeline generator lib
ultymatom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| #!/bin/bash | ||
| set -e | ||
| FLAGS=$(getopt -a --options c:n:d:a:b:l:i:u:p:hw --long "config-file:,pipeline-name:,local-directory:,artifact-path:,target-branch:,language:,build-pipeline-name:,sonar-url:,sonar-token:,image-name:,registry-user:,registry-password:,resource-group:,storage-account:,storage-container:,cluster-name:,s3-bucket:,s3-key-path:,quality-pipeline-name:,dockerfile:,test-pipeline-name:,aws-access-key:,aws-secret-access-key:,aws-region:,help" -- "$@") | ||
|
|
||
| eval set -- "$FLAGS" | ||
| while true; do | ||
| case "$1" in | ||
| -c | --config-file) configFile=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -n | --pipeline-name) export pipelineName=$2; shift 2;; | ||
| -d | --local-directory) localDirectory=$2; shift 2;; | ||
| -a | --artifact-path) artifactPath=$2; shift 2;; | ||
| -b | --target-branch) targetBranch=$2; shift 2;; | ||
| -l | --language) language=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --build-pipeline-name) export buildPipelineName=$2; shift 2;; | ||
| --sonar-url) sonarUrl=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --sonar-token) sonarToken=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -i | --image-name) imageName=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -u | --registry-user) dockerUser=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -p | --registry-password) dockerPassword=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --resource-group) resourceGroupName=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --storage-account) storageAccountName=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --storage-container) storageContainerName=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --cluster-name) clusterName=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --s3-bucket) s3Bucket=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --s3-key-path) s3KeyPath=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --quality-pipeline-name) export qualityPipelineName=$2; shift 2;; | ||
| --test-pipeline-name) export testPipelineName=$2; shift 2;; | ||
| --dockerfile) dockerFile=$2; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --aws-access-key) awsAccessKey="$2"; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --aws-secret-access-key) awsSecretAccessKey="$2"; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| --aws-region) awsRegion="$2"; shift 2;; | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| -h | --help) help="true"; shift 1;; | ||
| -w) webBrowser="true"; shift 1;; | ||
| --) shift; break;; | ||
| esac | ||
| done | ||
|
|
||
| # Colours for the messages. | ||
| white='\e[1;37m' | ||
| green='\e[1;32m' | ||
| red='\e[0;31m' | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Common var | ||
| commonTemplatesPath="scripts/pipelines/gitlab/templates/common" # Path for common files of the pipelines | ||
| pipelinePath=".pipelines" # Path to the pipelines. | ||
| scriptFilePath=".pipelines/scripts" # Path to the scripts. | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| gitlabCiFile=".gitlab-ci.yml" | ||
| export provider="gitlab" | ||
|
|
||
| function obtainHangarPath { | ||
|
|
||
| # This line goes to the script directory independent of wherever the user is and then jumps 3 directories back to get the path | ||
| hangarPath=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && cd ../../.. && pwd ) | ||
| } | ||
|
|
||
| function addAdditionalArtifact { | ||
| # Check if an extra artifact to store is supplied. | ||
| if test ! -z "$artifactPath" | ||
| then | ||
| # Add the extra step to the YAML. | ||
| grep " artifacts:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null && storeExtraPathContent=" - \"$artifactPath\"" | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| grep " artifacts:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null || storeExtraPathContent="\n artifacts:\n paths:\n - \"$artifactPath\"" | ||
| sed -i "s/# mark to insert step for additonal artifact #/$storeExtraPathContent\n/" "${localDirectory}/${pipelinePath}/${yamlFile}" | ||
| else | ||
| echo "The '-a' flag has not been set, skipping the step to add additional artifact." | ||
| sed -i '/# mark to insert step for additonal artifact #/d' "${localDirectory}/${pipelinePath}/${yamlFile}" | ||
| fi | ||
| } | ||
|
|
||
| # Function that adds the variables to be used in the pipeline. | ||
| function addCommonPipelineVariables { | ||
| if test -z "${artifactPath}" | ||
| then | ||
| echo "Skipping creation of the variable artifactPath as the flag has not been used." | ||
| # Delete the commentary to set the artifactPath input/var | ||
| sed -i '/# mark to insert additional artifact env var #/d' "${localDirectory}/${pipelinePath}/${yamlFile}" | ||
| else | ||
| # add the input for the additional artifact | ||
| grep "variables:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null && textArtifactPathVar=" artifactPath: ${artifactPath//\//\\/}" | ||
| grep "variables:" "${localDirectory}/${pipelinePath}/${yamlFile}" > /dev/null || textArtifactPathVar="variables:\n artifactPath: \"${artifactPath//\//\\/}\"" | ||
| sed -i "s/# mark to insert additional artifact env var #/$textArtifactPathVar/" "${localDirectory}/${pipelinePath}/${yamlFile}" | ||
| fi | ||
| } | ||
|
|
||
| function addCiFile { | ||
| echo -e "${green}Copying and commiting the gitlab ci file." | ||
| echo -ne ${white} | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| cp "${hangarPath}/${commonTemplatesPath}/${gitlabCiFile}" "${localDirectory}/${gitlabCiFile}" | ||
| testCommit=$(git status) | ||
| if echo "$testCommit" | grep "nothing to commit, working tree clean" > /dev/null | ||
| then | ||
| echo "gilab-ci file already present with same content, nothing to commit." | ||
| else | ||
| git add "${gitlabCiFile}" -f | ||
| git commit -m "adding gitlab-ci.yml" | ||
| git push | ||
| fi | ||
| } | ||
|
|
||
| function createPR { | ||
| # Check if a target branch is supplied. | ||
| if test -z "$targetBranch" | ||
| then | ||
| # No branch specified in the parameters, no Pull Request is created, the code will be stored in the current branch. | ||
| echo -e "${green}No branch specified to do the Pull Request, changes left in the ${sourceBranch} branch." | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| exit | ||
| else | ||
| echo -e "${green}Creating a Pull Request..." | ||
| echo -ne "${white}" | ||
| repoURL=$(git config --get remote.origin.url) | ||
| repoNameWithGit="${repoURL/https:\/\/gitlab.com\/}" | ||
| repoName="${repoNameWithGit/.git}" | ||
| # Create the Pull Request to merge into the specified branch. | ||
| #debug | ||
| echo "glab mr create -b \"$targetBranch\" -d \"merge request $sourceBranch\" -s \"$sourceBranch\" -H \"${repoName}\" -t \"merge $sourceBranch\"" | ||
| pr=$(glab mr create -b "$targetBranch" -d "merge request $sourceBranch" -s "$sourceBranch" -H "${repoName}" -t "merge $sourceBranch") | ||
|
|
||
| # trying to merge | ||
| if glab mr merge -s $(basename "$pr") -y | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| then | ||
| # Pull Request merged successfully. | ||
| echo -e "${green}Pull Request merged into $targetBranch branch successfully." | ||
| exit | ||
| else | ||
| # Check if the -w flag is activated. | ||
| if [[ "$webBrowser" == "true" ]] | ||
| then | ||
| # -w flag is activated and a page with the corresponding Pull Request is opened in the web browser. | ||
| echo -e "${green}Pull Request successfully created." | ||
| echo -e "${green}Opening the Pull Request on the web browser..." | ||
| python -m webbrowser "$pr" | ||
| exit | ||
| else | ||
| # -w flag is not activated and the URL to the Pull Request is shown in the console. | ||
| echo -e "${green}Pull Request successfully created." | ||
| echo -e "${green}To review the Pull Request and accept it, click on the following link:" | ||
| echo "${pr}" | ||
| exit | ||
| fi | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
|
|
||
| obtainHangarPath | ||
|
|
||
| # Load common functions | ||
| . "$hangarPath/scripts/pipelines/common/pipeline_generator.lib" | ||
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
ultymatom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [[ "$help" == "true" ]]; then help; fi | ||
|
|
||
| ensurePathFormat | ||
|
|
||
| importConfigFile | ||
|
|
||
| checkInstallations | ||
|
|
||
| createNewBranch | ||
|
|
||
| type addPipelineVariables &> /dev/null && addPipelineVariables | ||
|
|
||
| copyYAMLFile | ||
|
|
||
| addAdditionalArtifact | ||
|
|
||
| copyCommonScript | ||
|
|
||
| type copyScript &> /dev/null && copyScript | ||
|
|
||
| # This function does not exists for the github pipeline generator at this moment, but I let the line with 'type' to keep the same structure as the others pipeline generator | ||
| type addCommonPipelineVariables &> /dev/null && addCommonPipelineVariables | ||
|
|
||
| commitCommonFiles | ||
|
|
||
| type commitFiles &> /dev/null && commitFiles | ||
|
|
||
| addCiFile | ||
|
|
||
| createPR | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| include: | ||
| - '.pipelines/*.yml' | ||
|
|
||
| stages: | ||
| - build | ||
| - test | ||
| - quality | ||
| - package | ||
|
|
||
| default: | ||
| image: maven:3-jdk-11 | ||
| tags: ['docker_ruby'] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.