Skip to content

Commit 02a6875

Browse files
authored
GH action security updates (#264)
1 parent dd333de commit 02a6875

File tree

1 file changed

+55
-65
lines changed

1 file changed

+55
-65
lines changed
Lines changed: 55 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,58 @@
11
name: Add Netlify Links To Changed Pages
22
on:
3-
workflow_call:
4-
pull_request_target:
3+
workflow_call:
4+
pull_request_target:
55
jobs:
6-
get-pr-changes:
7-
name: Get Changed Files & Update PR Description
8-
runs-on: ubuntu-latest
9-
permissions:
10-
issues: write
11-
contents: write
12-
pull-requests: write
13-
repository-projects: write
14-
steps:
15-
- uses: actions/checkout@v4
16-
- name: Get Changed Files
17-
id: changed-files
18-
uses: tj-actions/changed-files@v44
19-
with:
20-
separator: ","
21-
files: source/**
22-
- name: Build Netlify Links for Changed Pages
23-
id: build_page_links
24-
env:
25-
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
26-
run: |
27-
# Function to validate file paths
28-
validate_file_path() {
29-
local file_path="$1"
30-
# Allow only alphanumeric characters, _ . / and -
31-
if [[ ! "$file_path" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
32-
echo "Invalid file path detected: $file_path" >&2
33-
exit 1
34-
fi
35-
}
36-
37-
new_links=""
38-
base_link='https://deploy-preview-${{ github.event.number }}--mongodb-docs-csharp.netlify.app'
39-
files=$(echo "$CHANGED_FILES" | tr "," "\n")
40-
for file in $files; do
41-
echo "processing ${file}"
42-
validate_file_path "$file"
43-
if (! grep -s "includes/" <<< $file) &&
44-
(! grep -s "images/" <<< $file) &&
45-
(! grep -s "examples/" <<< $file); then
46-
file="${file#source}"
47-
file="${file%.txt}"
48-
filenoslash="${file:1}"
49-
echo "${base_link}${file}"
50-
new_links+="<li><a href=${base_link}${file}>${filenoslash}</a></li>"
51-
else
52-
echo "(file skipped)"
53-
fi
54-
done
55-
if [ "$new_links" == "" ]; then
56-
new_links="No pages to preview"
57-
fi
58-
echo "Final new_links string: "
59-
echo "${new_links}"
60-
echo "staging_links=${new_links}" >> "$GITHUB_OUTPUT"
61-
- name: Update the PR Description
62-
uses: MongoCaleb/pr-description-action@master
63-
with:
64-
regex: "<!-- start insert-links -->.*<!-- end insert-links -->"
65-
appendContentOnMatchOnly: true
66-
regexFlags: is
67-
content: "<!-- start insert-links -->\n${{ steps.build_page_links.outputs.staging_links }}\n<!-- end insert-links -->"
68-
token: ${{ secrets.GITHUB_TOKEN }}
6+
get-pr-changes:
7+
name: Get Changed Files & Update PR Description
8+
runs-on: ubuntu-latest
9+
permissions:
10+
issues: write
11+
contents: write
12+
pull-requests: write
13+
repository-projects: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Get Changed Files
17+
id: changed-files
18+
# pin to a specific commit to ensure stability
19+
uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c
20+
with:
21+
separator: ","
22+
files: source/**
23+
- name: Build Netlify Links for Changed Pages
24+
id: build_page_links
25+
env:
26+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
27+
run: |
28+
new_links=""
29+
base_link='https://deploy-preview-${{ github.event.number }}--mongodb-docs-csharp.netlify.app'
30+
files=$(echo "$CHANGED_FILES" | tr "," "\n")
31+
for file in $files; do
32+
echo "processing ${file}"
33+
if (! grep -s "includes/" <<< "$file") &&
34+
(! grep -s "images/" <<< "$file") &&
35+
(! grep -s "examples/" <<< "$file"); then
36+
file="${file#source}"
37+
file="${file%.txt}"
38+
filenoslash="${file:1}"
39+
echo "${base_link}${file}"
40+
new_links+="<li><a href=${base_link}${file}>${filenoslash}</a></li>"
41+
else
42+
echo "(file skipped)"
43+
fi
44+
done
45+
if [ "$new_links" == "" ]; then
46+
new_links="No pages to preview"
47+
fi
48+
echo "Final new_links string: "
49+
echo "${new_links}"
50+
echo "staging_links=${new_links}" >> "$GITHUB_OUTPUT"
51+
- name: Update the PR Description
52+
uses: MongoCaleb/pr-description-action@master
53+
with:
54+
regex: "<!-- start insert-links -->.*<!-- end insert-links -->"
55+
appendContentOnMatchOnly: true
56+
regexFlags: is
57+
content: "<!-- start insert-links -->\n${{ steps.build_page_links.outputs.staging_links }}\n<!-- end insert-links -->"
58+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)