Skip to content

Commit

Permalink
Setup workflows to copy swagger files (#865)
Browse files Browse the repository at this point in the history
* Copy swagger job for smart-contract-verifier

* Update directory name not to contain file name

* feat(gh-action): add tag extraction, rename file, add commit msg

---------

Co-authored-by: sevenzing <41516657+sevenzing@users.noreply.github.com>
  • Loading branch information
rimrakhimov and sevenzing authored Sep 5, 2024
1 parent 040868d commit 6f1cf03
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 1 deletion.
94 changes: 94 additions & 0 deletions .github/workflows/_push_swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Copy Swagger

on:
workflow_call:
secrets:
api_token_github:
description: 'GitHub API token'
required: true
inputs:
user_name:
description: 'Commit username'
required: false
default: 'blockscout-bot'
type: string
user_email:
description: 'Commit user email'
required: false
type: string
default: 'bot@blockscout.com'
service_name:
description: 'Service name (e.g., smart-contract-verifier)'
required: true
type: string
swagger_path:
description: 'Path to the swagger file'
required: true
type: string
workflow_dispatch:
inputs:
user_name:
description: 'Commit username'
required: false
default: 'blockscout-bot'
type: string
user_email:
description: 'Commit user email'
required: false
default: 'bot@blockscout.com'
type: string
service_name:
description: 'Service name (e.g., smart-contract-verifier)'
required: true
type: string
swagger_path:
description: 'Path to the swagger file'
required: true
type: string
version:
description: 'Version to set if manually triggered'
required: true
type: string

jobs:
copy-swagger:
name: Copy swagger
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get the current tag, branch, or commit hash
id: git_info
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ inputs.version }}" >> $GITHUB_ENV
else
if [[ "${GITHUB_REF}" =~ refs/tags/${{ inputs.service_name }}/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
version=$(echo "${GITHUB_REF}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')
echo "version=${version}" >> $GITHUB_ENV
# If it's the main branch
elif [ "${GITHUB_REF#refs/heads/}" = "main" ]; then
echo "version=main" >> $GITHUB_ENV
# Otherwise, use the first 8 characters of the commit hash
else
echo "version=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
fi
fi
echo "version=${version}"
- name: Push swagger to another repo
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.api_token_github || secrets.BLOCKSCOUT_BOT_TOKEN }}
with:
source_file: ${{ inputs.swagger_path }}
rename: 'swagger.yaml'
commit_message: '[BOT] [CREATE-SWAGGER] [SKIP-GH-PAGES] create swagger for "${{ inputs.service_name }}" of version ${{ env.version }}'
destination_repo: 'blockscout/swaggers'
destination_folder: "services/${{ inputs.service_name }}/${{ env.version }}"
user_email: ${{ inputs.user_email }}
user_name: ${{ inputs.user_name }}
destination_branch: 'master'
11 changes: 10 additions & 1 deletion .github/workflows/bens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,13 @@ jobs:
secrets: inherit
with:
version: ${{ needs.push.outputs.semver }}
project_name: blockscout-ens
project_name: blockscout-ens

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'bens'
swagger_path: 'blockscout-ens/bens-proto/swagger/bens.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/da-indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ jobs:
uses: ./.github/workflows/_docker-build-push.yml
with:
service-name: da-indexer

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'da-indexer'
swagger_path: 'da-indexer/da-indexer-proto/swagger/v1/da-indexer.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/eth-bytecode-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ jobs:
uses: ./.github/workflows/_docker-build-push.yml
with:
service-name: eth-bytecode-db

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'eth-bytecode-db'
swagger_path: 'eth-bytecode-db/eth-bytecode-db-proto/swagger/v2/eth-bytecode-db.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/proxy-verifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ jobs:
uses: ./.github/workflows/_docker-build-push.yml
with:
service-name: proxy-verifier

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'proxy-verifier'
swagger_path: 'proxy-verifier/proxy-verifier-proto/swagger/v1/proxy-verifier.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
10 changes: 10 additions & 0 deletions .github/workflows/sig-provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ jobs:
uses: ./.github/workflows/_docker-build-push.yml
with:
service-name: sig-provider


push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'sig-provider'
swagger_path: 'sig-provider/sig-provider-proto/swagger/sig-provider.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/smart-contract-verifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ jobs:
uses: ./.github/workflows/_docker-build-push.yml
with:
service-name: smart-contract-verifier

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'smart-contract-verifier'
swagger_path: 'smart-contract-verifier/smart-contract-verifier-proto/swagger/v2/smart-contract-verifier.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
10 changes: 10 additions & 0 deletions .github/workflows/stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,13 @@ jobs:
with:
version: ${{ needs.docker.outputs.tag-value }}
project_name: stats


push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'stats'
swagger_path: 'stats/stats-proto/swagger/stats.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/user-ops-indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ jobs:
uses: ./.github/workflows/_docker-build-push.yml
with:
service-name: user-ops-indexer

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'user-ops-indexer'
swagger_path: 'user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/visualizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ jobs:
with:
version: ${{ needs.docker.outputs.tag-value }}
project_name: visualizer

push-swagger:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags'))
uses: ./.github/workflows/_push_swagger.yml
with:
service_name: 'visualizer'
swagger_path: 'visualizer/visualizer-proto/swagger/visualizer.swagger.yaml'
secrets:
api_token_github: ${{ secrets.BLOCKSCOUT_BOT_TOKEN }}

0 comments on commit 6f1cf03

Please sign in to comment.