-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add workflow to sync Snyk CLI GitBook doc to the CLI repo READ…
…ME (#4996) * chore: added worklfow to sync Readme with GitBook Added worklfow to synchronize content from the Snyk CLI's GitBook documentation to the CLI repository's README Also manually updated README file * chore: ran prettier to fix lint issues * chore: added prettier step to synchronize-readme workflow
- Loading branch information
1 parent
8b8fc37
commit 4b8c991
Showing
2 changed files
with
128 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Synchronize Readme | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 12 * * 1-5' # Mon-Fri at 12 | ||
|
||
jobs: | ||
build: | ||
name: synchronize-readme | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: | | ||
# Setup | ||
gh auth setup-git | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "$GITHUB_ACTOR" | ||
# Clone the CLI repository | ||
gh repo clone snyk/cli cli -- --depth=1 --quiet | ||
git -C ./cli checkout -B $DESTINATION_BRANCH | ||
# Retrieve the GitBook content | ||
wget https://raw.githubusercontent.com/snyk/user-docs/main/docs/snyk-cli/getting-started-with-the-snyk-cli.md -O current_gitbook.md | ||
# Find relative paths to GitBooks assets (such as images) and replace with absolute paths | ||
sed -i \ | ||
-e "s|../.gitbook/assets/|https://github.com/snyk/user-docs/raw/HEAD/docs/.gitbook/assets/|g" \ | ||
current_gitbook.md | ||
# Replace the README.md content with the GitBook content | ||
cp current_gitbook.md ./cli/README.md | ||
# If changes, commit and create PR | ||
if [[ $(git -C ./cli status --porcelain) ]]; then | ||
echo "Documentation changes detected" | ||
cd ./cli | ||
npm clean-install | ||
npx prettier --write ./cli/README.md | ||
git push -f -u origin $DESTINATION_BRANCH | ||
export SHA=$( git rev-parse $DESTINATION_BRANCH:README.md ) | ||
export CONTENT=$( base64 -i README.md ) | ||
gh api --method PUT /repos/:owner/:repo/contents/README.md \ | ||
--field message="$MESSAGE" \ | ||
--field content="$CONTENT" \ | ||
--field encoding="base64" \ | ||
--field branch="$DESTINATION_BRANCH" \ | ||
--field sha="$SHA" | ||
if [[ ! $(gh pr list --search "$MESSAGE" 2>&1 | grep -e "$MESSAGE";) ]]; then | ||
echo "Creating PR" | ||
gh pr create --title="$MESSAGE" --body="Automatic PR controlled by GitHub Action." --head $DESTINATION_BRANCH | ||
else | ||
echo "PR exists, pushed changes to it." | ||
fi | ||
else | ||
echo "No documentation changes detected, exiting." | ||
fi | ||
env: | ||
DESTINATION_BRANCH: docs/automatic-gitbook-update | ||
MESSAGE: 'docs: synchronizing README from GitBook' | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Oops, something went wrong.