-
Notifications
You must be signed in to change notification settings - Fork 1
166 lines (146 loc) · 6.45 KB
/
MCUsReleaseLive.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
name: Release MCUs from Branch to LIVE
on:
workflow_dispatch:
inputs:
release_branch:
type: string
description: Which Branch to release MCUs from? (change last number to desired number)
default: "new-feature/mcus/1"
release_version:
type: string
description: Tag to use for script run (i.e. v1.0.7)
default: "latest"
auto_merge:
type: boolean
description: If checked, PR shall be automatically merged to main branch.
default: false
notify_channel:
type: boolean
description: If checked, mikroe bot will notify mattermost channel with release details.
default: false
jobs:
upload_mcu_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 [email protected]
- name: Fetch Main Branch
run: git fetch origin main
- 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: |
python -m pip install --upgrade pip
pip install -r scripts/requirements/shared.txt
pip install -r scripts/requirements/databases.txt
pip install -r scripts/requirements/support.txt
sudo apt-get install p7zip-full
- 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: Build Message with Python
run: |
python -u scripts/build_message.py > message.txt
- 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 main\",\"head\":\"${{ github.event.inputs.release_branch }}\",\"base\":\"main\",\"body\":\"Automatically created pull request to merge branch ${{ github.event.inputs.release_branch }} into main\"}")
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 main\",\"merge_method\":\"squash\"}"
- name: Handle Merge Conflict
if: failure()
run: echo "::error::Merge conflict occurred. Please resolve manually."
- name: Update and upload new database
run: |
python -u scripts/reupload_databases.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ secrets.PROG_DEBUG_CODEGRIP_LIVE }} ${{ secrets.PROG_DEBUG_MIKROPROG }} ${{ github.event.inputs.release_version }} "latest" "Live"
- name: Run Index Script
env:
ES_HOST: ${{ secrets.ES_HOST }}
ES_USER: ${{ secrets.ES_USER }}
ES_PASSWORD: ${{ secrets.ES_PASSWORD }}
ES_INDEX_TEST: ${{ secrets.ES_INDEX_TEST }}
ES_INDEX_LIVE: ${{ secrets.ES_INDEX_LIVE }}
run: |
echo "Indexing to Live."
python -u scripts/index.py ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }} ${{ secrets.ES_INDEX_LIVE }} ${{ secrets.PROG_DEBUG_CODEGRIP_LIVE }} "False" ${{ github.event.inputs.release_version }} "False" "False"
- 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