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

feat: Add conditional Target #1962

Merged
merged 6 commits into from
Feb 28, 2024
Merged

feat: Add conditional Target #1962

merged 6 commits into from
Feb 28, 2024

Conversation

olblak
Copy link
Member

@olblak olblak commented Feb 27, 2024

Fix #1385

Allow to conditionally execute target.
if disablecondition is true then we ignore condition result for that target if conditionids has at least one valid conditionid then we only monitor that condition result

Test

To test this pull request, you can run the following commands:

go build -o bin/updatecli .
./bin/updatecli diff --config e2e/updatecli.d/success.d/conditionalTarget.yaml
Command Output
/bin/updatecli diff --config e2e/updatecli.d/success.d/conditionalTarget.yaml


+++++++++++
+ PREPARE +
+++++++++++

Loading Pipeline "e2e/updatecli.d/success.d/conditionalTarget.yaml"
WARNING: Updatecli binary version is unset. This means you are using a development version that ignores manifest version constraint.

SCM repository retrieved: 0


++++++++++++++++++
+ AUTO DISCOVERY +
++++++++++++++++++



++++++++++++
+ PIPELINE +
++++++++++++



##########################
# CONDITIONALTARGET.YAML #
##########################


CONDITIONS:
===========

failed
------
The shell 🐚 command "/bin/sh /tmp/updatecli/bin/fcbcf165908dd18a9e49f7ff27810176db8e9f63b4352213741664245224f8aa.sh" exited on error (exit code 1) with the following output:
----
----

command stderr output was:
----
----
ERROR: shell command failed. Expected exit code 0 but got 1

succeed
-------
The shell 🐚 command "/bin/sh /tmp/updatecli/bin/b5bea41b6c623f7c09f1bf24dcae58ebab3c0cdd90ad966bc43a45b44867e12b.sh" ran successfully with the following output:
----
----
βœ” shell condition of type "exitcode", passing


TARGETS
========

conditionFailed
---------------
Conditions [failed] not met. Skipping execution of the target["conditionFailed"]

succeed
-------

**Dry Run enabled**

The shell 🐚 command "/bin/sh /tmp/updatecli/bin/fbaba22b211f613db85316489b4d98e5c3eda2ed0c2956050d46dac55993ffa6.sh" ran successfully with the following output:
----
this should run
----
⚠ - ran shell command "echo 'this should run'"

neverrun
--------
Conditions [failed] not met. Skipping execution of the target["neverrun"]

alwaysrun
---------

**Dry Run enabled**

The shell 🐚 command "/bin/sh /tmp/updatecli/bin/84991134d75be86fb1e72fba5fc8541d4d5cee42e9d9fa32df3f66341f9ace3b.sh" ran successfully with the following output:
----
this should always run
----
⚠ - ran shell command "echo 'this should always run'"

=============================

REPORTS:



⚠ CONDITIONALTARGET.YAML:
	Condition:
		βœ— [failed] 
		βœ” [succeed] 
	Target:
		⚠ [alwaysrun] Target always executed because condition checking is disabled
		- [conditionFailed] Target shouldn't be executed as depend on condition failed
		- [neverrun] Target skipped because all conditions must succeed
		⚠ [succeed] Target should be executed as depends on condition succeed


Run Summary
===========
Pipeline(s) run:
  * Changed:	1
  * Failed:	0
  * Skipped:	0
  * Succeeded:	0
  * Total:	1


Additional Information

Tradeoff

Potential improvement

Allow to conditionally execute target
if `disablecondition` is true then we ignore condition result for that target
if `conditionids` has at least one valid `conditionid` then we only monitor that condition result

Signed-off-by: Olblak <me@olblak.com>
@olblak olblak added enhancement New feature or request core All things related to Updatecli core engine labels Feb 27, 2024
olblak and others added 4 commits February 27, 2024 18:11
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
@olblak
Copy link
Member Author

olblak commented Feb 28, 2024

Note that this pullrequest will allow to have interesting Updatecli scenario like for handling GitHub action workflow

updatecli.yaml
name: Bump updatecli/updatecli-action GitHub workflow

scms:
  git:
    kind: git
    spec:
      url: https://github.com/updatecli/updatecli-action

sources:
  release:
    name: Get latest GitHub Release for updatecli/updatecli-action
    kind: githubrelease
    spec:
      owner: updatecli
      repository: updatecli-action
      token: '{{ requiredEnv "GITHUB_TOKEN" }}'

  tag:
    name: Get latest tag for updatecli/updatecli-action
    kind: gittag
    scmid: git
    spec:
      versionfilter:
        kind: semver

  branch:
    name: Get latest branch for updatecli/updatecli-action
    kind: gitbranch
    scmid: git
    spec:
      versionfilter:
        kind: semver

conditions:
  release:
    name: Get latest GitHub Release for updatecli/updatecli-action
    kind: githubrelease
    disablesourceinput: true
    spec:
      owner: updatecli
      repository: updatecli-action
      token: '{{ requiredEnv "GITHUB_TOKEN" }}'
      tag: "v2"

  tag:
    name: Get latest tag for updatecli/updatecli-action
    kind: gittag
    scmid: git
    disablesourceinput: true
    spec:
      versionfilter:
        kind: semver
      tag: "v2"

  branch:
    name: Get latest branch for updatecli/updatecli-action
    kind: gitbranch
    scmid: git
    disablesourceinput: true
    spec:
      versionfilter:
        kind: semver
      branch: "v2"

targets:
  release:
    name: 'deps(github): bump GitHub action release for updatecli/updatcli-action to {{ source "release" }}'
    kind: yaml
    sourceid: release
    conditionids:
      - release
    transformers:
      - addprefix: '"updatecli/updatecli-action@'
      - addsuffix: '"'
    spec:
      file: .github/workflows/updatecli.yaml
      key: '$.jobs.updatecli.steps[1].uses'

  tag:
    name: 'deps(github): bump GitHub action tag for updatecli/updatcli-action to {{ source "tag" }}'
    kind: yaml
    sourceid: tag
    conditionids:
      - tag
    transformers:
      - addprefix: '"updatecli/updatecli-action@'
      - addsuffix: '"'
    spec:
      file: .github/workflows/updatecli.yaml
      key: '$.jobs.updatecli.steps[1].uses'

  branch:
    name: 'deps(github): bump GitHub action branch for updatecli/updatcli-action to {{ source "branch" }}'
    kind: yaml
    sourceid: branch
    conditionids:
      - branch
    transformers:
      - addprefix: '"updatecli/updatecli-action@'
      - addsuffix: '"'
    spec:
      file: .github/workflows/updatecli.yaml
      key: '$.jobs.updatecli.steps[1].uses'

Console Output
./bin/updatecli diff --config e2e/updatecli.d/success.d/githubWorkflow.yaml


+++++++++++
+ PREPARE +
+++++++++++

Loading Pipeline "e2e/updatecli.d/success.d/githubWorkflow.yaml"
WARNING: Updatecli binary version is unset. This means you are using a development version that ignores manifest version constraint.

SCM repository retrieved: 1


++++++++++++++++++
+ AUTO DISCOVERY +
++++++++++++++++++



++++++++++++
+ PIPELINE +
++++++++++++



###################################################
# BUMP UPDATECLI/UPDATECLI-ACTION GITHUB WORKFLOW #
###################################################


SOURCES
=======

tag
---
Searching for version matching pattern "*"
βœ” Git tag "v2.55.0" found matching pattern "*" of kind "semver"

release
-------
Searching for version matching pattern "latest"
βœ” GitHub release version "v2.55.0" found matching pattern "latest" of kind "latest"


CHANGELOG:
----------

Release published on the 2024-02-17 19:22:30 +0000 UTC at the url https://github.com/updatecli/updatecli-action/releases/tag/v2.55.0

## WARNING 
This release introduces a few important changes. 

**Ephemeral branch**

The ephemeral branch created by Updatecli before opening a pullrequest or merge request changes its format to include the base branch, more information [here](https://github.com/updatecli/updatecli/issues/1897) about why this change is needed.
The consequence of this, is that every pull requests or merge requests created by Updatecli before 0.73.0 will become orphan. They can be closed as Updatecli will recreate them with the new ephemeral branch format.

**Autodiscovery updating container tag**

The Autodiscovery plugins for Helm, Dockerfile, and docker compose have been improved to also include the image digest by default. 

So 

1. `updatecli/updatecli:latest` will be updated to  `updatecli/updatecli:latest@sha256xxxx`
2. `updatecli/updatecli:0.23.0` to `updatecli/updatecli:0.73.0@sha256xxx`
3. `updatecli/updatecli:0.23.0@sha256xxx` to `updatecli/updatecli:0.73.0@sha256yyy`

Docker image using digest without specifying the tag will be ignored.

This behavior can be disabled using the parameter `digest` set to `false` such as in the following example:

autodiscovery:
  scmid: default
  crawlers:
    helm:
      digest: false

## Changes

- Bump updatecli version to v0.73.0 @github-actions (#501)
- chore(deps): Bump tibdex/github-app-token from 1.8.2 to 2.1.0 @dependabot (#458)
- Bump All NPM package version @github-actions (#497)
- chore(deps): Bump release-drafter/release-drafter from 5 to 6 @dependabot (#499)
- chore(deps): Bump actions/setup-node from 4.0.1 to 4.0.2 @dependabot (#500)
- chore(deps): Bump @actions/core from 1.10.0 to 1.10.1 @dependabot (#446)

## Contributors

@dependabot, @dependabot[bot], @github-actions and @github-actions[bot]


branch
------
Searching for version matching pattern "*"
βœ” git branch "v2" found matching pattern "*"


CONDITIONS:
===========

branch
------
βœ” git branch "v2" matching

tag
---
Searching for version matching pattern "*"
βœ— git tag "*" not matching "v2.55.0"

release
-------
βœ— GitHub release "v2" not found


TARGETS
========

tag
---
Conditions [tag] not met. Skipping execution of the target["tag"]

release
-------
Conditions [release] not met. Skipping execution of the target["release"]

branch
------

**Dry Run enabled**

βœ” - no change detected:
	* key "$.jobs.updatecli.steps[1].uses" already set to "\"updatecli/updatecli-action@v2\"", from file ".github/workflows/updatecli.yaml"

=============================

REPORTS:



βœ” Bump updatecli/updatecli-action GitHub workflow:
	Source:
		βœ” [branch] Get latest branch for updatecli/updatecli-action
		βœ” [release] Get latest GitHub Release for updatecli/updatecli-action
		βœ” [tag] Get latest tag for updatecli/updatecli-action
	Condition:
		βœ” [branch] Get latest branch for updatecli/updatecli-action
		βœ— [release] Get latest GitHub Release for updatecli/updatecli-action
		βœ— [tag] Get latest tag for updatecli/updatecli-action
	Target:
		βœ” [branch] deps(github): bump GitHub action branch for updatecli/updatcli-action to v2
		- [release] deps(github): bump GitHub action release for updatecli/updatcli-action to v2.55.0
		- [tag] deps(github): bump GitHub action tag for updatecli/updatcli-action to v2.55.0


Run Summary
===========
Pipeline(s) run:
  * Changed:	0
  * Failed:	0
  * Skipped:	0
  * Succeeded:	1
  * Total:	1

Signed-off-by: Olblak <me@olblak.com>
@olblak olblak merged commit 2fcb691 into updatecli:main Feb 28, 2024
6 checks passed
@olblak olblak deleted the issue/1385 branch April 3, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core All things related to Updatecli core engine enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Conditional Target
1 participant