-
Notifications
You must be signed in to change notification settings - Fork 115
94 lines (88 loc) · 3.03 KB
/
_push_swagger.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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: '[email protected]'
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: '[email protected]'
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" ] && [ ! -z "${{ inputs.version }}" ]; 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'