From 1959dc68b629404c8114ddfdc61d93fb60ac153e Mon Sep 17 00:00:00 2001 From: sevenzing <41516657+sevenzing@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:52:26 +0200 Subject: [PATCH] feat(gh-action): add tag extraction, rename file, add commit msg --- .github/workflows/_push_swagger.yml | 65 +++++++++++ .github/workflows/smart-contract-verifier.yml | 110 ++++++++---------- 2 files changed, 116 insertions(+), 59 deletions(-) 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..f50a27a23 --- /dev/null +++ b/.github/workflows/_push_swagger.yml @@ -0,0 +1,65 @@ +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 + +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_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 + + - name: Push swagger to another repo + uses: dmnemec/copy_file_to_another_repo_action@main + env: + API_TOKEN_GITHUB: ${{ secrets.api_token_github }} + 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/smart-contract-verifier.yml b/.github/workflows/smart-contract-verifier.yml index 4f6b4bd60..ab369c9d1 100644 --- a/.github/workflows/smart-contract-verifier.yml +++ b/.github/workflows/smart-contract-verifier.yml @@ -23,64 +23,56 @@ defaults: working-directory: smart-contract-verifier jobs: - test: - name: Unit, doc and integration tests - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 +# test: +# name: Unit, doc and integration tests +# runs-on: ubuntu-latest +# steps: +# - name: Checkout sources +# uses: actions/checkout@v4 +# +# - name: Setup +# uses: ./.github/actions/setup +# with: +# working-directory: smart-contract-verifier +# +# - name: Unit tests +# run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --all-features --lib --bins -- --nocapture +# if: success() || failure() +# +# - name: Doc tests +# run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --all-features --doc -- --skip proto +# if: success() || failure() +# +# - name: Integration tests +# run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --test '*' -- --nocapture +# if: success() || failure() +# +# lint: +# name: Linting +# uses: ./.github/workflows/_linting.yml +# with: +# working-directory: smart-contract-verifier +# +# docker: +# name: Docker build and docker push +# needs: +# - test +# - lint +# if: | +# always() && +# (needs.test.result == 'success' || needs.test.result == 'cancelled') && +# (needs.lint.result == 'success' || needs.lint.result == 'cancelled') +# uses: ./.github/workflows/_docker-build-push.yml +# with: +# service-name: smart-contract-verifier - - name: Setup - uses: ./.github/actions/setup - with: - working-directory: smart-contract-verifier - - - name: Unit tests - run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --all-features --lib --bins -- --nocapture - if: success() || failure() - - - name: Doc tests - run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --all-features --doc -- --skip proto - if: success() || failure() - - - name: Integration tests - run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --test '*' -- --nocapture - if: success() || failure() - - lint: - name: Linting - uses: ./.github/workflows/_linting.yml + push-swagger: + # if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')) + uses: ./.github/workflows/_push_swagger.yml with: - working-directory: smart-contract-verifier - - docker: - name: Docker build and docker push - needs: - - test - - lint - if: | - always() && - (needs.test.result == 'success' || needs.test.result == 'cancelled') && - (needs.lint.result == 'success' || needs.lint.result == 'cancelled') - uses: ./.github/workflows/_docker-build-push.yml - with: - service-name: smart-contract-verifier - - copy-swagger: - name: Copy swagger - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Pushes - uses: dmnemec/copy_file_to_another_repo_action@main - env: - API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} - with: - source_file: 'smart-contract-verifier/smart-contract-verifier-proto/swagger/v2/smart-contract-verifier.swagger.yaml' - destination_repo: 'blockscout/swaggers' - destination_folder: 'services/smart-contract-verifier' - user_email: 'rimrakhimov@gmail.com ' - user_name: 'rimrakhimov' - destination_branch: 'master' \ No newline at end of file + user_name: 'blockscout-bot' + user_email: 'bot@blockscout.com' + 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 }}