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

Siteops 1328 remove file from upsteam #7

Merged
merged 10 commits into from
Jan 4, 2024
153 changes: 87 additions & 66 deletions .github/workflows/test-local-action.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
48 changes: 36 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/
```
17 changes: 17 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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