From ee6b8361da455f2144adfa8b1dd133f9970f17fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= Date: Thu, 3 Feb 2022 16:09:38 +0100 Subject: [PATCH] ci: Add PR validation flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs --- .github/workflows/pr-get-metadata.yaml | 71 ++++++++++++++++++++++++++ .github/workflows/pr-validate.yaml | 14 +++++ 2 files changed, 85 insertions(+) create mode 100644 .github/workflows/pr-get-metadata.yaml create mode 100644 .github/workflows/pr-validate.yaml diff --git a/.github/workflows/pr-get-metadata.yaml b/.github/workflows/pr-get-metadata.yaml new file mode 100644 index 00000000..79cbc986 --- /dev/null +++ b/.github/workflows/pr-get-metadata.yaml @@ -0,0 +1,71 @@ +name: "Pull Request: Get metadata" + +on: + workflow_call: + outputs: + isRenovatePR: + description: "Is the PR coming from Renovate?" + value: ${{ jobs.pr-metadata.outputs.isRenovatePR }} + isFork: + description: "Is the PR coming from a forked repo?" + value: ${{ jobs.pr-metadata.outputs.isFork }} + addedOrModified: + description: "Does the PR contain any changes?" + value: ${{ jobs.pr-changes.outputs.addedOrModified }} + addedOrModifiedFiles: + description: "A list of the files changed in this PR" + value: ${{ jobs.pr-changes.outputs.addedOrModifiedFiles }} + addedOrModifiedCharts: + description: "A list of the charts changed in this PR" + value: ${{ jobs.pr-changes.outputs.addedOrModifiedCharts }} + +jobs: + pr-metadata: + name: Collect PR metadata + runs-on: ubuntu-latest + outputs: + isRenovatePR: ${{ startsWith(steps.branch-name.outputs.current_branch, 'renovate/') }} + isFork: ${{ github.event.pull_request.head.repo.full_name != github.repository }} + steps: + - name: Get branch name + id: branch-name + uses: tj-actions/branch-names@v5.1 + + pr-changes: + name: Collect PR changes + runs-on: ubuntu-latest + outputs: + addedOrModified: ${{ steps.filter.outputs.addedOrModified }} + addedOrModifiedFiles: ${{ steps.filter.outputs.addedOrModified_files }} + addedOrModifiedCharts: ${{ steps.filter-charts.outputs.addedOrModified }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Collect changed files + uses: dorny/paths-filter@v2 + id: filter + with: + list-files: shell + filters: | + addedOrModified: + - added|modified: 'charts/**' + + - name: Collect changed charts + if: | + steps.filter.outputs.addedOrModified == 'true' + id: filter-charts + run: | + CHARTS=() + PATHS=(${{ steps.filter.outputs.addedOrModified_files }}) + # Get only the chart paths + for CHARTPATH in "${PATHS[@]}" + do + IFS='/' read -r -a path_parts <<< "${CHARTPATH}" + CHARTS+=("${path_parts[1]}/${path_parts[2]}") + done + + # Remove duplicates + CHARTS=( `printf "%s\n" "${CHARTS[@]}" | sort -u` ) + # Set output to changed charts + printf "::set-output name=addedOrModified::%s\n" "${CHARTS[*]}" diff --git a/.github/workflows/pr-validate.yaml b/.github/workflows/pr-validate.yaml new file mode 100644 index 00000000..2e4232a8 --- /dev/null +++ b/.github/workflows/pr-validate.yaml @@ -0,0 +1,14 @@ +name: "Pull Request: Validate" + +on: + pull_request: + branches: + - master + +concurrency: + group: ${{ github.head_ref }}-pr-validate + # cancel-in-progress: true + +jobs: + pr-get-metadata: + uses: k8s-at-home/charts/.github/workflows/pr-get-metadata.yaml@master