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

Fix Documentation Actions on dev/patch #6042

Merged
merged 2 commits into from
Sep 19, 2023
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
39 changes: 39 additions & 0 deletions .github/workflows/cleanup-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Cleanup nightly documentation
on: delete
jobs:
cleanup-nightly-docs:
if: github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Configure workflow
id: configuration
env:
DELETED_BRANCH: ${{ github.event.ref }}
run: |
BRANCH_NAME="${DELETED_BRANCH#refs/*/}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "DOCS_OUTPUT_DIR=${GITHUB_WORKSPACE}/skript-docs/docs/nightly/${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "DOCS_REPO_DIR=${GITHUB_WORKSPACE}/skript-docs" >> $GITHUB_OUTPUT
- name: Checkout Skript
uses: actions/checkout@v3
with:
ref: ${{ github.event.repository.default_branch }}
submodules: recursive
path: skript
- name: Setup documentation environment
uses: ./skript/.github/workflows/docs/setup-docs
with:
docs_deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
- name: Cleanup nightly documentation
env:
DOCS_OUTPUT_DIR: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
run: |
rm -rf ${DOCS_OUTPUT_DIR} || true
- name: Push nightly documentation cleanup
uses: ./skript/.github/workflows/docs/push-docs
with:
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
git_name: Nightly Docs Bot
git_email: nightlydocs@skriptlang.org
git_commit_message: "Delete ${{ steps.configuration.outputs.BRANCH_NAME }} branch nightly docs"
64 changes: 61 additions & 3 deletions .github/workflows/docs/generate-docs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,82 @@ inputs:
required: false
default: false
type: boolean
cleanup_pattern:
description: "A pattern designating which files to delete when cleaning the documentation output directory"
required: false
default: "*"
type: string

outputs:
DOCS_CHANGED:
description: "Whether or not the documentation has changed since the last push"
value: ${{ steps.generate.outputs.DOCS_CHANGED }}

runs:
using: 'composite'
steps:
- name: generate-docs
id: generate
shell: bash
env:
DOCS_OUTPUT_DIR: ${{ inputs.docs_output_dir }}
DOCS_REPO_DIR: ${{ inputs.docs_repo_dir }}
SKRIPT_REPO_DIR: ${{ inputs.skript_repo_dir }}
IS_RELEASE: ${{ inputs.is_release }}
CLEANUP_PATTERN: ${{ inputs.cleanup_pattern }}
run: |
export SKRIPT_DOCS_TEMPLATE_DIR=${DOCS_REPO_DIR}/doc-templates
export SKRIPT_DOCS_OUTPUT_DIR=${DOCS_OUTPUT_DIR}/
replace_in_directory() {
find $1 -type f -exec sed -i -e "s/$2/$3/g" {} \;
}

# this should be replaced with a more reliable jq command,
# but it can't be right now because docs.json is actually not valid json.
get_skript_version_of_directory() {
grep skriptVersion "$1/docs.json" | cut -d\" -f 4
}

if [ -d "${DOCS_REPO_DIR}/docs/templates" ]
then
export SKRIPT_DOCS_TEMPLATE_DIR=${DOCS_REPO_DIR}/docs/templates
else
export SKRIPT_DOCS_TEMPLATE_DIR=${DOCS_REPO_DIR}/doc-templates
fi

export SKRIPT_DOCS_OUTPUT_DIR=/tmp/generated-docs

cd $SKRIPT_REPO_DIR
if [[ "${IS_RELEASE}" == "true" ]]; then
./gradlew genReleaseDocs releaseJavadoc
else
./gradlew genNightlyDocs javadoc
fi
cp -a "./build/docs/javadoc/." "${DOCS_OUTPUT_DIR}/javadocs"

if [ -d "${DOCS_OUTPUT_DIR}" ]; then
mkdir -p "${SKRIPT_DOCS_OUTPUT_DIR}/javadocs" && cp -a "./build/docs/javadoc/." "$_"

mkdir -p "/tmp/normalized-output-docs" && cp -a "${DOCS_OUTPUT_DIR}/." "$_"
mkdir -p "/tmp/normalized-generated-docs" && cp -a "${SKRIPT_DOCS_OUTPUT_DIR}/." "$_"

output_skript_version=$(get_skript_version_of_directory "/tmp/normalized-output-docs")
generated_skript_version=$(get_skript_version_of_directory "/tmp/normalized-generated-docs")

replace_in_directory "/tmp/normalized-output-docs" "${output_skript_version}" "Skript"
replace_in_directory "/tmp/normalized-generated-docs" "${generated_skript_version}" "Skript"

diff -qbr /tmp/normalized-output-docs /tmp/normalized-generated-docs || diff_exit_code=$?
# If diff exits with exit code 1, that means there were some differences
if [[ ${diff_exit_code} -eq 1 ]]; then
echo "DOCS_CHANGED=true" >> $GITHUB_OUTPUT
echo "Documentation has changed since last push"
else
echo "Documentation hasn't changed since last push"
fi
else
echo "DOCS_CHANGED=true" >> $GITHUB_OUTPUT
echo "No existing documentation found"
fi

rm -rf ${DOCS_OUTPUT_DIR}/${CLEANUP_PATTERN} || true
mkdir -p "${DOCS_OUTPUT_DIR}/" && cp -a "${SKRIPT_DOCS_OUTPUT_DIR}/." "$_"


14 changes: 8 additions & 6 deletions .github/workflows/docs/push-docs/action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Generate documentation
name: Push documentation

inputs:
docs_output_dir:
description: "The directory to generate the documentation into"
required: true
type: string
docs_repo_dir:
description: "The skript-docs repository directory"
required: true
Expand Down Expand Up @@ -38,4 +34,10 @@ runs:
git config user.email "${GIT_EMAIL}"
git add -A
git commit -m "${GIT_COMMIT_MESSAGE}" || (echo "Nothing to push!" && exit 0)
git push origin main
# Attempt rebasing and pushing 5 times in case another job pushes before us
for i in 1 2 3 4 5
do
git pull --rebase -X theirs origin main
git push origin main && break
sleep 5
done
1 change: 0 additions & 1 deletion .github/workflows/docs/setup-docs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ runs:
CLEANUP_PATTERN: ${{ inputs.cleanup_pattern }}
run: |
eval `ssh-agent`
rm -rf ${DOCS_OUTPUT_DIR}/${CLEANUP_PATTERN} || true
echo "$DOCS_DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
mkdir ~/.ssh
ssh-keyscan www.github.com >> ~/.ssh/known_hosts
15 changes: 13 additions & 2 deletions .github/workflows/nightly-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ on:

jobs:
nightly-docs:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
if: "!contains(toJSON(github.event.commits.*.message), '[ci skip]')"
runs-on: ubuntu-latest
steps:
- name: Configure workflow
id: configuration
env:
DOCS_DEPLOY_KEY: ${{ secrets.DOCS_DEPLOY_KEY }}
run: |
if [ -n "$DOCS_DEPLOY_KEY" ]
then
echo "DOCS_DEPLOY_KEY_PRESENT=true" >> $GITHUB_OUTPUT
else
echo "Secret 'DOCS_DEPLOY_KEY' not present. Exiting job."
fi
BRANCH_NAME="${GITHUB_REF#refs/*/}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "DOCS_OUTPUT_DIR=${GITHUB_WORKSPACE}/skript-docs/docs/nightly/${BRANCH_NAME}" >> $GITHUB_OUTPUT
Expand All @@ -26,20 +34,23 @@ jobs:
submodules: recursive
path: skript
- name: Setup documentation environment
if: steps.configuration.outputs.DOCS_DEPLOY_KEY_PRESENT == 'true'
uses: ./skript/.github/workflows/docs/setup-docs
with:
docs_deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
- name: Generate documentation
id: generate
if: steps.configuration.outputs.DOCS_DEPLOY_KEY_PRESENT == 'true'
uses: ./skript/.github/workflows/docs/generate-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
skript_repo_dir: ${{ steps.configuration.outputs.SKRIPT_REPO_DIR }}
- name: Push nightly documentation
if: steps.generate.outputs.DOCS_CHANGED == 'true'
uses: ./skript/.github/workflows/docs/push-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
git_name: Nightly Docs Bot
git_email: nightlydocs@skriptlang.org
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
with:
docs_deploy_key: ${{ secrets.DOCS_DEPLOY_KEY }}
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
cleanup_pattern: "!(nightly|archives)"
- name: Generate documentation
uses: ./skript/.github/workflows/docs/generate-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
skript_repo_dir: ${{ steps.configuration.outputs.SKRIPT_REPO_DIR }}
is_release: true
cleanup_pattern: "!(nightly|archives|templates)"
- name: Push release documentation
uses: ./skript/.github/workflows/docs/push-docs
with:
Expand Down Expand Up @@ -68,14 +68,12 @@ jobs:
- name: Generate documentation
uses: ./skript/.github/workflows/docs/generate-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
skript_repo_dir: ${{ steps.configuration.outputs.SKRIPT_REPO_DIR }}
is_release: true
- name: Push archive documentation
uses: ./skript/.github/workflows/docs/push-docs
with:
docs_output_dir: ${{ steps.configuration.outputs.DOCS_OUTPUT_DIR }}
docs_repo_dir: ${{ steps.configuration.outputs.DOCS_REPO_DIR }}
git_name: Archive Docs Bot
git_email: archivedocs@skriptlang.org
Expand Down
31 changes: 23 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ license {
exclude('**/*.json') // JSON files do not have headers
}

javadoc {
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
options.encoding = 'UTF-8'
// currently our javadoc has a lot of errors, so we need to suppress the linter
options.addStringOption('Xdoclint:none', '-quiet')
}

task releaseJavadoc(type: Javadoc) {
title = project.property('version')
source = sourceSets.main.allJava
Expand Down Expand Up @@ -394,3 +386,26 @@ task nightlyRelease(type: ShadowJar) {
)
}
}

javadoc {
dependsOn nightlyResources

source = sourceSets.main.allJava

exclude("ch/njol/skript/conditions/**")
exclude("ch/njol/skript/expressions/**")
exclude("ch/njol/skript/effects/**")
exclude("ch/njol/skript/events/**")
exclude("ch/njol/skript/sections/**")
exclude("ch/njol/skript/structures/**")
exclude("ch/njol/skript/lang/function/EffFunctionCall.java")
exclude("ch/njol/skript/lang/function/ExprFunctionCall.java")
exclude("ch/njol/skript/hooks/**")
exclude("ch/njol/skript/test/**")

classpath = configurations.compileClasspath + sourceSets.main.output
options.encoding = 'UTF-8'
// currently our javadoc has a lot of errors, so we need to suppress the linter
options.addStringOption('Xdoclint:none', '-quiet')
}

2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class Documentation {
private static final Pattern CP_EMPTY_PARSE_MARKS_PATTERN = Pattern.compile("\\(\\)");
private static final Pattern CP_PARSE_TAGS_PATTERN = Pattern.compile("(?<=[(|\\[ ])[-a-zA-Z0-9!$#%^&*_+~=\"'<>?,.]*?:");
private static final Pattern CP_EXTRA_OPTIONAL_PATTERN = Pattern.compile("\\[\\(((\\w+? ?)+)\\)]");
private static final File DOCS_TEMPLATE_DIRECTORY = new File(Skript.getInstance().getDataFolder(), "doc-templates");
private static final File DOCS_TEMPLATE_DIRECTORY = new File(Skript.getInstance().getDataFolder(), "docs/templates");
private static final File DOCS_OUTPUT_DIRECTORY = new File(Skript.getInstance().getDataFolder(), "docs");

/**
Expand Down