Rework workflows and add devbuilds

This commit is contained in:
Willy-JL
2023-07-20 02:00:09 +01:00
parent f951eb5541
commit 49e6554acd
8 changed files with 107 additions and 45 deletions

4
.github/workflow_data/commit.sh vendored Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
export VERSION_TAG="$(python -c 'import fbt_options; print(fbt_options.DIST_SUFFIX, end="")')"
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV

65
.github/workflow_data/devbuild.py vendored Normal file
View File

@@ -0,0 +1,65 @@
#!/usr/bin/env python
import nextcloud_client
import datetime as dt
import requests
import json
import os
dev_share = os.environ["NC_HOST"] + "s/sGHsQB94a9x5CRs/download?path=/&files={files}"
if __name__ == "__main__":
with open(os.environ["GITHUB_EVENT_PATH"], "r") as f:
event = json.load(f)
client = nextcloud_client.Client(os.environ["NC_HOST"])
client.login(os.environ["NC_USER"], os.environ["NC_PASS"])
for file in (
os.environ["ARTIFACT_TGZ"],
os.environ["ARTIFACT_SDK"],
):
path = f"XFW-Dev/{file}"
# try:
# client.delete(path)
# except Exception:
# pass
client.put_file(path, file)
requests.post(
os.environ["BUILD_WEBHOOK"],
headers={"Accept": "application/json", "Content-Type": "application/json"},
json={
"content": None,
"embeds": [
{
"title": "Devbuild infos:",
"description": "",
"url": "",
"color": 16734443,
"fields": [
{
"name": "Changes since last commit:",
"value": f"[Compare {event['before']} to {event['after']}]({event['compare']})"
},
{
"name": "Changes since last release:",
"value": f"[Compare release to {event['after']}]({event['compare'].replace(event['before'], 'main')})"
},
{
"name": "Firmware download:",
"value": f"- [Download SDK for development]({dev_share.format(files=os.environ['ARTIFACT_SDK'])})\n- [Download Firmware TGZ]({dev_share.format(files=os.environ['ARTIFACT_TGZ'])})"
}
],
"author": {
"name": "Build Succeeded!",
"icon_url": "https://cdn.discordapp.com/emojis/1080005692485795930.png"
},
"footer": {
"text": "Build go brrrr",
"icon_url": "https://cdn.discordapp.com/emojis/1059798228725403719.png"
},
"timestamp": dt.datetime.utcnow().isoformat()
}
],
},
)

View File

@@ -1,4 +1,11 @@
#!/bin/bash
export VERSION_TAG="$(python -c 'import fbt_options; print(fbt_options.DIST_SUFFIX)')"
export VERSION_TAG="$(python -c '''
import datetime as dt
with open(os.environ["GITHUB_EVENT_PATH"], "r") as f:
event = json.load(f)
version = int(event["pull_request"]["title"].removeprefix("V").removesuffix(" Release").removesuffix(" Hotfix"))
date = dt.datetime.now().strftime("%d%m%Y")
print(f"XFW-{version:04}_{date}", end="")
''')"
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV

View File

@@ -24,47 +24,38 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: "Read version tag"
run: bash .github/workflow_data/commit.sh
- name: 'Build the firmware'
run: |
set -e
for TARGET in ${TARGETS}; do
TARGET_HW="$(echo "${TARGET}" | sed 's/f//')"; \
./fbt TARGET_HW=$TARGET_HW updater_package
./fbt TARGET_HW=$TARGET_HW DIST_SUFFIX=$VERSION_TAG updater_package
done
- name: "Check for uncommitted changes"
run: |
git diff --exit-code
- name: 'Updater artifact'
- name: 'Dist artifact'
uses: actions/upload-artifact@v3
with:
name: updater
name: dist
path: |
dist/${{ env.DEFAULT_TARGET }}-*/
# - name: 'Find Previous Comment'
# if: ${{ github.event.pull_request }}
# uses: peter-evans/find-comment@v1
# id: fc
# with:
# issue-number: ${{ github.event.pull_request.number }}
# comment-author: 'github-actions[bot]'
# body-includes: 'Compiled firmware:'
- name: "Make tgz, zip and sdk"
run: bash .github/workflow_data/package.sh
# - name: Artifact info
# id: artifact-info
# uses: dawidd6/action-download-artifact@v2
# with:
# dry_run: true
# - name: 'Create or update comment'
# if: ${{ github.event.pull_request}}
# uses: peter-evans/create-or-update-comment@v1
# with:
# comment-id: ${{ steps.fc.outputs.comment-id }}
# issue-number: ${{ github.event.pull_request.number }}
# body: |
# **Compiled firmware:**
# - [📦 Update package](${{steps.artifact-info.outputs.artifacts[0].archive_download_url}})
# edit-mode: replace
- name: Send devbuild webhook
if: "github.event_name == 'push' && endsWith(github.event.push.ref, '/dev')"
env:
NC_HOST: "https://cloud.cynthialabs.net/"
NC_USER: "${{ secrets.NC_USER }}"
NC_PASS: "${{ secrets.NC_PASS }}"
BUILD_WEBHOOK: ${{ secrets.BUILD_WEBHOOK }}
run: |
python -m pip install pyncclient
python .github/workflow_data/devbuild.py

View File

@@ -31,21 +31,21 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: "Read version tag"
run: bash .github/workflow_data/version.sh
- name: 'Build the firmware'
run: |
set -e
for TARGET in ${TARGETS}; do
TARGET_HW="$(echo "${TARGET}" | sed 's/f//')"; \
./fbt TARGET_HW=$TARGET_HW FORCE_NO_DIRTY=1 updater_package
./fbt TARGET_HW=$TARGET_HW DIST_SUFFIX=$VERSION_TAG FORCE_NO_DIRTY=1 updater_package
done
- name: "Check for uncommitted changes"
run: |
git diff --exit-code
- name: "Read version tag"
run: bash .github/workflow_data/version.sh
- name: "Make tgz, zip and sdk"
run: bash .github/workflow_data/package.sh

View File

@@ -12,7 +12,7 @@ jobs:
release:
if: |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name &&
endsWith(github.event.pull_request.title, ' Release Candidate Changes') &&
endsWith(github.event.pull_request.title, ' Release') &&
github.event.review.author_association == 'OWNER' &&
startsWith(github.event.pull_request.title, 'V') &&
github.event.pull_request.base.ref == 'main' &&
@@ -31,21 +31,21 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: "Read version tag"
run: bash .github/workflow_data/version.sh
- name: 'Build the firmware'
run: |
set -e
for TARGET in ${TARGETS}; do
TARGET_HW="$(echo "${TARGET}" | sed 's/f//')"; \
./fbt TARGET_HW=$TARGET_HW FORCE_NO_DIRTY=1 updater_package
./fbt TARGET_HW=$TARGET_HW DIST_SUFFIX=$VERSION_TAG FORCE_NO_DIRTY=1 updater_package
done
- name: "Check for uncommitted changes"
run: |
git diff --exit-code
- name: "Read version tag"
run: bash .github/workflow_data/version.sh
- name: "Make tgz, zip and sdk"
run: bash .github/workflow_data/package.sh