-
Notifications
You must be signed in to change notification settings - Fork 39
196 lines (174 loc) · 7.59 KB
/
boardCardReleaseLive.yaml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Release Boards/Cards from Branch to Live
on:
workflow_dispatch:
inputs:
release_branch:
type: string
description: Which Branch to release Boards from? (change last number to desired number)
default: "new-feature/boards_cards/1"
auto_merge:
type: boolean
description: If checked, PR shall be automatically merged to master branch.
default: false
notify_channel:
type: boolean
description: If checked, mikroe bot will notify mattermost channel with release details.
default: false
jobs:
upload_board_assets_live:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
packages: write
actions: read
steps:
- name: Authorize Mikroe Actions App
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.MIKROE_ACTIONS }}
private-key: ${{ secrets.MIKROE_ACTIONS_KEY_AUTHORIZE }}
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.release_branch }} # Dynamically using the branch input
token: ${{ steps.app-token.outputs.token }}
- name: Add GitHub Actions credentials
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Fetch Master Branch
run: git fetch origin master
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Cache Python packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install p7zip-full
sudo apt-get install -y jq
python -m pip install --upgrade pip
pip install aiohttp
pip install aiofiles
pip install requests
pip install py7zr
pip install pytz
pip install chardet
pip install elasticsearch==7.13.4
pip install packaging
pip install alive-progress
- name: Check for new_hw.md file
id: check_new_hw_file
run: |
FILE_PATH="changelog/new_hw.md"
if [ -f "$FILE_PATH" ]; then
echo "new_hw_present=true" >> $GITHUB_OUTPUT
else
echo "new_hw_present=false" >> $GITHUB_OUTPUT
fi
- name: Update Changelogs
id: changelog_update
run: |
python -u scripts/update_board_changelog.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }}
sdk_tag=$(<sdk_tag.txt)
rm sdk_tag.txt
echo "SDK Tag name is mikroSDK-$sdk_tag"
echo "sdk_tag_name=mikroSDK-$sdk_tag" >> $GITHUB_OUTPUT
python -u scripts/log_changes.py
- name: Remove original changelog file from git
if: ${{ steps.check_new_hw_file.outputs.new_hw_present == 'true' }}
run: |
git rm changelog/new_hw.md
git commit -m "Remove old changelog file after moving it"
git push
- name: Commit Changelog to current branch
run: |
echo "Updating with new changelog files";
git add changelog/**
git commit -m "Updated changelog files with latest release info."
git push
# Create a pull request using the GitHub API
- name: Create Pull Request
id: create_pr
run: |
PR_RESPONSE=$(curl -s -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d "{\"title\":\"Merge branch ${{ github.event.inputs.release_branch }} into master\",\"head\":\"${{ github.event.inputs.release_branch }}\",\"base\":\"master\",\"body\":\"Automatically created pull request to merge branch ${{ github.event.inputs.release_branch }} into master\"}")
echo "$PR_RESPONSE" > pr_response.json
PR_NUMBER=$(jq '.number' pr_response.json)
echo "PR NUMBER IS: ${PR_NUMBER}"
rm pr_response.json
echo "Pull request number is $PR_NUMBER"
echo "pull_request_number=$PR_NUMBER" >> $GITHUB_OUTPUT
# Automatically approve PR
- name: Approve Pull Request
if: ${{ github.event.inputs.auto_merge == 'true' }}
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.MIKROE_ACTIONS_KEY }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create_pr.outputs.pull_request_number }}/reviews \
-d '{"event":"APPROVE"}'
# Automatically merge the pull request using the GitHub API
- name: Automatically Merge Pull Request
if: ${{ github.event.inputs.auto_merge == 'true' }}
run: |
curl -s -X PUT \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create_pr.outputs.pull_request_number }}/merge \
-d "{\"commit_title\":\"Auto-merged PR from ${{ github.event.inputs.release_branch }} to master\",\"merge_method\":\"squash\"}"
- name: Handle Merge Conflict
if: failure()
run: echo "::error::Merge conflict occurred. Please resolve manually."
- name: Run Index Script
env:
ES_HOST: ${{ secrets.ES_HOST }}
ES_USER: ${{ secrets.ES_USER }}
ES_PASSWORD: ${{ secrets.ES_PASSWORD }}
MIKROE_NECTO_AWS: ${{ secrets.MIKROE_NECTO_AWS }}
run: |
if [[ ${{ steps.changelog_update.outputs.sdk_tag_name }} != "mikroSDK-0" ]]; then
echo "Indexing to Live."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ steps.changelog_update.outputs.sdk_tag_name }} ${{ secrets.ES_INDEX_LIVE }} "False" "--board_card_only" "True"
fi
- name: Trigger database update in Core repo
run: |
if [[ ${{ steps.changelog_update.outputs.sdk_tag_name }} != "mikroSDK-0" ]]; then
# Set the required variables
repo_owner="MikroElektronika"
repo_name="core_packages"
event_type="trigger-workflow"
version="${{ steps.changelog_update.outputs.sdk_tag_name }}"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.MIKROE_ACTIONS_KEY }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"version\": \"$version\", \"index\": \"Live\", \"unit\": false, \"integration\": true}}"
fi
- name: Build Message with Python
if: ${{ github.event.inputs.notify_channel == 'true' }}
run: |
python -u scripts/build_message.py > message.txt
- name: Send notification to Mattermost
if: ${{ github.event.inputs.notify_channel == 'true' }}
env:
MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
run: |
MESSAGE=$(cat message.txt)
curl -X POST -H 'Content-Type: application/json' \
--data "{\"text\": \"$MESSAGE\"}" \
$MATTERMOST_WEBHOOK_URL