diff --git a/.github/workflows/changed_files.yml b/.github/workflows/changed_files.yml new file mode 100644 index 000000000..295d0c853 --- /dev/null +++ b/.github/workflows/changed_files.yml @@ -0,0 +1,113 @@ +name: List files changed as GitHub comment + +on: + pull_request: + branches: + - main + +jobs: + list-files-changed: + if: github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Format list of changed files + id: format + env: + GH_TOKEN: ${{ github.token }} + run: | + declare -a output added_files modified_files removed_files no_preview_files + + pr_num="${{ github.event.pull_request.number }}" + + all_changed_files="$(gh pr view ${pr_num} --json files --jq '.files.[].path')" + for changed_file in "${all_changed_files[@]}"; do + status="$(echo '$changed_file' | awk -F ' ' {'print $1'})" + echo "Status: $status" + path="$(echo '$changed_file' | awk -F ' ' {'print $2'})" + echo "Path: $path" + if [ "$status" = "added" ]; then + added_files+=("$path") + elif [ "$status = "modified" ]; then + modified_files+=("$path") + elif [ "$status" = "removed" ]; then + removed_files+=("path") + fi + done + + echo "Added:" + echo "${added_files[@}" + echo + + echo "Modified:" + echo "${modified_files[@}" + echo + + echo "Removed:" + echo "${removed_files[@}" + echo + + function generatePreviewURL() { + # Preprocess input paths to output paths + # using # as sed separation character + # + # - Remove content/ + # - Remove _index/ + # - Remove integration_tutorials/ + + # Generate HTML preview links for added files in content/ + for file in ${added_files[@]}; do + if [[ "$file" =~ .*\/content\/.*\.md ]]; then + output_path=$(echo "$file" | sed -E 's#content\/##g' | sed -E 's#/_index/##g' | sed -E 's#integration-tutorials\/##g') + preview_link="$file" + output+=("
Preview links work only after the `Cloudflare Pages` build check succeeds. Links are generated only for new and modified .md
files under content/
.