Skip to content

Commit

Permalink
FIX: landing page for gh-actions (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: Revathyvenugopal162 <[email protected]>
Co-authored-by: Revathy Venugopal <[email protected]>
  • Loading branch information
3 people committed Dec 12, 2022
1 parent d9fa764 commit 6149139
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 62 additions & 15 deletions doc-deploy-dev/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/[email protected]
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 [email protected]
git add .
git commit -m "DOC: add development documentation"
git push
fi
12 changes: 9 additions & 3 deletions doc-deploy-stable/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}"
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -119,7 +125,7 @@ runs:
then
git config user.name github-actions
git config user.email [email protected]
git add release/
git add .
git commit -m "DOC: add documentation for ${{ github.ref_name }}"
git push
fi
5 changes: 5 additions & 0 deletions scripts/redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting to var-url</title>
<meta http-equiv="refresh" content="0; URL=var-url">
<link rel="canonical" href="var-url">
9 changes: 8 additions & 1 deletion scripts/version_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_scripts/test_version_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6149139

Please sign in to comment.