diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 82574c79c..7e6c74f6f 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -109,7 +109,9 @@ jobs: uses: actions/checkout@v3 - name: "Copy scripts into the tests/ dir" - run: mv scripts tests/tests_scripts/ + run: | + mv scripts tests/tests_scripts/ + mv tests/tests_scripts/scripts/redirect.html tests/tests_scripts/index.html - name: "List all the content of the tests/ dir" run: ls -R tests diff --git a/doc-deploy-dev/action.yml b/doc-deploy-dev/action.yml index 6f425a63d..dced89dc4 100644 --- a/doc-deploy-dev/action.yml +++ b/doc-deploy-dev/action.yml @@ -2,6 +2,11 @@ name: "Documentation deploy development version." description: "Deploy development documentation to GitHub pages." inputs: + doc-artifact-name: + description: "Name of the HTML documentation artifact." + required: false + default: 'documentation-html' + type: string cname: description: 'The canonical name of the documentation website.' required: true @@ -15,32 +20,74 @@ runs: using: "composite" steps: + - name: "Install system dependencies" + shell: bash + run: | + sudo apt-get install curl + - name: "Checkout project in the GitHub Pages branch" uses: actions/checkout@v3 + with: + ref: 'gh-pages' + + - name: "Create a fresh development folder" + shell: bash + run: rm -rf dev/ && mkdir dev/ - name: "Download the HTML documentation artifact" uses: actions/download-artifact@v3 with: - name: documentation-html - path: documentation-html + name: ${{ inputs.doc-artifact-name }} + path: dev - name: "Display structure of downloaded files" shell: bash run: | ls -R - + - name: "Include CNAME and nojekyll files expected by GitHub pages" shell: bash run: | - touch documentation-html/CNAME documentation-html/.nojekyll - echo ${{ inputs.cname }} > documentation-html/CNAME - - - name: "Deploy devevelopment documentation" - uses: JamesIves/github-pages-deploy-action@v4.4.0 - with: - token: ${{ inputs.token }} - branch: gh-pages - folder: documentation-html - clean: true - clean-exclude: release - single-commit: true + touch CNAME .nojekyll + echo ${{ inputs.cname }} > CNAME + + - name: "Generate the redirection URL" + shell: bash + run: | + # Verify if there is any stable release in release/versions.json + grep -E "\"version\": \"[0-9]+.[0-9]+ \(stable\)\"" release/versions.json + if [ $? -eq 0 ]; + then + # Generate the URL pointing to the latest stable version + echo "Found stable release. Generating stable redirection URL..." + line=$(grep -n -E "\"version\": \"[0-9]+.[0-9]+ \(stable\)\"" release/versions.json) + version=$(echo $line | grep -o -h -E "[0-9]+.[0-9]+") + echo "URL=https://${{ inputs.cname }}/release/$version" >> $GITHUB_ENV + else + # Generate the URL pointing to the development version if no stable releases + echo "Stable release not found. Generating development redirection URL..." + echo "URL=https://${{ inputs.cname }}/dev" >> $GITHUB_ENV + fi + + - name: "Update the redirection link" + shell: bash + run: | + curl https://raw.githubusercontent.com/pyansys/actions/release/2.0/scripts/redirect.html -o index.html + # HACK: if the GitHub actions variable is dereferenced inside the `sed` command a syntax error is raised. + # The URL Github actions environmental variable is loaded inside a shell one to avoid this conflict. + url=${{ env.URL }} + echo "Value for url: $url" + sed -i "s|var-url|$url|g" index.html + cat index.html + + - name: "Commit new changes (if required)" + shell: bash + run: | + if [[ ! -z $(git status -s) ]]; + then + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "DOC: add development documentation" + git push + fi diff --git a/doc-deploy-stable/action.yml b/doc-deploy-stable/action.yml index 6cace90ae..078208d8d 100644 --- a/doc-deploy-stable/action.yml +++ b/doc-deploy-stable/action.yml @@ -2,6 +2,11 @@ name: "Documentation deploy stable version." description: "Deploy stable documentation to GitHub pages." inputs: + doc-artifact-name: + description: "Name of the HTML documentation artifact." + required: false + default: 'documentation-html' + type: string cname: description: 'The canonical name of the documentation website.' required: true @@ -76,7 +81,7 @@ runs: if: env.ACCEPTED_FORMAT == 'true' uses: actions/download-artifact@v3 with: - name: documentation-html + name: ${{ inputs.doc-artifact-name }} path: release/${{ env.VERSION }} - name: "Set up Python ${{ inputs.python-version }}" @@ -98,6 +103,7 @@ runs: shell: bash run: | curl https://raw.githubusercontent.com/pyansys/actions/release/2.0/scripts/version_mapper.py -o version_mapper.py + curl https://raw.githubusercontent.com/pyansys/actions/release/2.0/scripts/redirect.html -o index.html - name: "Update the version JSON file" if: env.ACCEPTED_FORMAT == 'true' @@ -109,7 +115,7 @@ runs: --new_version ${{ env.VERSION }} \ --render_last ${{ inputs.render-last }} # Remove the script to avoid Git tracking it - rm -rf version_mapper.py + rm -rf version_mapper.py index.html - name: "Commit new changes (if required)" if: env.ACCEPTED_FORMAT == 'true' @@ -119,7 +125,7 @@ runs: then git config user.name github-actions git config user.email github-actions@github.com - git add release/ + git add . git commit -m "DOC: add documentation for ${{ github.ref_name }}" git push fi diff --git a/scripts/redirect.html b/scripts/redirect.html new file mode 100644 index 000000000..be2936483 --- /dev/null +++ b/scripts/redirect.html @@ -0,0 +1,5 @@ + + +Redirecting to var-url + + diff --git a/scripts/version_mapper.py b/scripts/version_mapper.py index fc9db687e..b52358930 100644 --- a/scripts/version_mapper.py +++ b/scripts/version_mapper.py @@ -79,7 +79,7 @@ def update_switch_version_file( new_content = [] # The first data for the new content is always the development version - new_content.append(dict(version="dev", url=cname)) + new_content.append(dict(version="dev", url=f"{cname}/dev")) # Append the information for the new content for ith_version, version in enumerate(new_versions_list): @@ -130,6 +130,13 @@ def update_switch_version_file( print(f"Writing content to {announcement_file}.") file.write(announcement_content) + # Make the redirec page to point to the latest stable + with open("index.html", "r") as redirection_file: + content = redirection_file.read() + content.replace("var-url", f"{cname}/release/{latest_stable_version}") + with open("index.html", "w") as redirection_file: + redirection_file.write(content) + def parse_cli_arguments(): """Parse all command line arguments.""" diff --git a/tests/tests_scripts/test_version_mapper.py b/tests/tests_scripts/test_version_mapper.py index 5bde15c42..443b232ed 100644 --- a/tests/tests_scripts/test_version_mapper.py +++ b/tests/tests_scripts/test_version_mapper.py @@ -14,7 +14,7 @@ def test_update_switch_version_file(new_version, render_last, cname): # The content for the file shouldn't change since the version already exists # and the number of shown versions is the available one expected_content = [] - expected_content.append(dict(version="dev", url=f"https://{cname}")) + expected_content.append(dict(version="dev", url=f"https://{cname}/dev")) minor_version = int(new_version[-1]) lower_bound, upper_bound = minor_version + 1 - render_last, minor_version + 1 for ith_version, minor_version in enumerate(