From 0f8eecbe4759a2c176a236dfea75697e8a80c0dd Mon Sep 17 00:00:00 2001 From: Fran Mulero Date: Tue, 27 Sep 2022 16:07:04 +0200 Subject: [PATCH] [bitnami/containers] Add automatically asset label in PRs (#7961) * Assign asset label Signed-off-by: Fran Mulero * Fix permissions and amend job names Signed-off-by: Fran Mulero * Aemnd warning message Signed-off-by: Fran Mulero * Human friendly name for send_to_board job in triage workflow Signed-off-by: Fran Mulero Signed-off-by: Fran Mulero --- .github/workflows/assign-labels.yml | 46 +++++++++++++++++++++++++++++ .github/workflows/triage.yml | 1 + 2 files changed, 47 insertions(+) create mode 100644 .github/workflows/assign-labels.yml diff --git a/.github/workflows/assign-labels.yml b/.github/workflows/assign-labels.yml new file mode 100644 index 000000000000..7da323ff50fc --- /dev/null +++ b/.github/workflows/assign-labels.yml @@ -0,0 +1,46 @@ +name: '[Support] Assign asset label' +on: + pull_request_target: + types: + - opened +permissions: + pull-requests: write + issues: write +jobs: + assign-label: + runs-on: ubuntu-latest + steps: + - id: get-asset + name: Get modified assets + run: | + # Using the Github API to detect the files changed as git merge-base stops working when the branch is behind + # and jitterbit/get-changed-files does not support pull_request_target + URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" + files_changed_data=$(curl -s --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -X GET -G "$URL") + files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')" + # Adding || true to avoid "Process exited with code 1" errors + assets=($(echo "$files_changed" | xargs dirname | sed -nr "s|bitnami/([^/]*)/.*|\1|p" | sort | uniq || true)) + + if [[ "${#assets[@]}" -ne "1" ]]; then + echo "::set-output name=result::skip" + echo "::set-output name=message::Label cannot be set, cannot infer a single label from: ${assets[@]}" + echo "::set-output name=name::NONE" + else + echo "::set-output name=result::ok" + echo "::set-output name=message::Adding label '${assets}'" + echo "::set-output name=name::${assets}" + fi + - name: Show messages + uses: actions/github-script@v6 + with: + script: | + if ("${{ steps.get-asset.outputs.result }}" != "ok" ) { + core.warning("${{ steps.get-asset.outputs.message }}") + } else { + core.info("${{ steps.get-asset.outputs.message }}") + } + - name: Labeling + if: ${{ steps.get-asset.outputs.result == 'ok' }} + uses: andymckay/labeler@1.0.4 + with: + add-labels: "${{ steps.get-asset.outputs.name }}" diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 78f6f4b33a54..9feaba67a891 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -12,6 +12,7 @@ on: jobs: # For any opened or reopened issue, should be sent into Triage send_to_board: + name: Organize triage runs-on: ubuntu-latest steps: - name: Repo checkout