Update Swagger UI #610
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: Update Swagger UI | |
on: | |
schedule: | |
- cron: "0 10 * * *" | |
repository_dispatch: | |
types: [update-swagger-ui] | |
workflow_dispatch: | |
jobs: | |
updateSwagger: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Get Latest Swagger UI Release | |
id: swagger-ui | |
run: | | |
echo ::set-output name=release_tag::$(curl -sL https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | jq -r ".tag_name") | |
echo ::set-output name=current_tag::$(<docs/swagger-ui.version) | |
- name: Update Swagger UI | |
if: steps.swagger-ui.outputs.current_tag != steps.swagger-ui.outputs.release_tag | |
env: | |
RELEASE_TAG: ${{ steps.swagger-ui.outputs.release_tag }} | |
SWAGGER_YAML: "openapi.json" | |
run: | | |
# Delete the dist directory and docs/index.html | |
rm -fr docs/dist docs/index.html | |
# Download the release | |
curl -sL -o $RELEASE_TAG https://api.github.com/repos/swagger-api/swagger-ui/tarball/$RELEASE_TAG | |
# make sure the docs directory exists | |
mkdir -p docs | |
# Extract the dist directory into the ./docs directory | |
tar -xzf $RELEASE_TAG --directory ./docs/ --strip-components=1 $(tar -tzf $RELEASE_TAG | head -1 | cut -f1 -d"/")/dist | |
rm $RELEASE_TAG | |
# Move index.html to the root | |
mv docs/dist/index.html docs/. | |
# Fix references in index.html | |
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$SWAGGER_YAML|g" docs/dist/swagger-initializer.js | |
sed -i "s|href=\"./|href=\"dist/|g" docs/index.html | |
sed -i "s|src=\"./|src=\"dist/|g" docs/index.html | |
# Update current release | |
echo ${{ steps.swagger-ui.outputs.release_tag }} > docs/swagger-ui.version | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }} | |
title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }} | |
body: | | |
Updates [swagger-ui][1] to ${{ steps.swagger-ui.outputs.release_tag }} | |
Auto-generated by [create-pull-request][2] | |
[1]: https://github.com/swagger-api/swagger-ui | |
[2]: https://github.com/peter-evans/create-pull-request | |
labels: dependencies, automated pr | |
branch: swagger-ui-updates |