Update Swagger UI #617
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 4 * * *" | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
updateSwagger: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GREENBONE_BOT_TOKEN }} | |
- name: Get Latest Swagger UI Release | |
id: swagger-ui | |
run: | | |
release_tag=$(curl -sL https://api.github.com/repos/swagger-api/swagger-ui/releases/latest | jq -r ".tag_name") | |
echo "release_tag=$release_tag" >> $GITHUB_OUTPUT | |
current_tag=$(<swagger-ui.version) | |
echo "current_tag=$current_tag" >> $GITHUB_OUTPUT | |
echo ${{ github.ref }} | |
- name: Setup pontos | |
uses: greenbone/actions/setup-pontos@v3 | |
- name: Set git name, mail and origin | |
uses: greenbone/actions/set-github-user@v3 | |
with: | |
user: ${{ secrets.GREENBONE_BOT }} | |
mail: ${{ secrets.GREENBONE_BOT_MAIL }} | |
token: ${{ secrets.GREENBONE_BOT_TOKEN }} | |
# Enable admin bypass | |
- name: Allow admin users bypassing protection | |
uses: greenbone/actions/admin-bypass@v3 | |
with: | |
allow: "true" | |
github-token: ${{ secrets.GREENBONE_BOT_TOKEN }} | |
- name: Update Swagger UI | |
if: steps.swagger-ui.outputs.current_tag != steps.swagger-ui.outputs.release_tag | |
env: | |
GH_TOKEN: ${{ github.token }} | |
GITHUB_TOKEN: ${{ secrets.GREENBONE_BOT_TOKEN }} | |
RELEASE_TAG: ${{ steps.swagger-ui.outputs.release_tag }} | |
SWAGGER_YAML: "urls: [{ url: \"https://raw.githubusercontent.com/greenbone/openvas-scanner/main/rust/doc/openapi.yml\", name: \"Scanner API\" },{ url: \"https://raw.githubusercontent.com/greenbone/openvas-scanner/main/rust/doc/reverse-sensor-openapi.yml\", name: \"Reverse Scanner API\" }],\"urls.primaryName\": \"Scanner API\"," | |
SWAGGER_OLD_YML: "url: \"https://petstore.swagger.io/v2/swagger.json\"," | |
run: | | |
# Delete the dist directory and index.html | |
rm -fr dist index.html | |
# Download the release | |
curl -sL -o $RELEASE_TAG https://api.github.com/repos/swagger-api/swagger-ui/tarball/$RELEASE_TAG | |
# Extract the dist directory | |
tar -xzf $RELEASE_TAG --strip-components=1 $(tar -tzf $RELEASE_TAG | head -1 | cut -f1 -d"/")/dist | |
rm $RELEASE_TAG | |
# Move index.html to the root | |
mv dist/index.html . | |
# Fix references in dist/swagger-initializer and index.html | |
sed -i "s|$SWAGGER_OLD_YML|$SWAGGER_YAML|g" dist/swagger-initializer.js | |
sed -i "s|href=\"./|href=\"dist/|g" index.html | |
sed -i "s|src=\"./|src=\"dist/|g" index.html | |
sed -i "s|href=\"index|href=\"dist/index|g" index.html | |
# Update current release | |
echo ${{ steps.swagger-ui.outputs.release_tag }} > swagger-ui.version | |
# delete previous branch if there is an unmerged PR open | |
git push origin :swagger-ui-update || true | |
# Create Branch | |
git checkout -b swagger-ui-update | |
# Create Pull Request | |
git add . | |
git commit -m "Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }}" | |
git push origin swagger-ui-update | |
pontos-github pr create ${{ github.repository }} swagger-ui-update ${{ github.ref }} 'Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }}' --body "Updates [swagger-ui][1] to ${{ steps.swagger-ui.outputs.release_tag }}\n\nAuto-generated Pull Request\n\n[1]: https://github.com/swagger-api/swagger-ui" | |
- name: Disable bypassing protection for admin users | |
if: always() | |
uses: greenbone/actions/admin-bypass@v3 | |
with: | |
allow: "false" | |
github-token: ${{ secrets.GREENBONE_BOT_TOKEN }} |