ci: publish direct OTA files via package registry
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
name: OTA build
|
name: OTA build
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@@ -27,20 +31,53 @@ jobs:
|
|||||||
- name: Build OTA firmware binaries
|
- name: Build OTA firmware binaries
|
||||||
run: pio run
|
run: pio run
|
||||||
|
|
||||||
- name: Collect OTA artifacts
|
- name: Prepare direct OTA files
|
||||||
run: |
|
run: |
|
||||||
|
set -eu
|
||||||
|
project_name="${GITHUB_REPOSITORY#*/}"
|
||||||
|
project_name="${project_name#PlatformIO_}"
|
||||||
|
timestamp="$(date -u +%Y-%m-%dT%H-%M-%SZ)"
|
||||||
mkdir -p dist/ota
|
mkdir -p dist/ota
|
||||||
find .pio/build -type f -name 'firmware.bin' -exec cp {} dist/ota/ \;
|
found=0
|
||||||
count=$(find dist/ota -type f -name '*.bin' | wc -l)
|
for fw in .pio/build/*/firmware.bin; do
|
||||||
if [ "$count" -eq 0 ]; then
|
[ -f "$fw" ] || continue
|
||||||
|
env_name="$(basename "$(dirname "$fw")")"
|
||||||
|
cp "$fw" "dist/ota/${project_name}_${env_name}_${timestamp}.bin"
|
||||||
|
found=1
|
||||||
|
done
|
||||||
|
if [ "$found" -eq 0 ]; then
|
||||||
echo 'No firmware.bin artifacts were produced.' >&2
|
echo 'No firmware.bin artifacts were produced.' >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
find dist/ota -maxdepth 1 -type f | sort
|
find dist/ota -maxdepth 1 -type f | sort
|
||||||
|
|
||||||
- name: Upload OTA artifacts
|
- name: Upload direct OTA files to Gitea Packages
|
||||||
uses: actions/upload-artifact@v3
|
env:
|
||||||
with:
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
name: ota-binaries
|
run: |
|
||||||
path: dist/ota/*.bin
|
set -eu
|
||||||
if-no-files-found: error
|
package_name="$(printf '%s' "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')-ota"
|
||||||
|
package_version="${GITHUB_SHA}"
|
||||||
|
base_url="${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/${package_name}/${package_version}"
|
||||||
|
for file in dist/ota/*; do
|
||||||
|
[ -f "$file" ] || continue
|
||||||
|
curl --fail --silent --show-error --user "${GITHUB_ACTOR}:${GITEA_TOKEN}" --upload-file "$file" "${base_url}/$(basename "$file")"
|
||||||
|
echo "Uploaded $(basename "$file")"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Verify uploaded OTA files
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
package_name="$(printf '%s' "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')-ota"
|
||||||
|
package_version="${GITHUB_SHA}"
|
||||||
|
curl --fail --silent --show-error --user "${GITHUB_ACTOR}:${GITEA_TOKEN}" "${GITHUB_SERVER_URL}/api/v1/packages/${GITHUB_REPOSITORY_OWNER}/generic/${package_name}/${package_version}/files" > /tmp/package-files.json
|
||||||
|
python3 - <<'PY'
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
files=json.loads(Path('/tmp/package-files.json').read_text())
|
||||||
|
assert files, 'no package files returned'
|
||||||
|
for item in files:
|
||||||
|
print(item.get('name') or item.get('file_name') or item)
|
||||||
|
PY
|
||||||
|
|||||||
Reference in New Issue
Block a user