-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from logchange/5-system-env-variables
Allow using system environment variables creating valhalla.yml
- Loading branch information
Showing
4 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
FROM alpine:3 | ||
|
||
# Labels. | ||
LABEL org.opencontainers.image.authors='[email protected]' \ | ||
org.opencontainers.image.url='https://github.com/logchange/valhalla' \ | ||
org.opencontainers.image.documentation='https://github.com/logchange/valhalla/blob/master/README.md' \ | ||
org.opencontainers.image.source='https://github.com/logchange/valhalla' \ | ||
org.opencontainers.image.vendor='The logchange Community' \ | ||
org.opencontainers.image.licenses='Apache-2.0' | ||
|
||
RUN apk --update --no-cache add \ | ||
bash \ | ||
git \ | ||
|
This file contains 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 |
---|---|---|
|
@@ -40,10 +40,10 @@ commit_before_release: # define actions which have to happen before release and | |
username: Test1234 # git config username | ||
email: [email protected] # git config email | ||
msg: Releasing version {VERSION} # commit message, you can use string predefined variables | ||
before: # list of bash commands, you can use string predefined variables | ||
before: # list of bash commands, you can use string predefined variables, custom variables or system environment variables! | ||
- echo "test" > some_file4.md | ||
- mkdir -p changelog/v{VERSION} | ||
- echo "Super release description for tests" > changelog/v{VERSION}/version_summary.md | ||
- echo "Super release description for tests generated at {CI_COMMIT_TIMESTAMP}" > changelog/v{VERSION}/version_summary.md | ||
# definition of release which will be created | ||
release: | ||
description: | ||
|
@@ -128,6 +128,14 @@ which will be overriden in child `valhalla.yml`.** | |
| `VERSION` | value extracted from branch name, for `release-1.2.14` it will be `1.2.14` | | ||
| `VALHALLA_TOKEN` | token passed to CI runner which execute this job | | ||
|
||
### 🐛 Environment variables | ||
|
||
Valhalla allows you to use any variable defined in your environment system, it is useful f.e when you | ||
are using GitLab CI/CD and you want to use [GitLab CI/CD predefined variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html) | ||
in your `valhalla.yml`. | ||
|
||
**Use `{}` to evaluate variable to value f.e. `{HOME}`** | ||
|
||
### 🦊 .gitlab-ci.yml | ||
|
||
- if using GitLab workflows | ||
|
@@ -136,16 +144,23 @@ which will be overriden in child `valhalla.yml`.** | |
|
||
```yml | ||
# Modify your workflow rules to include rule to start pipeline for branch starting with name | ||
# release- and exclude commits with VALHALLA SKIP (when valhalla commits files we don't want to start pipeline again) | ||
workflows: | ||
# .... your standard workflows here | ||
- if: $CI_COMMIT_BRANCH =~ /^release-*/ && $CI_COMMIT_TITLE !~ /.*VALHALLA SKIP.*/ | ||
# add new stage | ||
stages: | ||
# .... your standard stages here | ||
- release | ||
valhalla_release: | ||
stage: release | ||
image: logchange/valhalla:1.2.1 | ||
image: logchange/valhalla:1.3.0 | ||
# Prevent from fetching artifacts because it is a problem during committing all files (git add .) | ||
# https://docs.gitlab.com/ee/ci/jobs/job_artifacts.html#prevent-a-job-from-fetching-artifacts | ||
dependencies: [] | ||
rules: | ||
- if: $CI_PIPELINE_SOURCE == "merge_request_event" | ||
when: never | ||
|
@@ -158,7 +173,12 @@ valhalla_release: | |
``` | ||
### 🚧 .gitignore | ||
|
||
Add to your `.gitignore` following rules, please create issue if valhalla commits to much files! | ||
Add to your `.gitignore` following rules, please create issue if valhalla commits to many files! | ||
(For GitLab CI/CD add `dependencies: []` which will prevent from committing generated files) | ||
|
||
It is important to modify your `.gitignore` when valhalla during `commit_before_release` or | ||
`commit_after_release` phase generates files which you don't want to commit (f.e. maven release plugin or | ||
maven version plugin generates `pom.xml` backup - for mvn version you can also use `-DgenerateBackupPoms=false`) | ||
|
||
``` | ||
### Valhalla ### | ||
|
This file contains 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,42 @@ | ||
import os | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from valhalla.common.resolver import resolve, init_str_resolver, init_str_resolver_custom_variables | ||
|
||
|
||
class TestStringResolver(unittest.TestCase): | ||
|
||
def test_resolve_predefined(self): | ||
# given: | ||
init_str_resolver("1.0", "token123") | ||
init_str_resolver_custom_variables({"CUSTOM_VAR": "value123"}) | ||
|
||
# when: | ||
resolved_string = resolve("Testing {VERSION}") | ||
|
||
# then: | ||
self.assertEqual("Testing 1.0", resolved_string) | ||
|
||
def test_resolve_custom_variables(self): | ||
# given: | ||
init_str_resolver("1.0", "token123") | ||
init_str_resolver_custom_variables({"CUSTOM_VAR": "value123"}) | ||
|
||
# when: | ||
resolved_string = resolve("Testing {CUSTOM_VAR}") | ||
|
||
# then: | ||
self.assertEqual("Testing value123", resolved_string) | ||
|
||
@patch.dict(os.environ, {"ENV_VAR": "env_value123"}) | ||
def test_resolve_from_env(self): | ||
# given: | ||
init_str_resolver("1.0", "token123") | ||
init_str_resolver_custom_variables({"CUSTOM_VAR": "value123"}) | ||
|
||
# when: | ||
resolved_string = resolve("Testing {ENV_VAR}") | ||
|
||
# then: | ||
self.assertEqual("Testing env_value123", resolved_string) |
This file contains 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