|
| 1 | +name: Copy Swagger |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + api_token_github: |
| 7 | + description: 'GitHub API token' |
| 8 | + required: true |
| 9 | + inputs: |
| 10 | + user_name: |
| 11 | + description: 'Commit username' |
| 12 | + required: false |
| 13 | + default: 'blockscout-bot' |
| 14 | + type: string |
| 15 | + user_email: |
| 16 | + description: 'Commit user email' |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: 'bot@blockscout.com' |
| 20 | + service_name: |
| 21 | + description: 'Service name (e.g., smart-contract-verifier)' |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + swagger_path: |
| 25 | + description: 'Path to the swagger file' |
| 26 | + required: true |
| 27 | + type: string |
| 28 | + workflow_dispatch: |
| 29 | + inputs: |
| 30 | + user_name: |
| 31 | + description: 'Commit username' |
| 32 | + required: false |
| 33 | + default: 'blockscout-bot' |
| 34 | + type: string |
| 35 | + user_email: |
| 36 | + description: 'Commit user email' |
| 37 | + required: false |
| 38 | + default: 'bot@blockscout.com' |
| 39 | + type: string |
| 40 | + service_name: |
| 41 | + description: 'Service name (e.g., smart-contract-verifier)' |
| 42 | + required: true |
| 43 | + type: string |
| 44 | + swagger_path: |
| 45 | + description: 'Path to the swagger file' |
| 46 | + required: true |
| 47 | + type: string |
| 48 | + version: |
| 49 | + description: 'Version to set if manually triggered' |
| 50 | + required: true |
| 51 | + type: string |
| 52 | + |
| 53 | +jobs: |
| 54 | + copy-swagger: |
| 55 | + name: Copy swagger |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - name: Checkout |
| 59 | + uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: Get the current tag, branch, or commit hash |
| 62 | + id: git_info |
| 63 | + run: | |
| 64 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 65 | + echo "version=${{ inputs.version }}" >> $GITHUB_ENV |
| 66 | + else |
| 67 | + if [[ "${GITHUB_REF}" =~ refs/tags/${{ inputs.service_name }}/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then |
| 68 | + version=$(echo "${GITHUB_REF}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+') |
| 69 | + echo "version=${version}" >> $GITHUB_ENV |
| 70 | +
|
| 71 | + # If it's the main branch |
| 72 | + elif [ "${GITHUB_REF#refs/heads/}" = "main" ]; then |
| 73 | + echo "version=main" >> $GITHUB_ENV |
| 74 | +
|
| 75 | + # Otherwise, use the first 8 characters of the commit hash |
| 76 | + else |
| 77 | + echo "version=${GITHUB_SHA:0:8}" >> $GITHUB_ENV |
| 78 | + fi |
| 79 | + fi |
| 80 | + echo "version=${version}" |
| 81 | +
|
| 82 | + - name: Push swagger to another repo |
| 83 | + uses: dmnemec/copy_file_to_another_repo_action@main |
| 84 | + env: |
| 85 | + API_TOKEN_GITHUB: ${{ secrets.api_token_github || secrets.BLOCKSCOUT_BOT_TOKEN }} |
| 86 | + with: |
| 87 | + source_file: ${{ inputs.swagger_path }} |
| 88 | + rename: 'swagger.yaml' |
| 89 | + commit_message: '[BOT] [CREATE-SWAGGER] [SKIP-GH-PAGES] create swagger for "${{ inputs.service_name }}" of version ${{ env.version }}' |
| 90 | + destination_repo: 'blockscout/swaggers' |
| 91 | + destination_folder: "services/${{ inputs.service_name }}/${{ env.version }}" |
| 92 | + user_email: ${{ inputs.user_email }} |
| 93 | + user_name: ${{ inputs.user_name }} |
| 94 | + destination_branch: 'master' |
0 commit comments