diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 56243e7..d3545c7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,9 +8,24 @@ stages:
- sync
include:
+ - local: $JOB_ROOT_DIR/yaml_lint/.gitlab-ci.yml
- local: $JOB_ROOT_DIR/conventional_commits/.gitlab-ci.yml
- local: $JOB_ROOT_DIR/git_push_mirror/.gitlab-ci.yml
- local: $JOB_ROOT_DIR/gitlab_release/.gitlab-ci.yml
+ - local: $JOB_ROOT_DIR/python/.gitlab-ci.yml
+
+PyLint:
+ extends:
+ - .PyLint
+ image: python:3.6-slim
+
+
+gilab-ci.yml Lint (python 3.6):
+ variables:
+ YAML_LINT_PATH: "/*/.gitlab-ci.yml"
+ extends:
+ - .yaml_lint_defaults
+ image: python:3.6-slim
Gitlab Release:
@@ -20,7 +35,6 @@ Gitlab Release:
- .gitlab_release
-
Github (Push --mirror):
variables:
GIT_SYNC_URL: "https://$GITHUB_USERNAME_ROBOT:$GITHUB_TOKEN_ROBOT@github.com/NoFussComputing/gitlab-ci.git"
diff --git a/.gitlab/.gitkeep b/.gitlab/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/.gitlab/issue_templates/.gitkeep b/.gitlab/issue_templates/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/.gitlab/issue_templates/new_job.md b/.gitlab/issue_templates/new_job.md
new file mode 100644
index 0000000..d95b30c
--- /dev/null
+++ b/.gitlab/issue_templates/new_job.md
@@ -0,0 +1,84 @@
+## :new: Ansible Role - {new ansible role name}
+
+
+
+:clipboard: template filename.extension
+
+``` yaml
+your yaml playbook here
+```
+
+
+
+### Playbook usage
+
+
+
+
+
+:clipboard: example playbook
+
+``` yaml
+your yaml playbook here
+```
+
+
+
+
+### :ledger: Documentation
+
+
+
+
+:clipboard: contribution - Documentation
+
+
+
+
+
+## :link: Links
+
+
+ - link 1
+
+ - issue #number
+
+
+## :ballot_box_with_check: Tasks
+
+
+ - [ ] ~Documentation Added
+
+ - [ ] (dev) Merge request opened and linked to this issue
+
+
+
+
+
+
+/label ~"workflow::not started"
+
+/label ~"category::feature"
diff --git a/.gitlab/merge_request_templates/.gitkeep b/.gitlab/merge_request_templates/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/.gitlab/merge_request_templates/default.md b/.gitlab/merge_request_templates/default.md
new file mode 100644
index 0000000..8f81fc6
--- /dev/null
+++ b/.gitlab/merge_request_templates/default.md
@@ -0,0 +1,34 @@
+## :books: Summary
+
+
+
+
+-----
+
+| :link: **Related Issue(s)** | :link: **Related Merge Request(s)** |
+|:----:|:----:|
+| | |
+
+
+### :construction_worker: Tasks
+
+
+ - [ ] merging to correct branch?
+
+ - [ ] issue linked to this MR?
+
+ - related issues:
+
+ - [ ] closed in a commit message
+
+ - [ ] Manually closed
+
+ - [ ] All related issues tasks complete?
+
+
+
+
+
+/label ~"workflow::not started"
+
+/label ~"category::feature"
diff --git a/.templates/README.md b/.templates/README.md
new file mode 100644
index 0000000..1445d4b
--- /dev/null
+++ b/.templates/README.md
@@ -0,0 +1,40 @@
+# {CI Job Name}
+Summary of job here
+
+This job provides the following badge:
+
+{A badge here}
+
+## Dependencies
+
+- {dependent job name}
+
+## your .gitlab-ci.yml changes
+To use this job add the following to your `.gitlab-ci.yml` file
+
+``` yaml
+variables:
+ VARNAME: "a var value"
+
+stages:
+ - {new stage name}
+
+include:
+ - local: CI/{job name}/.gitlab-ci.yml
+```
+
+## CI/CD Variables required
+
+| var name | Description |
+|:----:|:----|
+| NEW VAR | this var does this and bka |
+
+
+## Job Workflow
+
+
+## Artifacts
+
+
+## License
+To view the license for this folder and any sub-folders, refer [here](https://gitlab.com/nofusscomputing/projects/gitlab-ci)
diff --git a/README.md b/README.md
index dab0ff2..dbca36e 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,104 @@
-# Ansible Roles
+# No Fuss Computing - Gitlab-CI
-[](https://gitlab.com/nofusscomputing/projects/gitlab-ci)
+
+
+[](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/issues)
-[](https://gitlab.com/nofusscomputing/projects/gitlab-ci)
+| Stable Branch |
+[](https://gitlab.com/nofusscomputing/projects/gitlab-ci) |
+[](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/jobs/artifacts/master/file/artifacts/validation/tests/gl-code-quality-report.html?job=PyLint) |
+|:----|:----|:----|
+
+| development Branch |
+[](https://gitlab.com/nofusscomputing/projects/gitlab-ci) |
+[](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/jobs/artifacts/development/file/artifacts/validation/tests/gl-code-quality-report.html?job=PyLint) |
+|:----|:----|:----|
+
+
This repository is hosted on [gitlab.com](https://gitlab.com/nofusscomputing/projects/gitlab-ci) and has a read-only copy hosted on [github.com](https://github.com/NoFussComputing/gitlab-ci).
links:
-- [Issues](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/issues)
+
+- [ Issues](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/issues)
- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/merge_requests)
-> *To Do: expand on how repo setup and how to use.*
+## Using this repository for your Gitlab CI/CD Jobs.
+This repository has been designed as a central point for your repositories CI/CD jobs. By simply linking this repository to your repository and configuring, your CI/CD jobs will run as part of the build process, whilst keeping any CI/CD commits limited within your git history.
+
+Each CI/CD job is contained within its own sub-folder. Each sub-folder has a readme specific to the job, which includes the details on how to implement, use etc.
+
+
+### gitlab-ci layout
+
+We use the following branches:
+ - `master` - Considered as the stable branch
+ - `development` considered as unstable
+
+We also tag each branch to denote the version of release. We use our own repo to do the version increment automagically in line with [semantic versioning](https://semver.org/).
+
+
+
+### CI Stages
+The CI stages for these jobs are as follows, and in the order expected by the jobs:
+
+- validation
+ > validation of files, commits, Merge Request titles, code quality, license checks.
+
+- build
+ > build any binaries or files that would be used in the later stages .
+
+- prepare
+ > any jobs that must run after build but before testing. for example a docker image build that includes artifacts from the build job
+
+- test
+ > unit, functional, integration and any other tests.
+
+- release
+ > git tagging and creating a gitlab release. Also includes adding build artifacts to gitlab registry.
+
+- sync
+ > repository synchronization, i.e. push mirror to github.
+
+- publish
+ > placement of build objects to external sources
+
+
+### Artifacts
+Any artifacts by jobs will be created in folders named after the stage.
+
+preference is placed on jobs to output JUnit.xml test reports. This is because they are visible in merge requests.
+
+
+It is recommended that you set-up this repo as a git sub-module to your repo and that you configure it to a set commit/tag. This ensures that any change to `gitlab-ci` repo, does not effect your CI/CD jobs.
+
+run the following commands:
+``` bash
+git submodule add -b {ref} https://gitlab.com/nofusscomputing/projects/gitlab-ci.git gitlab-ci
+git submodule update --remote
+
+```
+
+| :bulb: Tip |
+|:-----|
+| NOTE: `{ref}` should be replaced with the branch name, `master` is the stable branch and recommended. by default the sub-module will be created in folder `gitlab-ci`, it is recommended that you **don't** change this folder name.
+You can also substitute the gitlab url with the github url `https://github.com/NoFussComputing/gitlab-ci.git` for the submodule if you desire. this repo is auto-synced with github on each change to the repo. |
+
+After each `git submodule update --remote` you will have to commit the sub-module update to your repo. Suggested commands as follows:
+``` bash
+git add .gitmodules
+
+git add gitlab-ci
+
+git commit -m "ci(gitlab-ci): updated to use version x
+
+{your reason here or explain what is provided/changed}"
+```
+Then push the changes to your source.
## Contributing
diff --git a/ansible/.gitlab-ci.yml b/ansible/.gitlab-ci.yml
index 9222756..80222b3 100644
--- a/ansible/.gitlab-ci.yml
+++ b/ansible/.gitlab-ci.yml
@@ -22,13 +22,13 @@
after_script:
- echo deactivate
artifacts:
- expire_in: 3 days
- when: always
- paths:
- - "artifacts/*"
- reports:
- junit:
- - "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
+ expire_in: 3 days
+ when: always
+ paths:
+ - "artifacts/*"
+ reports:
+ junit:
+ - "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
when: never
diff --git a/conventional_commits/.gitlab-ci.yml b/conventional_commits/.gitlab-ci.yml
index 972bd97..cf84d5e 100644
--- a/conventional_commits/.gitlab-ci.yml
+++ b/conventional_commits/.gitlab-ci.yml
@@ -50,11 +50,11 @@
junit:
- "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
rules:
- - if: '$CI_COMMIT_BRANCH == "master"'
- when: never
- - if: '$CI_COMMIT_BRANCH'
- when: always
- - when: never
+ - if: '$CI_COMMIT_BRANCH == "master"'
+ when: never
+ - if: '$CI_COMMIT_BRANCH'
+ when: always
+ - when: never
MR Title:
diff --git a/git_push_mirror/.gitlab-ci.yml b/git_push_mirror/.gitlab-ci.yml
index daa9b98..3bd1967 100644
--- a/git_push_mirror/.gitlab-ci.yml
+++ b/git_push_mirror/.gitlab-ci.yml
@@ -14,9 +14,7 @@
artifacts:
expire_in: 1 day
rules:
- - if: '$CI_COMMIT_BRANCH == "master"'
- - if: '$CI_COMMIT_BRANCH == "development"'
- when: always
-
-
+ - if: '$CI_COMMIT_BRANCH == "master"'
+ - if: '$CI_COMMIT_BRANCH == "development"'
+ when: always
diff --git a/gitlab_release/.gitlab-ci.yml b/gitlab_release/.gitlab-ci.yml
index d1ebfa9..4283696 100644
--- a/gitlab_release/.gitlab-ci.yml
+++ b/gitlab_release/.gitlab-ci.yml
@@ -85,10 +85,10 @@ commit footer refs:
junit:
- "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
rules:
- - if: '$CI_COMMIT_BRANCH == "master"'
- - if: '$CI_COMMIT_BRANCH == "development"'
- when: never
- - if: '$CI_COMMIT_BRANCH && $CHANGELOG_FOOTER_REFERENCES != "False"'
- when: always
- - when: never
+ - if: '$CI_COMMIT_BRANCH == "master"'
+ - if: '$CI_COMMIT_BRANCH == "development"'
+ when: never
+ - if: '$CI_COMMIT_BRANCH && $CHANGELOG_FOOTER_REFERENCES != "False"'
+ when: always
+ - when: never
diff --git a/gitlab_release/python-module/commit_footer/commits.py b/gitlab_release/python-module/commit_footer/commits.py
index f7a344c..b21f0fa 100644
--- a/gitlab_release/python-module/commit_footer/commits.py
+++ b/gitlab_release/python-module/commit_footer/commits.py
@@ -13,7 +13,7 @@ class Commits:
self._repository = git.Repo(os.getcwd())
self._failed = []
- merge_base = self._repository.merge_base('development', 'changelog-footer-toggle')
+ merge_base = self._repository.merge_base('development', self._repository.active_branch)
self._merge_base = str(merge_base[0])
self.fetch_all()
diff --git a/python/.gitlab-ci.yml b/python/.gitlab-ci.yml
new file mode 100644
index 0000000..824025b
--- /dev/null
+++ b/python/.gitlab-ci.yml
@@ -0,0 +1,49 @@
+
+.pylint_badge: &pylint_badge |
+ echo "{
+ \"PyLintScore\": \"$PyPIScore\"
+ }" > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/badge_pylint.json"
+
+.PyLint:
+ variables:
+ PYLINT_PATH: "/*/python-module/*/*.py"
+ stage: validation
+ before_script:
+ - if [ "0$JOB_ROOT_DIR" == "0" ]; then ROOT_DIR=gitlab-ci; else ROOT_DIR=$JOB_ROOT_DIR ; fi
+ - echo "[DEBUG] ROOT_DIR[$ROOT_DIR]"
+ - mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME"
+ - mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests"
+ - export PYTHON_VERSION=`python -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}.{2}".format(*version))'`
+ - apt update
+ - apt install --no-install-recommends -y git
+ - python3 -m venv env
+ - . env/bin/activate
+ - pip install --upgrade pip
+ - pip install -r $ROOT_DIR/python/requirements.txt
+ - mkdir $PYTHON_VERSION
+ script:
+ - PYLINT_PATH=$ROOT_DIR$PYLINT_PATH
+ - echo "[DEBUG] PYLINT_PATH[$PYLINT_PATH]"
+ - python3 -m pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter $PYLINT_PATH > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/gl-code-quality-report.json"
+
+ - python3 -m pylint --exit-zero --output-format=pylint_gitlab.GitlabPagesHtmlReporter $PYLINT_PATH > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/gl-code-quality-report.html"
+
+ - PyPIScore=$(python3 -m pylint --exit-zero $PYLINT_PATH | sed -n 's/^Your code has been rated at \([-0-9./]*\).*/\1/p')
+
+ - *pylint_badge
+
+
+ after_script:
+ - echo deactivate
+ artifacts:
+ expire_in: 1 days
+ when: always
+ paths:
+ - "artifacts/*"
+ reports:
+ codequality: "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/gl-code-quality-report.json"
+ rules:
+ - if: '$CI_COMMIT_BRANCH'
+ when: always
+ - when: never
+
diff --git a/python/README.md b/python/README.md
new file mode 100644
index 0000000..33802ab
--- /dev/null
+++ b/python/README.md
@@ -0,0 +1,88 @@
+# Python
+This folder (`python`) covers jobs for python development
+
+
+These jobs provides the following badge:
+
+- `PyLint` - code quality [](https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/jobs/artifacts/development/file/artifacts/validation/tests/gl-code-quality-report.html?job=PyLint)
+
+Use the following MD to add a badge adjusting the variables and ensuring everything is on one line.
+``` md
+[](https://gitlab.com/
+
+{project path}
+
+/-/jobs/artifacts/
+
+{branch}
+
+/file/
+
+artifacts/validation/tests/gl-code-quality-report.html
+
+?job=
+
+{Job Name}
+)
+```
+| Variable | Description |
+|:----|:----|
+| `{project path}` | *project path, what's after gitlab.com/* |
+| `{branch}` | *git branch to fetch the score from* |
+| `{Job Name}` | *name of the gitlab-ci job for the linting* |
+
+
+## Dependencies
+
+- None
+
+## your .gitlab-ci.yml changes
+To add the `PyLint` job, add the following to your `.gitlab-ci.yml` file
+
+``` yaml
+stages:
+ - validation
+
+include:
+ - remote: https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/raw/master/python/.gitlab-ci.yml
+
+PyLint:
+ variables:
+ PYLINT_PATH: "/*/*.py"
+ extends:
+ - .PyLint
+ image: python:3.6-slim
+```
+
+
+## CI/CD Variables required
+
+| var name | Description |
+|:----:|:----|
+| PYLINT_PATH | *The path you wish the linter to search for python files* |
+
+
+## Job Workflow
+
+ - This job will lint any yaml file in the specified directory using the specified rules.
+
+## Artifacts
+
+ - `$CI_PROJECT_DIR/artifacts` - Root artifact directory
+ - `$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/gl-code-quality-report.json` - Gitlab code quality report (displays in merge request)
+ - `$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/gl-code-quality-report.html` - html code quality report
+
+## License
+To view the license for this folder and any sub-folders, refer [here](https://gitlab.com/nofusscomputing/projects/gitlab-ci)
diff --git a/python/requirements.txt b/python/requirements.txt
new file mode 100644
index 0000000..bc478a8
--- /dev/null
+++ b/python/requirements.txt
@@ -0,0 +1,2 @@
+pylint==2.9.6
+pylint-gitlab==0.3.0
diff --git a/yaml_lint/.gitlab-ci.yml b/yaml_lint/.gitlab-ci.yml
new file mode 100644
index 0000000..0cd3eb6
--- /dev/null
+++ b/yaml_lint/.gitlab-ci.yml
@@ -0,0 +1,44 @@
+
+.yaml_lint_defaults:
+ variables:
+ YAML_LINT_PATH: "/*.yml"
+ YAML_LINT_CONFIG: "/yaml_lint/.yamllint.yaml"
+ stage: validation
+ before_script:
+ - if [ "0$JOB_ROOT_DIR" == "0" ]; then ROOT_DIR=gitlab-ci; else ROOT_DIR=$JOB_ROOT_DIR ; fi
+ - echo "[DEBUG] ROOT_DIR[$ROOT_DIR]"
+ - mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME"
+ - mkdir -p "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests"
+ - export PYTHON_VERSION=`python -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}.{2}".format(*version))'`
+ - apt update
+ - apt install --no-install-recommends -y git
+ - python3 -m venv env
+ - . env/bin/activate
+ - pip install --upgrade pip
+ - pip install -r $ROOT_DIR/yaml_lint/requirements.txt
+ - mkdir $PYTHON_VERSION
+ script:
+ - YAML_LINT_PATH=$ROOT_DIR$YAML_LINT_PATH
+ - echo "[DEBUG] YAML_LINT_PATH[$YAML_LINT_PATH]"
+ - YAML_LINT_CONFIG=$ROOT_DIR$YAML_LINT_CONFIG
+ - echo "[DEBUG] YAML_LINT_CONFIG[$YAML_LINT_CONFIG]"
+ - yamllint $YAML_LINT_PATH -f parsable -c $ROOT_DIR/yaml_lint/.yamllint.yaml > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-yaml-lint.log" 1>&1 || YAML_LINT=$?
+ - cat "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-yaml-lint.log" | ansible-lint-to-junit-xml > "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$PYTHON_VERSION-yaml-lint.junit.xml"
+ - if [ $YAML_LINT > 0 ]; then echo "YAML lint failed with $YAML_LINT"; exit $YAML_LINT; fi
+ after_script:
+ - echo deactivate
+ artifacts:
+ expire_in: 3 days
+ when: always
+ paths:
+ - "artifacts/*"
+ reports:
+ junit:
+ - "$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/*.junit.xml"
+ rules:
+ - if: '$CI_COMMIT_BRANCH == "master"'
+ when: never
+ - if: '$CI_COMMIT_BRANCH'
+ when: always
+ - when: never
+
diff --git a/yaml_lint/.yamllint.yaml b/yaml_lint/.yamllint.yaml
new file mode 100644
index 0000000..ba30e87
--- /dev/null
+++ b/yaml_lint/.yamllint.yaml
@@ -0,0 +1,26 @@
+---
+extends: default
+
+rules:
+ braces: {max-spaces-inside: 1, level: error}
+ brackets: {max-spaces-inside: 1, level: error}
+ colons: {max-spaces-after: -1, level: error}
+ commas: {max-spaces-after: -1, level: error}
+ comments: disable
+ comments-indentation: disable
+ document-start: disable
+ empty-lines:
+ max: 2
+ max-start: 1
+ max-end: 1
+ level: error
+ hyphens: {level: error}
+# indentation: disable
+ indentation:
+ spaces: consistent
+ key-duplicates: enable
+ line-length: disable
+ new-line-at-end-of-file: disable
+ new-lines: {type: unix}
+ trailing-spaces: disable
+ truthy: disable
diff --git a/yaml_lint/README.md b/yaml_lint/README.md
new file mode 100644
index 0000000..03fddc6
--- /dev/null
+++ b/yaml_lint/README.md
@@ -0,0 +1,52 @@
+# Yaml Lint
+This job does yaml linting when any commit is pushed to any branch.
+
+
+This job provides the following badge:
+
+- None
+
+## Dependencies
+
+- None
+
+## your .gitlab-ci.yml changes
+To use this job add the following to your `.gitlab-ci.yml` file
+
+``` yaml
+stages:
+ - validation
+
+include:
+ - remote: https://gitlab.com/nofusscomputing/projects/gitlab-ci/-/raw/master/yaml_lint/.gitlab-ci.yml
+
+Yaml Lint (python 3.6):
+ variables:
+ YAML_LINT_PATH: "roles/"
+ YAML_LINT_CONFIG: ".yamllint.yaml"
+ extends:
+ - .yaml_linter_defaults
+ image: python:3.6-slim
+```
+> You can use any python version you wish.
+
+## CI/CD Variables required
+
+| var name | Description |
+|:----:|:----|
+| YAML_LINT_PATH | *The path you wish the linter to search for yaml files* |
+| YAML_LINT_CONFOG | *The path you have stored the yaml config file in* |
+
+
+## Job Workflow
+
+ - This job will lint any yaml file in the specified directory using the specified rules.
+
+## Artifacts
+
+ - `$CI_PROJECT_DIR/artifacts` - Root artifact directory
+ - `$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/tests/$PYTHON_VERSION-yaml-lint.junit.xml` - JUnit Test report
+ - `$CI_PROJECT_DIR/artifacts/$CI_JOB_STAGE/$CI_JOB_NAME/$PYTHON_VERSION-yaml-lint.log` - Linter log
+
+## License
+To view the license for this folder and any sub-folders, refer [here](https://gitlab.com/nofusscomputing/projects/gitlab-ci)
diff --git a/yaml_lint/requirements.txt b/yaml_lint/requirements.txt
new file mode 100644
index 0000000..1013116
--- /dev/null
+++ b/yaml_lint/requirements.txt
@@ -0,0 +1,2 @@
+yamllint
+ansible-lint-to-junit-xml