diff --git a/.github/workflows/test-local-action.yaml b/.github/workflows/test-local-action.yaml index c5d5ff2..ab2f7fc 100644 --- a/.github/workflows/test-local-action.yaml +++ b/.github/workflows/test-local-action.yaml @@ -1,75 +1,96 @@ on: [push] jobs: - local_test_lasttag: - runs-on: ubuntu-latest - name: Test local action without fixed version - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Test local action - id: local-action - uses: ./ - with: - upstream_repo: sysdiglabs/kube-psp-advisor - local_patch_dir: tests/sysdiglabs/kube-psp-advisor - outputs: - used_tag: ${{ steps.local-action.outputs.tag }} - used_latest: ${{ steps.local-action.outputs.latest }} - tag_major: ${{ steps.local-action.outputs.tag_major }} - tag_minor: ${{ steps.local-action.outputs.tag_minor }} - tag_patch: ${{ steps.local-action.outputs.tag_patch }} + local_test_lasttag: + runs-on: ubuntu-latest + name: Test local action without fixed version + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test local action + id: local-action + uses: ./ + with: + upstream_repo: sysdiglabs/kube-psp-advisor + local_patch_dir: tests/sysdiglabs/kube-psp-advisor + outputs: + used_tag: ${{ steps.local-action.outputs.tag }} + used_latest: ${{ steps.local-action.outputs.latest }} + tag_major: ${{ steps.local-action.outputs.tag_major }} + tag_minor: ${{ steps.local-action.outputs.tag_minor }} + tag_patch: ${{ steps.local-action.outputs.tag_patch }} - local_test_fixed: - runs-on: ubuntu-latest - name: Test local action with fixed version - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Test local action - id: local-action - uses: ./ - with: - upstream_repo: sysdiglabs/kube-psp-advisor - local_patch_dir: tests/sysdiglabs/kube-psp-advisor - upstream_ref: master - outputs: - used_tag: ${{ steps.local-action.outputs.tag }} - used_latest: ${{ steps.local-action.outputs.latest }} - tag_major: ${{ steps.local-action.outputs.tag_major }} - tag_minor: ${{ steps.local-action.outputs.tag_minor }} - tag_patch: ${{ steps.local-action.outputs.tag_patch }} + local_test_fixed: + runs-on: ubuntu-latest + name: Test local action with fixed version + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test local action + id: local-action + uses: ./ + with: + upstream_repo: sysdiglabs/kube-psp-advisor + local_patch_dir: tests/sysdiglabs/kube-psp-advisor + upstream_ref: master + outputs: + used_tag: ${{ steps.local-action.outputs.tag }} + used_latest: ${{ steps.local-action.outputs.latest }} + tag_major: ${{ steps.local-action.outputs.tag_major }} + tag_minor: ${{ steps.local-action.outputs.tag_minor }} + tag_patch: ${{ steps.local-action.outputs.tag_patch }} - local_test_upstream_remove_files: - runs-on: ubuntu-latest - name: Test local action with upstream_remove_files set - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Test local action - id: local-action - uses: ./ - with: - upstream_repo: sysdiglabs/kube-psp-advisor - local_patch_dir: tests/sysdiglabs/kube-psp-advisor - upstream_ref: master - upstream_remove_files: | + print_results: + runs-on: ubuntu-latest + name: Print test results + needs: [local_test_lasttag, local_test_fixed] + steps: + - run: | + echo "local_test_lasttag: ${{ needs.local_test_lasttag.outputs.used_tag }},${{ needs.local_test_lasttag.outputs.used_latest }}" + echo "local_test_fixed: ${{ needs.local_test_fixed.outputs.used_tag }},${{ needs.local_test_fixed.outputs.used_latest }}" + echo "semver_fixed: ${{ needs.local_test_fixed.outputs.tag_major }}, ${{ needs.local_test_fixed.outputs.tag_minor }}, ${{ needs.local_test_fixed.outputs.tag_patch }}" + echo "semver_lasttag: ${{ needs.local_test_lasttag.outputs.tag_major }}, ${{ needs.local_test_lasttag.outputs.tag_minor }}, ${{ needs.local_test_lasttag.outputs.tag_patch }}" + shell: bash + + local_test_upstream_remove_files: + runs-on: ubuntu-latest + name: Test local action with upstream_remove_files set + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test local action + id: local-action + uses: ./ + with: + upstream_repo: sysdiglabs/kube-psp-advisor + local_patch_dir: tests/sysdiglabs/kube-psp-advisor + upstream_ref: master + upstream_remove_files: | version comparator/comparator.go - - name: Assert that files are removed - id: test-remove - run: |- + - name: Assert that files are removed + id: test-remove + run: |- ! [[ -f upstream/version ]] && ! [[ -f upstream/comparator/comparator.go ]] - shell: bash + shell: bash - print_results: - runs-on: ubuntu-latest - name: Print test results - needs: [local_test_lasttag, local_test_fixed] - steps: - - run: | - echo "local_test_lasttag: ${{ needs.local_test_lasttag.outputs.used_tag }},${{ needs.local_test_lasttag.outputs.used_latest }}" - echo "local_test_fixed: ${{ needs.local_test_fixed.outputs.used_tag }},${{ needs.local_test_fixed.outputs.used_latest }}" - echo "semver_fixed: ${{ needs.local_test_fixed.outputs.tag_major }}, ${{ needs.local_test_fixed.outputs.tag_minor }}, ${{ needs.local_test_fixed.outputs.tag_patch }}" - echo "semver_lasttag: ${{ needs.local_test_lasttag.outputs.tag_major }}, ${{ needs.local_test_lasttag.outputs.tag_minor }}, ${{ needs.local_test_lasttag.outputs.tag_patch }}" - shell: bash + local_test_copy_from_upstream: + runs-on: ubuntu-latest + name: Test local action with upstream_copy set + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test local action + id: local-action + uses: ./ + with: + upstream_repo: sysdiglabs/kube-psp-advisor + local_patch_dir: tests/sysdiglabs/kube-psp-advisor + upstream_ref: master + upstream_copy: | + generator/* tests/ + - name: Assert that files are copied + id: test-copy + run: |- + [[ -f tests/generator.go ]] && [[ -f tests/generator_test.go ]] + shell: bash diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ed1357..7313b28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.4.0" + rev: "v4.5.0" hooks: - id: check-added-large-files - id: check-case-conflict @@ -11,7 +11,7 @@ repos: - id: trailing-whitespace args: ['--markdown-linebreak-ext=md,txt,gotmpl'] - repo: https://github.com/python-jsonschema/check-jsonschema - rev: "0.22.0" + rev: "0.27.3" hooks: - id: check-dependabot - id: check-github-actions diff --git a/README.md b/README.md index daa87cb..3695e07 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,10 @@ Checkout the ref (or latest) upstream version and apply one or more patch files ### Optional -- `upstream_ref`: The upstream ref, can be: branch, tag, sha, if not provided last semver tag will be grabbed automatically -- `upstream_tag_regex`: Regex to use while checking the last upstream versions -- `upstream_remove_files`: Line separated list of files to remove from upstream repository +- `upstream_ref`: The upstream ref, can be: branch, tag, sha, if not provided last semver tag will be grabbed automatically. +- `upstream_tag_regex`: Regex to use while checking the last upstream versions. +- `upstream_remove_files`: Line separated list of files to remove from upstream repository. +- `upstream_copy`: Line separated pair of source directory from upstream repository and destinations. The fields are passed as is to the cp command. ## Outputs @@ -27,23 +28,46 @@ Checkout the ref (or latest) upstream version and apply one or more patch files ## Example workflow -Perform all checks on pull requests +Patch files from upstream repository ```yaml -name: Checkout and Patch +jobs: + build: + steps: + - uses: draios/infra-action-patch-upstream@v0.0.6 + with: + upstream_repo: sysdiglabs/charts + local_patch_dir: tests/sysdiglabs/charts + upstream_ref: master +``` + +Patch files from upstream repository and remove some not needed files -on: - pull_request: - types: [opened, edited, synchronize, reopened] - paths: - - 'containers/**' +```yaml +jobs: + build: + steps: + - uses: draios/infra-action-patch-upstream@v0.0.6 + with: + upstream_repo: sysdiglabs/charts + local_patch_dir: tests/sysdiglabs/charts + upstream_ref: master + upstream_remove_files: | + scripts/cluster-scanner/README.md + scripts/cluster-scanner/generate_kubeconfig.sh +``` + +Patch files from upstream repository and copy files to custom locations + +```yaml jobs: build: - runs-on: self-hosted steps: - - uses: draios/infra-action-patch-upstream@v1 + - uses: draios/infra-action-patch-upstream@v0.0.6 with: upstream_repo: sysdiglabs/charts local_patch_dir: tests/sysdiglabs/charts upstream_ref: master + upstream_copy: | + scripts/cluster-scanner/* k8s/ ``` diff --git a/action.yml b/action.yml index 794d99d..8d69669 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,10 @@ inputs: description: "Line separated list of files to remove from upstream repository" required: false + upstream_copy: + description: "Line separated pair of source directory from upstream and destinations. The fields are passed as is to the cp command" + required: false + runs: using: "composite" steps: @@ -105,3 +109,16 @@ runs: for file in ${FILES}; do [[ -f "upstream/${file}" ]] && rm -v "upstream/${file}" || true done + + - name: Copy from upstream to chart + id: upstream_copy + if: ${{ inputs.upstream_copy != '' }} + shell: bash + run: | + MAPPINGS=$(echo "${{ inputs.upstream_copy }}") + echo "${MAPPINGS}" | while read mapping; do + SRC=$(echo "$mapping" | awk '{print $1}') + DST=$(echo "$mapping" | awk '{print $2}') + echo Copying from ${SRC} to ${DST} + cp -Rv upstream/${SRC} "${DST}" + done