Skip to content

Commit c59de58

Browse files
sdaultonfacebook-github-bot
authored andcommitted
Fix Docusaurus versioning error in publish_website workflow (#3218)
Summary: Fix Docusaurus version deletion not matching 'v' prefixed directories ## Problem The 'Delete existing similar versions from Docusaurus' step fails to find and delete existing versions when the release workflow is re-run. This causes the subsequent 'Create new docusaurus version' step to fail with: ``` Error: [docs]: this version already exists! Use a version tag that does not already exist. ``` ## Root Cause When Docusaurus creates a version with `yarn docusaurus docs:version v0.17.2`, it creates directories/files with the 'v' prefix: - `versioned_docs/version-v0.17.2/` - `versioned_sidebars/version-v0.17.2-sidebars.json` But the delete step was stripping the 'v' prefix before searching: ```bash MAJOR_MINOR_VERSION=$(cut -d '.' -f 1-2 <<< v0.17.2) # gives 'v0.17' MAJOR_MINOR_VERSION=${MAJOR_MINOR_VERSION#v} # strips to '0.17' for dir in website/versioned_docs/version-$MAJOR_MINOR_VERSION.* # looks for 'version-0.17.*' ``` The glob `version-0.17.*` never matches `version-v0.17.2/`, so nothing gets deleted. ## Solution Search for both patterns (with and without 'v' prefix): ```bash for pattern in "version-$MAJOR_MINOR_VERSION.*" "version-${MAJOR_MINOR_VERSION#v}.*"; do ``` Also added `-f` flag to `rm` for sidebars to avoid errors if file doesn't exist. Reviewed By: saitcakmak Differential Revision: D95305476
1 parent ee72a65 commit c59de58

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

.github/workflows/publish_website.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,22 @@ jobs:
6565
# Delete existing versions for same Major and Minor version numbers.
6666
# We do this to keep only the latest patch for a given major/minor version.
6767
MAJOR_MINOR_VERSION=$(cut -d '.' -f 1-2 <<< ${{ inputs.new_version }}) # remove patch number
68-
MAJOR_MINOR_VERSION=${MAJOR_MINOR_VERSION#v} # remove optional "v" prefix
69-
for dir in website/versioned_docs/version-$MAJOR_MINOR_VERSION.*; do
70-
if [ -d "$dir" ]; then
71-
OLD_VERSION=$(basename "$dir" | sed 's/^version-//') # remove "version-" prefix from the directory name
72-
echo "Deleting older version $OLD_VERSION with the same major and minor version numbers as $NEW_VERSION"
73-
# Delete version from the three locations Docusaurus uses:
74-
# - versioned_docs/version-X.Y.Z/
75-
# - versioned_sidebars/version-X.Y.Z-sidebars.json
76-
# - versions.json
77-
# https://docusaurus.io/docs/versioning#deleting-an-existing-version
78-
rm -rf "$dir"
79-
rm "website/versioned_sidebars/version-$OLD_VERSION-sidebars.json"
80-
sed -i "/\"$OLD_VERSION\"/d" website/versions.json
81-
fi
68+
# Search for both with and without 'v' prefix since docusaurus preserves the prefix from the version tag
69+
for pattern in "version-$MAJOR_MINOR_VERSION.*" "version-${MAJOR_MINOR_VERSION#v}.*"; do
70+
for dir in website/versioned_docs/$pattern; do
71+
if [ -d "$dir" ]; then
72+
OLD_VERSION=$(basename "$dir" | sed 's/^version-//') # remove "version-" prefix from the directory name
73+
echo "Deleting older version $OLD_VERSION with the same major and minor version numbers as ${{ inputs.new_version }}"
74+
# Delete version from the three locations Docusaurus uses:
75+
# - versioned_docs/version-X.Y.Z/
76+
# - versioned_sidebars/version-X.Y.Z-sidebars.json
77+
# - versions.json
78+
# https://docusaurus.io/docs/versioning#deleting-an-existing-version
79+
rm -rf "$dir"
80+
rm -f "website/versioned_sidebars/version-$OLD_VERSION-sidebars.json"
81+
sed -i "/\"$OLD_VERSION\"/d" website/versions.json
82+
fi
83+
done
8284
done
8385
- if: ${{ inputs.new_version && !inputs.dry_run }}
8486
name: Create new docusaurus version

0 commit comments

Comments
 (0)