Deploy Javadoc #405
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
name: Deploy Javadoc | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
push: | |
branches: | |
- '**javadoc**' | |
jobs: | |
check-new-release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
- uses: actions/github-script@v7 | |
id: versions | |
with: | |
result-encoding: json | |
script: | | |
const fs = require('fs'); | |
const opts = github.rest.repos.listReleases.endpoint.merge({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const releases = await github.paginate(opts); | |
const missings = []; | |
releases.forEach((release) => { | |
if (!release.draft && !release.prerelease && release.tag_name) { | |
if (!fs.existsSync(release.tag_name)) { | |
missings.push(release.tag_name); | |
} | |
} | |
}); | |
return missings; | |
outputs: | |
versions: ${{ steps.versions.outputs.result }} | |
deploy-new-javadoc: | |
needs: | |
- check-new-release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
- id: download-javadoc | |
if: > | |
needs.check-new-release.outputs.versions != '[]' | |
env: | |
MISSING_VERSIONS: ${{ join(fromJSON(needs.check-new-release.outputs.versions), ' ') }} | |
run: | | |
for version in $MISSING_VERSIONS; do | |
url="https://repo1.maven.org/maven2/com/deploygate/sdk/${version}/sdk-${version}-javadoc.jar" | |
dist="$version" | |
mkdir -p "$dist" | |
if curl -sSfL -I --url "$url"; then | |
curl -sSfL \ | |
-X GET \ | |
--url "$url" \ | |
-o javadoc.jar | |
unzip javadoc.jar -d "$dist/" | |
rm javadoc.jar | |
fi | |
if [[ ! -f "$dist/index.html" ]]; then | |
rm -fr "$dist" | |
fi | |
done | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const opts = github.rest.repos.listReleases.endpoint.merge({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const releases = await github.paginate(opts); | |
const metadata = []; | |
for (const release of releases) { | |
if (release.draft || release.prerelease) { | |
continue; | |
} | |
try { | |
fs.mkdirSync(release.tag_name); | |
console.log(`javadocs of ${release.tag_name} are not found`); | |
metadata.push({ | |
version: release.tag_name, | |
release_link: release.html_url, | |
released_at: release.published_at | |
}); | |
} catch (e) { | |
console.log(`javadocs of ${release.tag_name} are found`); | |
metadata.push({ | |
version: release.tag_name, | |
javadoc_link: release.tag_name, | |
release_link: release.html_url, | |
released_at: release.published_at | |
}); | |
} | |
} | |
fs.writeFileSync('releases.json', JSON.stringify(metadata)); | |
- name: "commit and push if needed" | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "github pages automation" | |
git add . | |
if git commit -m ":rocket: ${{ needs.check-new-release.outputs.latest-version }} javadoc"; then | |
if [[ "${{ github.event_name }}" = "push" ]]; then | |
echo 'git push origin gh-pages (dry-run)' | |
else | |
git push origin gh-pages | |
fi | |
fi |