Skip to content

fix: clean-up metadata outputs #68

fix: clean-up metadata outputs

fix: clean-up metadata outputs #68

Workflow file for this run

name: Create index.html for new swagger.yaml
on:
push:
paths:
- '**/swagger.yaml'
jobs:
create-swagger-version:
if: "contains(github.event.commits[0].message, '[CREATE-SWAGGER]')"
env:
GITHUB_TOKEN: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
GH_TOKEN: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# fetch the last 2 commits to check difference
fetch-depth: 2
- name: Check commit message
id: check-commit
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Commit message: $COMMIT_MESSAGE"
if [[ "$COMMIT_MESSAGE" != *"[BOT]"* || "$COMMIT_MESSAGE" != *"[CREATE-SWAGGER]"* ]]; then
echo "The commit message does not contain [BOT] and [CREATE-SWAGGER]. Exiting."
exit 1
fi
- name: Find swagger.yaml file actions
id: find-swagger-action
run: |
# Find swagger.yaml files and identify their action (A or M)
git diff --name-status master~1 master | grep 'swagger.yaml' | while read status file; do
if [ "$status" = "A" ]; then
echo "SWAGGER_FILE_ACTION=new" >> $GITHUB_OUTPUT
echo "$file" >> swagger_files.txt
elif [ "$status" = "M" ]; then
echo "SWAGGER_FILE_ACTION=modified" >> $GITHUB_OUTPUT
echo "$file" >> swagger_files.txt
fi
done
if [ ! -f swagger_files.txt ]; then
echo "No relevant swagger.yaml changes found. Exiting."
exit 1
fi
- name: Handle new swagger file
if: ${{ steps.find-swagger-action.outputs.SWAGGER_FILE_ACTION == 'new' }}
run: |
while IFS= read -r file; do
dir=$(dirname "$file")
mkdir -p "$dir"
cp utils/default_swagger_index_page.html "$dir/index.html"
version=$(basename "$dir")
parent_dir=$(dirname "$dir")
echo "$version" >> "$parent_dir/hosted_versions.txt"
done < swagger_files.txt
rm swagger_files.txt
- name: Commit and push changes
if: ${{ steps.find-swagger-action.outputs.SWAGGER_FILE_ACTION == 'new' }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "blockscout-bot"
git add .
git commit -m "[BOT] [SKIP-GH-PAGES] Add index.html for new swagger.yaml files"
git fetch origin master
if git rebase origin/master; then
git push origin master
else
git rebase --abort
exit 1
fi
- name: Trigger github-pages workflow
if: ${{ steps.find-swagger-action.outputs.SWAGGER_FILE_ACTION == 'new' || steps.find-swagger-action.outputs.SWAGGER_FILE_ACTION == 'modified' }}
uses: actions/github-script@v4
with:
github-token: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
script: |
await github.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'jekyll-gh-pages.yml',
ref: 'master'
});