From 97eda37edb213ed5037038a5605c34f94c5ca482 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 17 Sep 2024 14:44:52 -0400 Subject: [PATCH] Add `changed-files` workflow (#239) --- .github/workflows/changed-files.yaml | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/changed-files.yaml diff --git a/.github/workflows/changed-files.yaml b/.github/workflows/changed-files.yaml new file mode 100644 index 00000000..5a4d0352 --- /dev/null +++ b/.github/workflows/changed-files.yaml @@ -0,0 +1,78 @@ +on: + workflow_call: + inputs: + files_yaml: + type: string + required: true + transform_expr: + type: string + required: false + default: | + to_entries | + map( + select(.key | endswith("_any_changed")) | + { + "key": (.key | rtrimstr("_any_changed")), + "value": (.value == "true"), + } + ) | + from_entries + outputs: + changed_file_groups: + value: ${{ jobs.changed-files.outputs.transformed_output }} + +defaults: + run: + shell: bash + +permissions: + actions: read + checks: none + contents: read + deployments: none + discussions: none + id-token: write + issues: none + packages: read + pages: none + pull-requests: read + repository-projects: none + security-events: none + statuses: none + +jobs: + changed-files: + runs-on: ubuntu-latest + name: "Check changed files" + outputs: + transformed_output: ${{ steps.transform-changed-files.outputs.transformed-output }} + steps: + - name: Get PR info + id: get-pr-info + uses: rapidsai/shared-actions/get-pr-info@main + - name: Checkout code repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Calculate merge base + id: calculate-merge-base + env: + PR_SHA: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).head.sha }} + BASE_SHA: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).base.sha }} + run: | + (echo -n "merge-base="; git merge-base "$BASE_SHA" "$PR_SHA") | tee --append "$GITHUB_OUTPUT" + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + with: + base_sha: ${{ steps.calculate-merge-base.outputs.merge-base }} + sha: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).head.sha }} + files_yaml: ${{ inputs.files_yaml }} + - name: Transform changed files into output + id: transform-changed-files + env: + CHANGED_FILES: ${{ toJSON(steps.changed-files.outputs) }} + TRANSFORM_EXPR: ${{ inputs.transform_expr }} + run: | + (echo -n "transformed-output="; jq -c -n "env.CHANGED_FILES | fromjson | $TRANSFORM_EXPR") | tee --append "$GITHUB_OUTPUT"