Release Boards/Cards from Branch to Live #69
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | |
- 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 |