Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brokenpip3 committed Jan 25, 2022
0 parents commit f69cdbf
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test-local-action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on: [push]

jobs:
local_test_lasttag:
runs-on: ubuntu-latest
name: Test local action without fixed version
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test local action
uses: ./
with:
upstream_repo: sysdiglabs/charts
local_patch_dir: tests/sysdiglabs/charts

local_test_fixed:
runs-on: ubuntu-latest
name: Test local action with fixed version
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test local action
uses: ./
with:
upstream_repo: sysdiglabs/charts
local_patch_dir: tests/sysdiglabs/charts
upstream_ref: master
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: detect-private-key
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# action-patch-upstream

Checkout the ref (or latest) upstream version and apply one or more patch files

## Inputs

### Required

- `upstream_repo`: The upstream repo we want to checkout and patch
- `local_patch_dir`: Directory of the patch files, must end with .patch

### 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

## Caveats

- The action will always checkout the upstream repo under `upstream` directory.

## Example workflow

Perform all checks on pull requests

```yaml
name: Checkout and Patch

on:
pull_request:
types: [opened, edited, synchronize, reopened]
paths:
- 'containers/**'
jobs:
build:
runs-on: self-hosted
steps:
- uses: draios/infra-action-patch-upstream@v1
with:
upstream_repo: sysdiglabs/charts
local_patch_dir: tests/sysdiglabs/charts
upstream_ref: master
```
57 changes: 57 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: 'Checkout the x (or latest) upstream version and apply a patch'
description: Checkout the x (or latest) upstream version and apply a patch
inputs:
upstream_repo:
description: "The upstream repo that we want to checkout and patch"
required: true

upstream_ref:
description: "The upstream ref, can be: branch, tag, sha, if not provided last semver tag will be grabbed"
required: false

upstream_tag_regex:
description: "Regex to use while checking the last upstream versions"
required: false

local_patch_dir:
description: "Directory of the patch files, must end with .patch"
required: true

runs:
using: "composite"
steps:
# Only run when upstream_ref was not provided
- name: Check last tag in upstream repo
id: check_last_tag
uses: oprypin/find-latest-tag@v1
if: ${{ inputs.upstream_ref == '' }}
with:
repository: ${{ inputs.upstream_repo }}
regex: ${{ inputs.upstream_tag_regex }}

- uses: actions/checkout@v2
name: Checkout latest version
if: ${{ inputs.upstream_ref == '' }}
with:
repository: ${{inputs.upstream_repo }}
ref: ${{ steps.check_last_tag.outputs.tag }}
path: 'upstream'

- uses: actions/checkout@v2
name: Checkout the fixed version
if: ${{ inputs.upstream_ref != '' }}
with:
repository: ${{inputs.upstream_repo }}
ref: ${{ inputs.upstream_ref }}
path: 'upstream'

- uses: actions/checkout@v2
name: Checkout local repo
with:
path: 'patch'

- name: Apply Patch files
shell: bash
env:
PATCHDIR: ${{ inputs.local_patch_dir }}
run: for p in patch/${PATCHDIR}/*.patch; do patch -d upstream/ -p1 < $p; done
13 changes: 13 additions & 0 deletions tests/sysdiglabs/charts/README.md.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/README.md b/README.md
index 76f23d8..03a84bd 100644
--- a/README.md
+++ b/README.md
@@ -47,3 +47,8 @@ You can find more information at:
* [The Helm package manager](https://helm.sh/)
* [Chart Releaser](https://github.com/helm/chart-releaser)
* [Chart Releaser GitHub Action](https://github.com/helm/chart-releaser-action)
+
+
+## Testing patch action
+
+This is a test

0 comments on commit f69cdbf

Please sign in to comment.