From 6f1cf03f1b801d2bf627445e312eddde61a87815 Mon Sep 17 00:00:00 2001 From: Rim Rakhimov Date: Thu, 5 Sep 2024 18:20:43 +0300 Subject: [PATCH] Setup workflows to copy swagger files (#865) * 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> --- .github/workflows/_push_swagger.yml | 94 +++++++++++++++++++ .github/workflows/bens.yml | 11 ++- .github/workflows/da-indexer.yml | 9 ++ .github/workflows/eth-bytecode-db.yml | 9 ++ .github/workflows/proxy-verifier.yml | 9 ++ .github/workflows/sig-provider.yml | 10 ++ .github/workflows/smart-contract-verifier.yml | 9 ++ .github/workflows/stats.yml | 10 ++ .github/workflows/user-ops-indexer.yml | 9 ++ .github/workflows/visualizer.yml | 9 ++ 10 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/_push_swagger.yml diff --git a/.github/workflows/_push_swagger.yml b/.github/workflows/_push_swagger.yml new file mode 100644 index 000000000..9d72ad713 --- /dev/null +++ b/.github/workflows/_push_swagger.yml @@ -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' diff --git a/.github/workflows/bens.yml b/.github/workflows/bens.yml index e75e608ab..6bda8c7fd 100644 --- a/.github/workflows/bens.yml +++ b/.github/workflows/bens.yml @@ -175,4 +175,13 @@ jobs: secrets: inherit with: version: ${{ needs.push.outputs.semver }} - project_name: blockscout-ens \ No newline at end of file + 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 }} \ No newline at end of file diff --git a/.github/workflows/da-indexer.yml b/.github/workflows/da-indexer.yml index 88f3e5a4e..316bd3a7f 100644 --- a/.github/workflows/da-indexer.yml +++ b/.github/workflows/da-indexer.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/eth-bytecode-db.yml b/.github/workflows/eth-bytecode-db.yml index 9004d0daa..c9c939e5c 100644 --- a/.github/workflows/eth-bytecode-db.yml +++ b/.github/workflows/eth-bytecode-db.yml @@ -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 }} diff --git a/.github/workflows/proxy-verifier.yml b/.github/workflows/proxy-verifier.yml index e8705cca9..4bf3cda78 100644 --- a/.github/workflows/proxy-verifier.yml +++ b/.github/workflows/proxy-verifier.yml @@ -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 }} diff --git a/.github/workflows/sig-provider.yml b/.github/workflows/sig-provider.yml index 0fe3cdeeb..7b3fe9d29 100644 --- a/.github/workflows/sig-provider.yml +++ b/.github/workflows/sig-provider.yml @@ -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 }} diff --git a/.github/workflows/smart-contract-verifier.yml b/.github/workflows/smart-contract-verifier.yml index dcd86e63b..b43692097 100644 --- a/.github/workflows/smart-contract-verifier.yml +++ b/.github/workflows/smart-contract-verifier.yml @@ -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 }} diff --git a/.github/workflows/stats.yml b/.github/workflows/stats.yml index ed1d155bb..c23db6dc9 100644 --- a/.github/workflows/stats.yml +++ b/.github/workflows/stats.yml @@ -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 }} diff --git a/.github/workflows/user-ops-indexer.yml b/.github/workflows/user-ops-indexer.yml index 593f28af3..669e7d62a 100644 --- a/.github/workflows/user-ops-indexer.yml +++ b/.github/workflows/user-ops-indexer.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/visualizer.yml b/.github/workflows/visualizer.yml index ea7eef424..f537c4128 100644 --- a/.github/workflows/visualizer.yml +++ b/.github/workflows/visualizer.yml @@ -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 }}