-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
308 additions
and
487 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
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 |
---|---|---|
|
@@ -8,229 +8,19 @@ on: | |
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
release-context: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version-name: ${{ github.ref_name }} | ||
is-latest: ${{ steps.compare-tags.outputs.is-latest }} | ||
steps: | ||
- uses: joutvhu/get-release@v1 | ||
id: latest-release | ||
with: | ||
latest: true | ||
throwing: false | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Compare tags | ||
id: compare-tags | ||
env: | ||
REF_TYPE: ${{ github.ref_type }} | ||
REF_NAME: ${{ github.ref_name }} | ||
LATEST_TAG: ${{ steps.latest-release.outputs.tag_name }} | ||
run: | | ||
if [ "${REF_TYPE}" == 'tag' ] && [ "${REF_NAME}" == "${LATEST_TAG}" ]; then | ||
echo 'is-latest=true' >> "${GITHUB_OUTPUT}" | ||
else | ||
echo 'is-latest=false' >> "${GITHUB_OUTPUT}" | ||
fi | ||
spm-context: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
package-dump: ${{ steps.dump-package.outputs.package-dump }} | ||
steps: | ||
- uses: swift-actions/[email protected] | ||
with: | ||
swift-version: '5.7' | ||
- uses: actions/checkout@v4 | ||
# We don't use a cache here, because SPM doesn't resolve dependencies when dumping packages. | ||
- name: Dump package | ||
id: dump-package | ||
run: | | ||
delimiter="$(openssl rand -hex 8)" | ||
echo "package-dump<<${delimiter}" >> "${GITHUB_OUTPUT}" | ||
swift package dump-package >> "${GITHUB_OUTPUT}" | ||
echo "${delimiter}" >> "${GITHUB_OUTPUT}" | ||
permissions: | ||
contents: write | ||
|
||
generate-docs: | ||
needs: | ||
- release-context | ||
- spm-context | ||
runs-on: macos-12 | ||
strategy: | ||
matrix: | ||
target: ${{ fromJson(needs.spm-context.outputs.package-dump).products.*.targets.* }} | ||
steps: | ||
- uses: swift-actions/[email protected] | ||
id: swift-setup | ||
with: | ||
swift-version: '5.7' | ||
- name: Read OS Version | ||
uses: sersoft-gmbh/os-version-action@v3 | ||
id: os-version | ||
- uses: actions/checkout@v4 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: .build | ||
key: ${{ runner.os }}-${{ steps.os-version.outputs.version }}-spm-${{ steps.swift-setup.outputs.version }}-${{ hashFiles('**/Package.resolved') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ steps.os-version.outputs.version }}-spm-${{ steps.swift-setup.outputs.version }}- | ||
- uses: sersoft-gmbh/swifty-docs-action@v3 | ||
env: | ||
ENABLE_DOCC_SUPPORT: '1' | ||
DOCC_JSON_PRETTYPRINT: 'YES' | ||
with: | ||
package-version: ${{ needs.release-context.outputs.version-name }} | ||
targets: ${{ matrix.target }} | ||
enable-inherited-docs: true | ||
enable-index-building: false | ||
transform-for-static-hosting: true | ||
hosting-base-path: ${{ github.event.repository.name }}/${{ needs.release-context.outputs.version-name }} | ||
output: ${{ matrix.target }}-docs | ||
- name: Package docs | ||
env: | ||
TARGET: ${{ matrix.target }} | ||
run: tar -cvf "${TARGET}-docs.tar" "${TARGET}-docs" | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ matrix.target }}-docs | ||
path: ${{ matrix.target }}-docs.tar | ||
concurrency: | ||
group: ${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
publish-docs: | ||
needs: | ||
- release-context | ||
- spm-context | ||
- generate-docs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: gh-pages | ||
path: repository | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
path: artifacts | ||
- name: Extract tars | ||
run: find artifacts -name '*.tar' -execdir tar -xvf '{}' --strip-components 1 \; -delete | ||
- name: Merge documentations | ||
env: | ||
TARGETS: ${{ join(fromJson(needs.spm-context.outputs.package-dump).products.*.targets.*, ' ') }} | ||
DOCS_BASE_DIR: repository/${{ needs.release-context.outputs.version-name }} | ||
run: | | ||
rm -rf "${DOCS_BASE_DIR}" | ||
is_first=1 | ||
for target in $TARGETS; do | ||
if [ $is_first -eq 1 ]; then | ||
echo "Copying initial documentation for ${target}" | ||
cp -R "artifacts/${target}-docs" "${DOCS_BASE_DIR}" | ||
is_first=0 | ||
else | ||
echo "Merging documentation for ${target}" | ||
cp -R "artifacts/${target}-docs/data/documentation/"* "${DOCS_BASE_DIR}/data/documentation/" | ||
cp -R "artifacts/${target}-docs/documentation/"* "${DOCS_BASE_DIR}/documentation/" | ||
fi | ||
done | ||
echo "Deleting non-mergable metadata.json" | ||
rm -f "${DOCS_BASE_DIR}/metadata.json" | ||
- name: Create version index | ||
working-directory: repository | ||
env: | ||
TARGET_DOCS_DIR: ${{ needs.release-context.outputs.version-name }}/documentation | ||
INDEX_FILE: ${{ needs.release-context.outputs.version-name }}/index.html | ||
BASE_URL: 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ needs.release-context.outputs.version-name }}/documentation' | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
run: | | ||
target_count=0 | ||
target_list="" | ||
single_target_name="" | ||
for target in $(ls "${TARGET_DOCS_DIR}"); do | ||
if [ -d "${TARGET_DOCS_DIR}/${target}" ]; then | ||
single_target_name="${target}" | ||
target_count=$((target_count+1)) | ||
target_list="${target_list}<li><a href=\"${BASE_URL}/${target}\"><code>${target}</code> Documentation</a></li>" | ||
fi | ||
done | ||
if [ ${target_count} -gt 1 ]; then | ||
echo "Found ${target_count} targets. Generating list..." | ||
cat > "${INDEX_FILE}" <<EOF | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>${REPO_NAME} Documentation</title> | ||
</head> | ||
<body> | ||
<ul> | ||
${target_list} | ||
</ul> | ||
</body> | ||
</html> | ||
EOF | ||
else | ||
echo "Found one target. Generating redirect file to target ${single_target_name}" | ||
cat > "${INDEX_FILE}" <<EOF | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>${REPO_NAME} Documentation</title> | ||
<meta http-equiv="refresh" content="0; url=${BASE_URL}/${single_target_name}" /> | ||
</head> | ||
<body> | ||
<p>Redirecting...</p> | ||
</body> | ||
</html> | ||
EOF | ||
fi | ||
- name: Create root index | ||
working-directory: repository | ||
env: | ||
REDIRECT_URL: 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/latest' | ||
REPO_NAME: ${{ github.event.repository.name }} | ||
run: | | ||
cat > 'index.html' <<EOF | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>${REPO_NAME} Documentation</title> | ||
<meta http-equiv="refresh" content="0; url=${REDIRECT_URL}" /> | ||
</head> | ||
<body> | ||
<p>Redirecting...</p> | ||
</body> | ||
</html> | ||
EOF | ||
- name: Create latest symlink | ||
if: ${{ needs.release-context.outputs.is-latest }} | ||
working-directory: repository | ||
env: | ||
VERSION_NAME: ${{ needs.release-context.outputs.version-name }} | ||
run: | | ||
rm -f 'latest' | ||
ln -s "${VERSION_NAME}" 'latest' | ||
- name: Determine changes | ||
id: check-changes | ||
working-directory: repository | ||
run: | | ||
if [ -n "$(git status --porcelain)" ]; then | ||
echo 'has-changes=true' >> "${GITHUB_OUTPUT}" | ||
else | ||
echo 'has-changes=false' >> "${GITHUB_OUTPUT}" | ||
fi | ||
- uses: crazy-max/ghaction-github-pages@v4 | ||
if: ${{ steps.check-changes.outputs.has-changes }} | ||
with: | ||
keep_history: true | ||
build_dir: repository | ||
commit_message: Deploy documentation for '${{ needs.release-context.outputs.version-name }}' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
cleanup: | ||
needs: | ||
- generate-docs | ||
- publish-docs | ||
if: ${{ always() }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cleanup Artifacts | ||
uses: joutvhu/delete-artifact@v1 | ||
jobs: | ||
generate-and-publish-docs: | ||
uses: sersoft-gmbh/oss-common-actions/.github/workflows/swift-generate-and-publish-docs.yml@main | ||
with: | ||
os: macOS | ||
swift-version: '5.9' | ||
organisation: ${{ github.repository_owner }} | ||
repository: ${{ github.event.repository.name }} | ||
pages-branch: gh-pages |
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
Oops, something went wrong.