Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix generate.sh bug #665

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions .github/actions/hugo-build-action/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,18 @@ name: Hugo Build
description: Builds documentation using Hugo
inputs:
base-url:
required: false
description: Optional base url used during build
working-directory:
required: false
description: Path to documentation directory
default: docs
hugo-env:
required: false
description: Environment variable
default: public
fetch-from:
required: false
description: repo to fetch the versions from
default: origin
required: true
description: Base url used during build

runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
cache: 'pip'
cache-dependency-path: scripts/script-requirements.txt
- uses: actions/setup-go@v4
- name: "Setup GO"
uses: actions/setup-go@v4
with:
go-version: '>=1.20.1'
- uses: actions/setup-node@v3
- name: "Setup Node"
uses: actions/setup-node@v3
with:
node-version: 18
- name: "Setup Hugo"
Expand All @@ -45,4 +28,4 @@ runs:
run: |
cd docs
npm install
hugo --minify ${BASE_URL:+--baseURL $BASE_URL}
hugo --minify ${BASE_URL:+--baseURL $BASE_URL} -e _default
20 changes: 7 additions & 13 deletions .github/workflows/netlify-deploy-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,35 @@ jobs:
netlify-deploy:
runs-on: infra1-rxa-xlarge
steps:
- name: Checkout
- name: "Checkout Recursive"
uses: actions/checkout@v4
with:
submodules: recursive
- name: Checkout
- name: "Checkout to PR-tmp"
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
path: 'PR-tmp'
- name: Get only changed docs
- name: "Get only changed docs"
run: |
rsync --delete -av PR-tmp/docs/content/en/ docs/content/en/
rm -rf PR-tmp
- name: Generate Docs
- name: "Generate Docs"
uses: gooddata/gooddata-python-sdk/.github/actions/hugo-build-action@master
with:
base-url: https://preview-${{ env.GITHUB_PR_NUMBER }}--${{ env.NETLIFY_SITE_NAME }}.netlify.app
- name: Publish
- name: "Publish"
uses: netlify/actions/cli@master
with:
args: deploy -d docs/public --alias=preview-${{ env.GITHUB_PR_NUMBER }}
env:
NETLIFY_SITE_ID: 93e23db0-d31a-4a12-801a-b9479ffef486 # Not a secret
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
# `htmltest` is after publishing, so we can see the artifact.
- name: htmltest
# `htmltest` is after publishing, so we can see the artifact.
- name: "htmltest"
run: |
rm -f htmltest.sh
wget https://raw.githubusercontent.com/gooddata/gooddata-python-sdk/master/scripts/htmltest.sh
chmod +x ./htmltest.sh
./htmltest.sh -c docs/.htmltest.yml docs/public
Comment on lines +42 to 48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Is htmltest necessary for preview?

# Commented out, because it has been failing. Check up later.
# - name: Comment PR
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# https://preview-${{ env.GITHUB_PR_NUMBER }}--${{ env.NETLIFY_SITE_NAME }}.netlify.app/
39 changes: 27 additions & 12 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ remote_name=${1:-origin}
# target branch where changes will be applied (master, rel/0.7, ...)
target_branch=${2:-master}
# Number of the versions to persist. Older ones are accesible only from GitHub.
num_versions=${4:-4}
num_versions=${3:-4}

echo "Validating target branch '$target_branch'"
case "$target_branch" in
Expand Down Expand Up @@ -42,14 +42,15 @@ fi

git fetch "$remote_name"


latest_branches=()
# Get all relevant rel/* branches, sort them, and pick the latest num_versions
while IFS= read -r vers; do
latest_branches+=("$remote_name/rel/$vers")
done < <(git branch -rl "$remote_name/rel/*" | sed 's|.*/rel/||' | sort -t. -k1,1n -k2,2n | tail -n"$num_versions")

# Add special branches to the array (only rel/dev and master for now)
special_branches=("$remote_name/rel/dev")
special_branches=("$remote_name/rel/dev" "$remote_name/master")

branches_to_process=("${latest_branches[@]}" "${special_branches[@]}")

Expand All @@ -63,9 +64,17 @@ for branch in "${branches_to_process[@]}" ; do
target_section=${branch#"$remote_name"/}
target_section=${target_section#rel/}
target_section=${target_section%.*}
# number of path segments to throw away by tar: content/en/x.y => 3
strip_count=3
src_section=docs
if [ "$target_section" == "master" ] ; then
# handle master branch specially, all contents is copied, not just docs
target_section=""
# number of path segments to throw away by tar: content/en => 2
strip_count=2
src_section=""
else
# number of path segments to throw away by tar: content/en/x.y => 3
strip_count=3
src_section=docs
fi
if [ "$target_section" == "$current_section" ] ; then
# copy the current docs to proper section
echo "Getting data from workdir for $branch"
Expand All @@ -81,15 +90,19 @@ for branch in "${branches_to_process[@]}" ; do
if git cat-file -e $API_GEN_FILE; then
echo "$API_GEN_FILE exists."
echo "Generating API ref..."
if git ls-tree --name-only "$branch" | grep -q "^api_spec.toml$"; then
git checkout "$branch" -- api_spec.toml
if [ "$target_section" == "" ] ; then
echo "Skipping master api ref"
else
echo "removing the API_spec"
rm -rf api_spec.toml
if git ls-tree --name-only "$branch" | grep -q "^api_spec.toml$"; then
git checkout "$branch" -- api_spec.toml
else
echo "removing the API_spec"
rm -rf api_spec.toml
fi
python3 ../scripts/docs/json_builder.py
mv -f data.json ./versioned_docs/"$target_section"/
python3 ../scripts/docs/python_ref_builder.py api_spec.toml ./versioned_docs/"$target_section"/data.json "$target_section" versioned_docs
fi
python3 ../scripts/docs/json_builder.py
mv -f data.json ./versioned_docs/"$target_section"/
python3 ../scripts/docs/python_ref_builder.py api_spec.toml ./versioned_docs/"$target_section"/data.json "$target_section" versioned_docs
fi
done

Expand All @@ -104,4 +117,6 @@ sed "s|${highest_version}|latest|g" ./versioned_docs/latest/links.json > temp.js

mv temp.json ./versioned_docs/latest/links.json

echo "master docs will not be published, removing"
rm -rf "${content_dir}/docs"
popd
Loading