Skip to content

Commit 3242004

Browse files
chore: Updating release script to update reference to all example links (#3643)
* adjust script and release commit file * adjust files to be commited * adding comment * test: Update example links in registry docs for v2.0.0 release * Revert "test: Update example links in registry docs for v2.0.0 release" This reverts commit 2e64ddb. * simplify script avoiding complex target expression
1 parent e3a0b97 commit 3242004

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ jobs:
6161
- uses: ./.github/templates/run-script-and-commit
6262
with:
6363
script_call: './scripts/update-examples-reference-in-docs.sh ${{inputs.version_number}}'
64-
file_to_commit: 'docs/index.md'
65-
commit_message: 'chore: Updates examples link in index.md for ${{ github.event.inputs.version_number }} release'
64+
file_to_commit: 'docs/* templates/*' # only docs files are updated
65+
commit_message: 'chore: Update example links in registry docs for ${{ github.event.inputs.version_number }} release'
6666
apix_bot_pat: ${{ secrets.APIX_BOT_PAT }}
6767
remote: https://svc-apix-bot:${{ secrets.APIX_BOT_PAT }}@github.com/${{ github.repository }}
6868
gpg_private_key: ${{ secrets.APIX_BOT_GPG_PRIVATE_KEY }}

scripts/update-examples-reference-in-docs.sh

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,44 @@ set -euo pipefail
44

55
: "${1?"Tag of new release must be provided"}"
66

7-
FILE_PATH="./docs/index.md"
87
RELEASE_TAG=$1
98

109
# Define the old URL pattern and new URL
11-
OLD_URL_PATTERN="\[example configurations\](https:\/\/github.com\/mongodb\/terraform-provider-mongodbatlas\/tree\/[a-zA-Z0-9._-]*\/examples)"
12-
NEW_URL="\[example configurations\](https:\/\/github.com\/mongodb\/terraform-provider-mongodbatlas\/tree\/$RELEASE_TAG\/examples)"
13-
14-
15-
TMP_FILE_NAME="docs.tmp"
16-
rm -f $TMP_FILE_NAME
17-
18-
# Use sed to update the URL and write to temporary file
19-
sed "s|$OLD_URL_PATTERN|$NEW_URL|g" "$FILE_PATH" > "$TMP_FILE_NAME"
20-
21-
# Move temporary file to original file
22-
mv "$TMP_FILE_NAME" "$FILE_PATH"
23-
24-
echo "Link updated successfully in $FILE_PATH"
10+
OLD_URL_PATTERN="https:\/\/github.com\/mongodb\/terraform-provider-mongodbatlas\/tree\/[a-zA-Z0-9._-]*\/examples"
11+
NEW_URL="https:\/\/github.com\/mongodb\/terraform-provider-mongodbatlas\/tree\/$RELEASE_TAG\/examples"
12+
13+
FILES=()
14+
15+
# 1) docs/index.md
16+
FILES+=("./docs/index.md")
17+
18+
# 2) collect all *.md and *.md.tmpl under docs/resources, templates/resources,
19+
# docs/data-sources, and templates/data-sources
20+
TARGET_DIRS=(
21+
"./docs/resources"
22+
"./templates/resources"
23+
"./docs/data-sources"
24+
"./templates/data-sources"
25+
)
26+
27+
for DIR in "${TARGET_DIRS[@]}"; do
28+
if [ -d "$DIR" ]; then
29+
while IFS= read -r -d '' f; do
30+
FILES+=("$f")
31+
done < <(find "$DIR" -type f \( -name "*.md" -o -name "*.md.tmpl" \) -print0)
32+
fi
33+
done
34+
35+
# Update links in each target file
36+
for FILE_PATH in "${FILES[@]}"; do
37+
TMP_FILE_NAME="${FILE_PATH}.tmp"
38+
rm -f "$TMP_FILE_NAME"
39+
40+
# Use sed to update the URL and write to temporary file
41+
sed "s|$OLD_URL_PATTERN|$NEW_URL|g" "$FILE_PATH" > "$TMP_FILE_NAME"
42+
43+
# Move temporary file to original file
44+
mv "$TMP_FILE_NAME" "$FILE_PATH"
45+
46+
echo "Link updated successfully in $FILE_PATH"
47+
done

0 commit comments

Comments
 (0)