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

ci: Add UI inputs for Update helm charts job, refactor and drop need for crds_asset_id #400

Merged
merged 6 commits into from
Mar 14, 2024

Conversation

viccuad
Copy link
Member

@viccuad viccuad commented Mar 13, 2024

Description

Fix #307

Changes:

  • Add UI inputs when workflow triggered as workflow_dispatch.
    Given that the values can come from repository_dispatch (other repos) or workflow_dispatch (UI button), add a new setvariables job, that sets its job outputs to the corresponding values obtained from the payload of the repository_dispatch or from the inputs of the workflow_dispatch.
    It is needed to use job outputs as is the only way to pass values between jobs, as jobs are run in their own VM instances and don't share the env.
    Make the following jobs depend on it with needs: setvariables.
    The javascript script from actions/github-script cannot read job outputs. Hence, add a step that reads the needs.setvariables.outputs and creates env vars. Consume those env vars in js as process.env.foo.
  • refactor: Calculate crds_asset_id by querying GH instead of passing it from the job.
  • refactor: Remove 2 repetitions of install_crds.sh, call update_cli/scripts/install_crds.sh.

image

Test

Major/minor release update run: https://github.com/viccuad/helm-charts/actions/runs/8263364335
Patch release update run: https://github.com/viccuad/helm-charts/actions/runs/8263508789/job/22605107087

Also, tested updatecli/scripts/install_crds.sh locally, with various /tmp/crds-{controller,audit-scanner}.tar.gz.

Additional Information

Tradeoff

Potential improvement

I don't like the added complexity created by adding the workflow_dispatch inputs, and needing to pass it to the js scripts via GH env vars, but it is what it is.

About the refactors, I'm happy splitting the commits in several PRs. I tested it altogether to save time. If they aren't wanted they can be dropped, or we can go with #399.

viccuad added 5 commits March 13, 2024 11:43
Add UI inputs when workflow triggered as `workflow_dispatch`.

Given that the values can come from `repository_dispatch` (other repos)
or `workflow_dispatch` (UI button), add a new `setvariables` job, that
sets its job outputs to the corresponding values obtained from the
payload of the repository_dispatch or from the inputs of the
workflow_dispatch.
It is needed to use job outputs as is the only way to pass values
between jobs, as jobs are run in their own VM instances and don't share
the env.

Make the following jobs depend on it with `needs: setvariables`.

The javascript script from actions/github-script cannot read job
outputs. Hence, add a step that reads the `needs.setvariables.outputs`
and creates env vars. Consume those env vars in js as
`process.env.foo`.

Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Instead of consuming the crds_asset_id from workflow inputs, query the
repos to obtain the asset id, and use that id to download the
CRDs.tar.gz.

Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Also, we don't need a js script to set them.

Signed-off-by: Víctor Cuadrado Juan <[email protected]>
This simplifies testing, one can create
/tmp/crds-{controller,audit-scanner}.tar.gz and run the script locally.

Signed-off-by: Víctor Cuadrado Juan <[email protected]>
Signed-off-by: Víctor Cuadrado Juan <[email protected]>
@viccuad viccuad requested a review from a team as a code owner March 13, 2024 11:04
@viccuad viccuad changed the title ci: Add UI inputs for "Update helm charts" job, ci: Add UI inputs for Update helm charts job, refactor and drop need for crds_asset_id Mar 13, 2024
core.exportVariable("UPDATECLI_CHART_VERSION", context.payload.client_payload.version)
- name: create env vars from needs.setvariables.outputs
# This is neeeded because in scripts, we don't have a way to access the `needs` json object.
# The env vars defined here will be accesible in the scripts under `process.env.foo`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be possible to drop this step, not save the vars as env vars, and in the script parse the needs.setvariables.outputs string into json.
So instead of let version = process.env.version do
let version = JSON.parse( ' ${{ needs.setvariables.outputs }} ' ).version.
But I couldn't get it to work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave it around

@viccuad
Copy link
Member Author

viccuad commented Mar 13, 2024

Updated input fields from review:

Screenshot_2024-03-13_18-34-23

Copy link
Member

@flavio flavio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix

core.exportVariable("UPDATECLI_CHART_VERSION", context.payload.client_payload.version)
- name: create env vars from needs.setvariables.outputs
# This is neeeded because in scripts, we don't have a way to access the `needs` json object.
# The env vars defined here will be accesible in the scripts under `process.env.foo`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave it around

@viccuad viccuad merged commit 80ba9ef into kubewarden:main Mar 14, 2024
3 checks passed
@viccuad viccuad deleted the refactor-update-charts branch March 14, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow triggering the chart update job using Github UI
3 participants