From 951d2c20f372f95ed46eff70eab9a8a96ec07f93 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: Fri, 4 Feb 2022 20:26:12 +0100 Subject: [PATCH] ci: Use composite action to collect changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs --- .github/actions/collect-changes/action.yaml | 44 +++++++++++++++++++++ .github/workflows/charts-release.yaml | 34 +++------------- .github/workflows/pr-metadata.yaml | 36 +++-------------- 3 files changed, 55 insertions(+), 59 deletions(-) create mode 100644 .github/actions/collect-changes/action.yaml diff --git a/.github/actions/collect-changes/action.yaml b/.github/actions/collect-changes/action.yaml new file mode 100644 index 00000000..179097fd --- /dev/null +++ b/.github/actions/collect-changes/action.yaml @@ -0,0 +1,44 @@ +name: "Collect changes" +description: "Collects and stores changed files/charts" + +outputs: + changesDetected: + description: "Whether or not changes to charts have been detected" + value: ${{ steps.filter.outputs.addedOrModified }} + addedOrModifiedFiles: + description: "A list of the files changed" + value: ${{ steps.filter.outputs.addedOrModified_files || "" }} + addedOrModifiedCharts: + description: "A list of the charts changed" + value: ${{ steps.filter-charts.outputs.addedOrModified || "" }} + +runs: + using: "composite" + steps: + - 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/charts-release.yaml b/.github/workflows/charts-release.yaml index f8d6b659..d9a28b41 100644 --- a/.github/workflows/charts-release.yaml +++ b/.github/workflows/charts-release.yaml @@ -42,39 +42,15 @@ jobs: wget -O /tmp/helm-docs.deb https://github.com/k8s-at-home/helm-docs/releases/download/v0.1.1/helm-docs_0.1.1_Linux_x86_64.deb sudo dpkg -i /tmp/helm-docs.deb - - 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[*]}" + - name: Collect changes + id: collect-changes + uses: ./.github/actions/collect-changes - name: Generate README for changed charts in Renovate PR's if: | - steps.filter.outputs.addedOrModified == 'true' + steps.collect-changes.outputs.addedOrModified == 'true' run: | - CHARTS=(${{ steps.filter-charts.outputs.addedOrModified }}) + CHARTS=(${{ steps.collect-changes.outputs.addedOrModifiedCharts }}) for i in "${CHARTS[@]}" do IFS='/' read -r -a chart_parts <<< "$i" diff --git a/.github/workflows/pr-metadata.yaml b/.github/workflows/pr-metadata.yaml index 9176654a..26d432d6 100644 --- a/.github/workflows/pr-metadata.yaml +++ b/.github/workflows/pr-metadata.yaml @@ -47,37 +47,13 @@ jobs: 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 }} + addedOrModified: ${{ steps.collect-changes.outputs.addedOrModified }} + addedOrModifiedFiles: ${{ steps.collect-changes.outputs.addedOrModifiedFiles }} + addedOrModifiedCharts: ${{ steps.collect-changes.outputs.addedOrModifiedCharts }} 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[*]}" + - name: Collect changes + id: collect-changes + uses: ./.github/actions/collect-changes