Skip to content

Commit

Permalink
Add changed-files workflow (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA authored Sep 17, 2024
1 parent 157e982 commit 97eda37
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/changed-files.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 97eda37

Please sign in to comment.