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

BUD-3634 add input to copy paths to env branch #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ inputs:
deploy-pr/<environment> branch and open a PR for review
required: false
default: .*(staging|production).*
include-paths:
description: |
Copy specified paths to branch.
Input format: JSON list of objects string with fields: if, source and target.
Example: [{"if": true, "source": "path/to/source1", "target": "path/to/target1"}]

Choose a reason for hiding this comment

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

  • is this is a folder or a file?
  • what is the if for?
  • may it happen that source and target path are different?
  • is this a relative path? relative to what?

can we do something like

 include-paths:
  - source: local/path
    target: target/folder1
  - source: local/path2
    target: target/folder2

can we even copy files to the root target folder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is this is a folder or a file?
can be folder or a file

what is the if for?
if is used to add some condition if needed, for example if we want to copy files for wf-budget service but do not want for others

may it happen that source and target path are different?
yes, it's going to be different

is this a relative path? relative to what?
path should be relative to repository root

can we do something like
no, github action input do not support objects, we need to use JSON

can we even copy files to the root target folder?
it should be root of the repo, so should not be any problem

Choose a reason for hiding this comment

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

no, github action input do not support objects, we need to use JSON
you mean Github Actions is yaml based and does not understand yaml lists as parameters?
what about https://stackoverflow.com/questions/65345432/github-actions-pass-list-of-variables-to-shell-script ?

if is used to add some condition if needed, for example if we want to copy files for wf-budget service but do not want for others
oh, right : we would need to add it here https://github.com/OpenGov/k8s-deployment-bnp/blob/main/.github/workflows/render-manifests.yaml#L83 and it would need a per project config so you could do something like

include-paths: [{"if": matrix.env == "wf-budget", "source": "path/to/source1", "target": "path/to/target1"}]

like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you mean Github Actions is yaml based and does not understand yaml lists as parameters?
yaml in general supports lists or object but GH action inputs do not. https://stackoverflow.com/questions/75420197/how-to-use-array-input-for-a-custom-github-actions
I've tried to search in stackoverflow and ask ChatGPT but it only proposes to use JSON

like that?
yes, that's correct

required: false
default: '[]'
dry-run:
description: |
On a dry-run only the kustomize build will occur and the built branch will
Expand Down Expand Up @@ -110,7 +117,7 @@ runs:
- name: Branch and stage
shell: bash
working-directory: ${{ inputs.working-directory }}
run: branch-and-stage.sh
run: branch-and-stage.sh '${{ inputs.include-paths }}'

- name: Git diff against ${{ env.DIFF_BRANCH }}
shell: bash
Expand Down
39 changes: 39 additions & 0 deletions branch-and-stage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@

source "${GITHUB_ACTION_PATH}/util.sh"

pathsToCopy="$1"
schmidtjohannes marked this conversation as resolved.
Show resolved Hide resolved

copy() {
local row=$1
local render_dir=$2

_jq() {
echo ${row} | jq -r ${1}
}

copy=$(_jq '.if')
source=$(_jq '.source')
target=$(_jq '.target')

if [ "${copy}" = true ]; then
if [ $3 = "from_render" ]; then
echo "Copying to ./${target}"
mkdir -p $(dirname "./${target}") && cp -r "${render_dir}/${target}" "./${target}"
git add "./${target}"
else
echo "Copying to ${render_dir}/${target}"
mkdir -p $(dirname "${render_dir}/${target}") && cp -r "${source}" "${render_dir}/${target}"
fi
else
echo "Skipping copy for ${source}"
fi
}

# Copy paths to render dir
echo Start copy include paths to rendered manifest
for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do
copy "${row}" "${RENDER_DIR}"
done

# Base changes off the branch being deployed to
set +e
# If the branch exists, check it out
Expand Down Expand Up @@ -49,3 +83,8 @@ else
# git add the removed files; hopefully no yaml pollution
git add --all -fv .
fi

# Copy from render dir to branch
for row in $(echo "${pathsToCopy}" | jq -c '.[]'); do
schmidtjohannes marked this conversation as resolved.
Show resolved Hide resolved
copy "${row}" "${RENDER_DIR}" "from_render"
done